Run As Root

A java library to run pieces of code as root.

License

License

GroupId

GroupId

com.github.dyorgio.runtime
ArtifactId

ArtifactId

run-as-root
Last Version

Last Version

1.2.3
Release Date

Release Date

Type

Type

jar
Description

Description

Run As Root
A java library to run pieces of code as root.
Project URL

Project URL

https://github.com/dyorgio/run-as-root
Source Code Management

Source Code Management

https://github.com/dyorgio/run-as-root.git

Download run-as-root

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.dyorgio.runtime/run-as-root/ -->
<dependency>
    <groupId>com.github.dyorgio.runtime</groupId>
    <artifactId>run-as-root</artifactId>
    <version>1.2.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.dyorgio.runtime/run-as-root/
implementation 'com.github.dyorgio.runtime:run-as-root:1.2.3'
// https://jarcasting.com/artifacts/com.github.dyorgio.runtime/run-as-root/
implementation ("com.github.dyorgio.runtime:run-as-root:1.2.3")
'com.github.dyorgio.runtime:run-as-root:jar:1.2.3'
<dependency org="com.github.dyorgio.runtime" name="run-as-root" rev="1.2.3">
  <artifact name="run-as-root" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.dyorgio.runtime', module='run-as-root', version='1.2.3')
)
libraryDependencies += "com.github.dyorgio.runtime" % "run-as-root" % "1.2.3"
[com.github.dyorgio.runtime/run-as-root "1.2.3"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.dyorgio.runtime : out-process jar 1.2.7

Project Modules

There are no modules declared in this project.

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>

Versions

Version
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.1
1.0.0