Run As Root

Build Status Maven Central Known Vulnerabilities

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?

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

Maven

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