Skip to content

A java library to run pieces of code as root.

License

Notifications You must be signed in to change notification settings

youndon/run-as-root

 
 

Repository files navigation

Run As Root

Build Status Maven Central

A java library to run pieces of code as root using native root password input dialog.

A new JVM is created in every execution and destroyed after completion.

This library uses Out Process to create new JVMs.

Why use it?

  • Ask user for credentials in Windows, Linux and macOS.
  • Do privileged actions.
  • Limit scope of root code execution.
  • Upgrade permissions during runtime temporarily.

Usage

// Specify JVM options (optional)
RootExecutor rootExecutor = new RootExecutor("-Xmx64m");

// Execute privileged action without return
rootExecutor.run(() -> {
    // Call your admin code here.
}));

// Execute privileged action with return
Object value = rootExecutor.call(() -> {
    // Call your admin code with return here.
    return null;
}));
System.out.println(value);

Tips

  • Init simple, after include this lib in your project just try to write a file in a protected folder to validate if it is working.
  • Avoid big classpaths, it can be a problem in Windows. #8

Maven

<dependency>
    <groupId>com.github.dyorgio.runtime</groupId>
    <artifactId>run-as-root</artifactId>
    <version>1.2.3</version>
</dependency>

About

A java library to run pieces of code as root.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 62.6%
  • HTML 37.4%