[Minor] Added StrolchAgent.runAsWithResult()

This commit is contained in:
Robert von Burg 2021-05-17 18:03:06 +02:00
parent b99ef252a9
commit b7ce4b355c
3 changed files with 40 additions and 2 deletions

View File

@ -129,14 +129,29 @@ public class StrolchAgent {
} }
/** /**
* @see ComponentContainer#runAsAgent(PrivilegedRunnable) * @see PrivilegeHandler#runAs(String, PrivilegedRunnable)
*/
public void runAs(String systemUser, PrivilegedRunnable runnable) throws PrivilegeException, Exception {
getPrivilegeHandler().runAs(systemUser, runnable);
}
/**
* @see PrivilegeHandler#runAsAgent(PrivilegedRunnable)
*/ */
public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception { public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
getPrivilegeHandler().runAsAgent(runnable); getPrivilegeHandler().runAsAgent(runnable);
} }
/** /**
* @see ComponentContainer#runAsAgentWithResult(PrivilegedRunnableWithResult) * @see PrivilegeHandler#runAsAgentWithResult(PrivilegedRunnableWithResult)
*/
public <T> T runAsWithResult(String systemUser, PrivilegedRunnableWithResult<T> runnable)
throws PrivilegeException, Exception {
return getPrivilegeHandler().runAsWithResult(systemUser, runnable);
}
/**
* @see PrivilegeHandler#runAsAgentWithResult(PrivilegedRunnableWithResult)
*/ */
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception { public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception {
return getPrivilegeHandler().runAsAgentWithResult(runnable); return getPrivilegeHandler().runAsAgentWithResult(runnable);

View File

@ -264,6 +264,11 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
.runWithResult(StrolchConstants.SYSTEM_USER_AGENT, new StrolchSystemActionWithResult<>(runnable)); .runWithResult(StrolchConstants.SYSTEM_USER_AGENT, new StrolchSystemActionWithResult<>(runnable));
} }
@Override
public <T> T runAsWithResult(String username, PrivilegedRunnableWithResult<T> runnable) throws Exception {
return this.privilegeHandler.runWithResult(username, new StrolchSystemActionWithResult<>(runnable));
}
@Override @Override
public PrivilegeContext openAgentSystemUserContext() throws PrivilegeException { public PrivilegeContext openAgentSystemUserContext() throws PrivilegeException {
return this.privilegeHandler.openSystemUserContext(StrolchConstants.SYSTEM_USER_AGENT); return this.privilegeHandler.openSystemUserContext(StrolchConstants.SYSTEM_USER_AGENT);

View File

@ -298,6 +298,24 @@ public interface PrivilegeHandler {
*/ */
<T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception; <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception;
/**
* Run the given {@link PrivilegedRunnableWithResult} as the given system user
*
* @param username
* the system username
* @param runnable
* the runnable to perform
*
* @return the result
*
* @throws PrivilegeException
* if there is something wrong
* @throws Exception
* if anything else goes wrong during execution
*/
<T> T runAsWithResult(String username, PrivilegedRunnableWithResult<T> runnable)
throws PrivilegeException, Exception;
/** /**
* Opens a {@link PrivilegeContext} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT} * Opens a {@link PrivilegeContext} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
* *