li.strolch.runtime.privilege.StrolchSystemActionWithResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agent Show documentation
Show all versions of agent Show documentation
Strolch Agent which is the runtime for Strolch
The newest version!
package li.strolch.runtime.privilege;
import li.strolch.privilege.handler.SystemAction;
import li.strolch.privilege.handler.SystemActionWithResult;
import li.strolch.privilege.model.PrivilegeContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* {@link SystemAction} to run {@link PrivilegedRunnableWithResult} as a system user
*
* @param
*
* @author Robert von Burg
*/
public class StrolchSystemActionWithResult extends SystemActionWithResult {
public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);
private final PrivilegedRunnableWithResult runnable;
public StrolchSystemActionWithResult(PrivilegedRunnableWithResult runnable) {
this.runnable = runnable;
}
@Override
public T execute(PrivilegeContext privilegeContext) throws Exception {
try {
return this.runnable.run(privilegeContext);
} catch (Exception e) {
logger.error("Failed to execute SystemAction for " + privilegeContext.getUsername() + " due to " + e
.getMessage(), e);
throw e;
}
}
}