[Major] runAs*() now throws Exception
This commit is contained in:
parent
15a03928e2
commit
21c414ab00
|
@ -96,8 +96,10 @@ public interface ComponentContainer {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException;
|
void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the given {@link PrivilegedRunnable} as the privileged system user {@link
|
* Performs the given {@link PrivilegedRunnable} as the privileged system user {@link
|
||||||
|
@ -110,6 +112,8 @@ public interface ComponentContainer {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
<T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException;
|
<T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception;
|
||||||
}
|
}
|
|
@ -155,7 +155,7 @@ public class StrolchAgent {
|
||||||
this.executors = new HashMap<>();
|
this.executors = new HashMap<>();
|
||||||
this.scheduledExecutors = new HashMap<>();
|
this.scheduledExecutors = new HashMap<>();
|
||||||
|
|
||||||
this.container.initialize(this.strolchConfiguration);
|
this.container.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -283,8 +283,10 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAs(String username, SystemAction action) throws PrivilegeException {
|
protected void runAs(String username, SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAs(username, action);
|
this.container.getPrivilegeHandler().runAs(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,8 +302,11 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException {
|
protected <T> T runWithResult(String username, SystemActionWithResult<T> action)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runWithResult(username, action);
|
return this.container.getPrivilegeHandler().runWithResult(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,8 +320,10 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAs(username, runnable);
|
this.container.getPrivilegeHandler().runAs(username, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,8 +339,11 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <T> T runWithResult(String username, PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
protected <T> T runWithResult(String username, PrivilegedRunnableWithResult<T> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runWithResult(username, runnable);
|
return this.container.getPrivilegeHandler().runWithResult(username, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,8 +355,10 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(SystemAction action) throws PrivilegeException {
|
protected void runAsAgent(SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAsAgent(action);
|
this.container.getPrivilegeHandler().runAsAgent(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,8 +372,10 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <T> T runAsAgentWithResult(SystemActionWithResult<T> action) throws PrivilegeException {
|
protected <T> T runAsAgentWithResult(SystemActionWithResult<T> action) throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runAsAgentWithResult(action);
|
return this.container.getPrivilegeHandler().runAsAgentWithResult(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,8 +388,10 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAsAgent(runnable);
|
this.container.getPrivilegeHandler().runAsAgent(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +406,11 @@ public class StrolchComponent {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the given username is not allowed to perform the action
|
* if the given username is not allowed to perform the action
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
protected <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runAsAgentWithResult(runnable);
|
return this.container.getPrivilegeHandler().runAsAgentWithResult(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,12 +134,12 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
getPrivilegeHandler().runAsAgent(runnable);
|
getPrivilegeHandler().runAsAgent(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception {
|
||||||
return getPrivilegeHandler().runAsAgentWithResult(runnable);
|
return getPrivilegeHandler().runAsAgentWithResult(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
||||||
.format(msg, applicationName, environment, this.componentMap.size(), formatNanoDuration(took)));
|
.format(msg, applicationName, environment, this.componentMap.size(), formatNanoDuration(took)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(StrolchConfiguration strolchConfiguration) {
|
public void initialize() {
|
||||||
this.state.validateStateChange(ComponentState.INITIALIZED, "agent");
|
this.state.validateStateChange(ComponentState.INITIALIZED, "agent");
|
||||||
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package li.strolch.handler.operationslog;
|
package li.strolch.handler.operationslog;
|
||||||
|
|
||||||
|
import static li.strolch.model.Tags.AGENT;
|
||||||
|
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
|
import li.strolch.agent.api.StrolchAgent;
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
import li.strolch.agent.api.StrolchComponent;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
|
@ -112,6 +116,7 @@ public class OperationsLog extends StrolchComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persist(StrolchRealm realm, LogMessage logMessage, List<LogMessage> messagesToRemove) {
|
private void persist(StrolchRealm realm, LogMessage logMessage, List<LogMessage> messagesToRemove) {
|
||||||
|
try {
|
||||||
runAsAgent(ctx -> {
|
runAsAgent(ctx -> {
|
||||||
try (StrolchTransaction tx = realm.openTx(ctx.getCertificate(), getClass())) {
|
try (StrolchTransaction tx = realm.openTx(ctx.getCertificate(), getClass())) {
|
||||||
LogMessageDao logMessageDao = tx.getPersistenceHandler().getLogMessageDao(tx);
|
LogMessageDao logMessageDao = tx.getPersistenceHandler().getLogMessageDao(tx);
|
||||||
|
@ -121,6 +126,17 @@ public class OperationsLog extends StrolchComponent {
|
||||||
tx.commitOnClose();
|
tx.commitOnClose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to persist operations logs!", e);
|
||||||
|
synchronized (this) {
|
||||||
|
this.logMessagesByRealmAndId.computeIfAbsent(realm.getRealm(), r -> new ArrayList<>())
|
||||||
|
.add(new LogMessage(realm.getRealm(), SYSTEM_USER_AGENT,
|
||||||
|
Locator.valueOf(AGENT, "strolch-agent", StrolchAgent.getUniqueId()), LogSeverity.Info,
|
||||||
|
ResourceBundle.getBundle("strolch-agent"), "operationsLog.persist.failed") //
|
||||||
|
.value("reason", e.getMessage()) //
|
||||||
|
.withException(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void clearMessages(String realm, Locator locator) {
|
public synchronized void clearMessages(String realm, Locator locator) {
|
||||||
|
|
|
@ -183,42 +183,43 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAs(String username, SystemAction action) throws PrivilegeException {
|
public void runAs(String username, SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.privilegeHandler.runAs(username, action);
|
this.privilegeHandler.runAs(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException {
|
public <T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException, Exception {
|
||||||
return this.privilegeHandler.runWithResult(username, action);
|
return this.privilegeHandler.runWithResult(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException {
|
public void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.privilegeHandler.runAs(username, new StrolchSystemAction(runnable));
|
this.privilegeHandler.runAs(username, new StrolchSystemAction(runnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T runWithResult(String username, PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
public <T> T runWithResult(String username, PrivilegedRunnableWithResult<T> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.privilegeHandler.runWithResult(username, new StrolchSystemActionWithResult<>(runnable));
|
return this.privilegeHandler.runWithResult(username, new StrolchSystemActionWithResult<>(runnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAsAgent(SystemAction action) throws PrivilegeException {
|
public void runAsAgent(SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.privilegeHandler.runAs(StrolchConstants.SYSTEM_USER_AGENT, action);
|
this.privilegeHandler.runAs(StrolchConstants.SYSTEM_USER_AGENT, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T runAsAgentWithResult(SystemActionWithResult<T> action) throws PrivilegeException {
|
public <T> T runAsAgentWithResult(SystemActionWithResult<T> action) throws PrivilegeException, Exception {
|
||||||
return this.privilegeHandler.runWithResult(StrolchConstants.SYSTEM_USER_AGENT, action);
|
return this.privilegeHandler.runWithResult(StrolchConstants.SYSTEM_USER_AGENT, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.privilegeHandler.runAs(StrolchConstants.SYSTEM_USER_AGENT, new StrolchSystemAction(runnable));
|
this.privilegeHandler.runAs(StrolchConstants.SYSTEM_USER_AGENT, new StrolchSystemAction(runnable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception {
|
||||||
return this.privilegeHandler
|
return this.privilegeHandler
|
||||||
.runWithResult(StrolchConstants.SYSTEM_USER_AGENT, new StrolchSystemActionWithResult<>(runnable));
|
.runWithResult(StrolchConstants.SYSTEM_USER_AGENT, new StrolchSystemActionWithResult<>(runnable));
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
void runAs(String username, SystemAction action) throws PrivilegeException;
|
void runAs(String username, SystemAction action) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link SystemActionWithResult} as the given system user
|
* Run the given {@link SystemActionWithResult} as the given system user
|
||||||
|
@ -119,8 +121,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
<T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException;
|
<T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link PrivilegedRunnable} as the given system user
|
* Run the given {@link PrivilegedRunnable} as the given system user
|
||||||
|
@ -132,8 +136,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException;
|
void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link PrivilegedRunnable} as the given system user
|
* Run the given {@link PrivilegedRunnable} as the given system user
|
||||||
|
@ -147,8 +153,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
<T> T runWithResult(String username, PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException;
|
<T> T runWithResult(String username, PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link SystemAction} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* Run the given {@link SystemAction} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
|
@ -158,8 +166,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
void runAsAgent(SystemAction action) throws PrivilegeException;
|
void runAsAgent(SystemAction action) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link SystemActionWithResult} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* Run the given {@link SystemActionWithResult} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
|
@ -169,8 +179,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
<T> T runAsAgentWithResult(SystemActionWithResult<T> action) throws PrivilegeException;
|
<T> T runAsAgentWithResult(SystemActionWithResult<T> action) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link PrivilegedRunnable} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* Run the given {@link PrivilegedRunnable} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
|
@ -180,8 +192,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException;
|
void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the given {@link PrivilegedRunnableWithResult} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* Run the given {@link PrivilegedRunnableWithResult} as the system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
|
@ -193,8 +207,10 @@ public interface PrivilegeHandler {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if there is something wrong
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
<T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException;
|
<T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link li.strolch.privilege.handler.PrivilegeHandler}
|
* Returns the {@link li.strolch.privilege.handler.PrivilegeHandler}
|
||||||
|
@ -202,5 +218,4 @@ public interface PrivilegeHandler {
|
||||||
* @return the {@link li.strolch.privilege.handler.PrivilegeHandler}
|
* @return the {@link li.strolch.privilege.handler.PrivilegeHandler}
|
||||||
*/
|
*/
|
||||||
li.strolch.privilege.handler.PrivilegeHandler getPrivilegeHandler();
|
li.strolch.privilege.handler.PrivilegeHandler getPrivilegeHandler();
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,5 +4,5 @@ import li.strolch.privilege.model.PrivilegeContext;
|
||||||
|
|
||||||
public interface PrivilegedRunnable {
|
public interface PrivilegedRunnable {
|
||||||
|
|
||||||
public void run(PrivilegeContext ctx);
|
public void run(PrivilegeContext ctx) throws Exception;
|
||||||
}
|
}
|
|
@ -4,5 +4,5 @@ import li.strolch.privilege.model.PrivilegeContext;
|
||||||
|
|
||||||
public interface PrivilegedRunnableWithResult<T> {
|
public interface PrivilegedRunnableWithResult<T> {
|
||||||
|
|
||||||
public T run(PrivilegeContext ctx);
|
public T run(PrivilegeContext ctx) throws Exception;
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ public class StrolchSystemAction extends SystemAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(PrivilegeContext privilegeContext) {
|
public void execute(PrivilegeContext privilegeContext) throws Exception {
|
||||||
try {
|
try {
|
||||||
this.runnable.run(privilegeContext);
|
this.runnable.run(privilegeContext);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T execute(PrivilegeContext privilegeContext) {
|
public T execute(PrivilegeContext privilegeContext) throws Exception {
|
||||||
try {
|
try {
|
||||||
return this.runnable.run(privilegeContext);
|
return this.runnable.run(privilegeContext);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -17,9 +17,6 @@ package li.strolch.service.api;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchComponent;
|
import li.strolch.agent.api.StrolchComponent;
|
||||||
import li.strolch.agent.api.StrolchRealm;
|
import li.strolch.agent.api.StrolchRealm;
|
||||||
|
@ -37,6 +34,8 @@ import li.strolch.runtime.privilege.PrivilegedRunnable;
|
||||||
import li.strolch.runtime.privilege.PrivilegedRunnableWithResult;
|
import li.strolch.runtime.privilege.PrivilegedRunnableWithResult;
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
import li.strolch.utils.helper.StringHelper;
|
import li.strolch.utils.helper.StringHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -110,7 +109,8 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
* Returns the reference to the {@link StrolchComponent} with the given name, if it exists. If it does not exist, an
|
* Returns the reference to the {@link StrolchComponent} with the given name, if it exists. If it does not exist, an
|
||||||
* {@link IllegalArgumentException} is thrown
|
* {@link IllegalArgumentException} is thrown
|
||||||
*
|
*
|
||||||
* @param clazz the type of component to return
|
* @param clazz
|
||||||
|
* the type of component to return
|
||||||
*
|
*
|
||||||
* @return the component with the given name
|
* @return the component with the given name
|
||||||
*
|
*
|
||||||
|
@ -131,11 +131,12 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link StrolchRealm} with the given name. If the realm does not exist, then a
|
* Returns the {@link StrolchRealm} with the given name. If the realm does not exist, then a {@link
|
||||||
* {@link StrolchException} is thrown
|
* StrolchException} is thrown
|
||||||
*
|
*
|
||||||
* @param realm
|
* @param realm
|
||||||
* the name of the {@link StrolchRealm} to return
|
* the name of the {@link StrolchRealm} to return
|
||||||
|
*
|
||||||
* @return the {@link StrolchRealm} with the given name
|
* @return the {@link StrolchRealm} with the given name
|
||||||
*
|
*
|
||||||
* @throws StrolchException
|
* @throws StrolchException
|
||||||
|
@ -220,9 +221,9 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a {@link StrolchTransaction} where the realm retrieved using
|
* Opens a {@link StrolchTransaction} where the realm retrieved using {@link ComponentContainer#getRealm(Certificate)},
|
||||||
* {@link ComponentContainer#getRealm(Certificate)}, the action for the TX is this implementation's class name. This
|
* the action for the TX is this implementation's class name. This transaction should be used in a try-with-resource
|
||||||
* transaction should be used in a try-with-resource clause so it is properly closed
|
* clause so it is properly closed
|
||||||
*
|
*
|
||||||
* @return the open {@link StrolchTransaction}
|
* @return the open {@link StrolchTransaction}
|
||||||
*
|
*
|
||||||
|
@ -234,9 +235,8 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a {@link StrolchTransaction} where the realm retrieved using
|
* Opens a {@link StrolchTransaction} where the realm retrieved using {@link ComponentContainer#getRealm(Certificate)}.
|
||||||
* {@link ComponentContainer#getRealm(Certificate)}. This transaction should be used in a try-with-resource clause
|
* This transaction should be used in a try-with-resource clause so it is properly closed
|
||||||
* so it is properly closed
|
|
||||||
*
|
*
|
||||||
* @param action
|
* @param action
|
||||||
* the action to use for the opened TX
|
* the action to use for the opened TX
|
||||||
|
@ -258,9 +258,12 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
* @param action
|
* @param action
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAs(String username, SystemAction action) throws PrivilegeException {
|
protected void runAs(String username, SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAs(username, action);
|
this.container.getPrivilegeHandler().runAs(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,9 +277,13 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runWithResult(String username, SystemActionWithResult<V> action) throws PrivilegeException {
|
protected <V> V runWithResult(String username, SystemActionWithResult<V> action)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runWithResult(username, action);
|
return this.container.getPrivilegeHandler().runWithResult(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,9 +295,12 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
* @param runnable
|
* @param runnable
|
||||||
* the runnable to perform
|
* the runnable to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAs(username, runnable);
|
this.container.getPrivilegeHandler().runAs(username, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,9 +314,13 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runWithResult(String username, PrivilegedRunnableWithResult<V> runnable) throws PrivilegeException {
|
protected <V> V runWithResult(String username, PrivilegedRunnableWithResult<V> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runWithResult(username, runnable);
|
return this.container.getPrivilegeHandler().runWithResult(username, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,9 +330,12 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
* @param action
|
* @param action
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the agent user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the agent user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(SystemAction action) throws PrivilegeException {
|
protected void runAsAgent(SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAsAgent(action);
|
this.container.getPrivilegeHandler().runAsAgent(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,44 +347,54 @@ public abstract class AbstractService<T extends ServiceArgument, U extends Servi
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the agent user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the agent user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runAsAgentWithResult(SystemActionWithResult<V> action) throws PrivilegeException {
|
protected <V> V runAsAgentWithResult(SystemActionWithResult<V> action) throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runAsAgentWithResult(action);
|
return this.container.getPrivilegeHandler().runAsAgentWithResult(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the given {@link PrivilegedRunnable} as the privileged system user
|
* Performs the given {@link PrivilegedRunnable} as the privileged system user {@link
|
||||||
* {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
*
|
*
|
||||||
* @param runnable
|
* @param runnable
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the agent user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the agent user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAsAgent(runnable);
|
this.container.getPrivilegeHandler().runAsAgent(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the given {@link PrivilegedRunnableWithResult} as the privileged system user
|
* Performs the given {@link PrivilegedRunnableWithResult} as the privileged system user {@link
|
||||||
* {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
*
|
*
|
||||||
* @param runnable
|
* @param runnable
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException if the agent user does not exist, or is not a system user
|
* @throws PrivilegeException
|
||||||
|
* if the agent user does not exist, or is not a system user
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runAsAgentWithResult(PrivilegedRunnableWithResult<V> runnable) throws PrivilegeException {
|
protected <V> V runAsAgentWithResult(PrivilegedRunnableWithResult<V> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runAsAgentWithResult(runnable);
|
return this.container.getPrivilegeHandler().runAsAgentWithResult(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is final as it enforces that the argument is valid, and catches all exceptions and enforces that a
|
* This method is final as it enforces that the argument is valid, and catches all exceptions and enforces that a
|
||||||
* service result is returned. A concrete implementation will implement the business logic in
|
* service result is returned. A concrete implementation will implement the business logic in {@link
|
||||||
* {@link #internalDoService(ServiceArgument)}
|
* #internalDoService(ServiceArgument)}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final U doService(T argument) {
|
public final U doService(T argument) {
|
||||||
|
|
|
@ -103,7 +103,8 @@ public abstract class Command implements Restrictable {
|
||||||
*
|
*
|
||||||
* @param policyClass
|
* @param policyClass
|
||||||
* the policy type to return. The simple name of the class determines the type of Policy to return.
|
* the policy type to return. The simple name of the class determines the type of Policy to return.
|
||||||
* @param policyContainer the container
|
* @param policyContainer
|
||||||
|
* the container
|
||||||
*
|
*
|
||||||
* @return the policy
|
* @return the policy
|
||||||
*/
|
*/
|
||||||
|
@ -125,8 +126,11 @@ public abstract class Command implements Restrictable {
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAs(String username, SystemAction action) throws PrivilegeException {
|
protected void runAs(String username, SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAs(username, action);
|
this.container.getPrivilegeHandler().runAs(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,8 +145,12 @@ public abstract class Command implements Restrictable {
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException {
|
protected <T> T runWithResult(String username, SystemActionWithResult<T> action)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runWithResult(username, action);
|
return this.container.getPrivilegeHandler().runWithResult(username, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +163,11 @@ public abstract class Command implements Restrictable {
|
||||||
* the runnable to perform
|
* the runnable to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAs(username, runnable);
|
this.container.getPrivilegeHandler().runAs(username, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,38 +182,44 @@ public abstract class Command implements Restrictable {
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runWithResult(String username, PrivilegedRunnableWithResult<V> runnable) throws PrivilegeException {
|
protected <V> V runWithResult(String username, PrivilegedRunnableWithResult<V> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runWithResult(username, runnable);
|
return this.container.getPrivilegeHandler().runWithResult(username, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the given {@link SystemAction} as the privileged system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* Performs the given {@link SystemAction} as the privileged system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
*
|
*
|
||||||
* @param username
|
|
||||||
* the name of the system user to perform the action as
|
|
||||||
* @param action
|
* @param action
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(SystemAction action) throws PrivilegeException {
|
protected void runAsAgent(SystemAction action) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAsAgent(action);
|
this.container.getPrivilegeHandler().runAsAgent(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the given {@link SystemAction} as the privileged system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
* Performs the given {@link SystemAction} as the privileged system user {@link StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
*
|
*
|
||||||
* @param username
|
|
||||||
* the name of the system user to perform the action as
|
|
||||||
* @param action
|
* @param action
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runAsAgentWithResult(SystemActionWithResult<V> action) throws PrivilegeException {
|
protected <V> V runAsAgentWithResult(SystemActionWithResult<V> action) throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runAsAgentWithResult(action);
|
return this.container.getPrivilegeHandler().runAsAgentWithResult(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,12 +227,15 @@ public abstract class Command implements Restrictable {
|
||||||
* Performs the given {@link PrivilegedRunnable} as the privileged system user {@link
|
* Performs the given {@link PrivilegedRunnable} as the privileged system user {@link
|
||||||
* StrolchConstants#SYSTEM_USER_AGENT}
|
* StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
*
|
*
|
||||||
* @param action
|
* @param runnable
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
this.container.getPrivilegeHandler().runAsAgent(runnable);
|
this.container.getPrivilegeHandler().runAsAgent(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,14 +243,18 @@ public abstract class Command implements Restrictable {
|
||||||
* Performs the given {@link PrivilegedRunnableWithResult} as the privileged system user {@link
|
* Performs the given {@link PrivilegedRunnableWithResult} as the privileged system user {@link
|
||||||
* StrolchConstants#SYSTEM_USER_AGENT}
|
* StrolchConstants#SYSTEM_USER_AGENT}
|
||||||
*
|
*
|
||||||
* @param action
|
* @param runnable
|
||||||
* the action to perform
|
* the action to perform
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
|
* if there is something wrong
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <V> V runAsAgentWithResult(PrivilegedRunnableWithResult<V> runnable) throws PrivilegeException {
|
protected <V> V runAsAgentWithResult(PrivilegedRunnableWithResult<V> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return this.container.getPrivilegeHandler().runAsAgentWithResult(runnable);
|
return this.container.getPrivilegeHandler().runAsAgentWithResult(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,3 +2,4 @@ agent.started={applicationName}:{environment} All {components} Strolch Component
|
||||||
agent.stopping={applicationName}:{environment} Stopping Strolch Agent with {components} components.
|
agent.stopping={applicationName}:{environment} Stopping Strolch Agent with {components} components.
|
||||||
agent.tx.failed=Transaction has failed due to {reason}
|
agent.tx.failed=Transaction has failed due to {reason}
|
||||||
strolchjob.failed=Execution of Job {jobName} has failed due to {reason}
|
strolchjob.failed=Execution of Job {jobName} has failed due to {reason}
|
||||||
|
operationsLog.persist.failed=Failed to persist OperationsLog due to: {reason}
|
|
@ -1839,7 +1839,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runAs(String username, SystemAction action) throws PrivilegeException {
|
public void runAs(String username, SystemAction action) throws PrivilegeException, Exception {
|
||||||
|
|
||||||
PrivilegeContext systemUserPrivilegeContext = initiateSystemPrivilege(username, action);
|
PrivilegeContext systemUserPrivilegeContext = initiateSystemPrivilege(username, action);
|
||||||
|
|
||||||
|
@ -1853,7 +1853,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException {
|
public <T> T runWithResult(String username, SystemActionWithResult<T> action) throws PrivilegeException, Exception {
|
||||||
|
|
||||||
PrivilegeContext systemUserPrivilegeContext = initiateSystemPrivilege(username, action);
|
PrivilegeContext systemUserPrivilegeContext = initiateSystemPrivilege(username, action);
|
||||||
|
|
||||||
|
|
|
@ -697,9 +697,11 @@ public interface PrivilegeHandler {
|
||||||
* the action to be performed as the system user
|
* the action to be performed as the system user
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the user does not exist, or the system action is not alloed
|
* if the user does not exist, or the system action is not allowed
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
void runAs(String systemUsername, SystemAction action) throws PrivilegeException;
|
void runAs(String systemUsername, SystemAction action) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special method to perform work as a System user, meaning the given systemUsername corresponds to an account which
|
* Special method to perform work as a System user, meaning the given systemUsername corresponds to an account which
|
||||||
|
@ -714,9 +716,11 @@ public interface PrivilegeHandler {
|
||||||
* @return the action
|
* @return the action
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the user does not exist, or the system action is not alloed
|
* if the user does not exist, or the system action is not allowed
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
<T> T runWithResult(String systemUsername, SystemActionWithResult<T> action) throws PrivilegeException;
|
<T> T runWithResult(String systemUsername, SystemActionWithResult<T> action) throws PrivilegeException, Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link EncryptionHandler} instance
|
* Returns the {@link EncryptionHandler} instance
|
||||||
|
|
|
@ -45,5 +45,5 @@ public abstract class SystemAction implements Restrictable {
|
||||||
* @param privilegeContext
|
* @param privilegeContext
|
||||||
* the {@link PrivilegeContext} which was generated for a valid system user
|
* the {@link PrivilegeContext} which was generated for a valid system user
|
||||||
*/
|
*/
|
||||||
public abstract void execute(PrivilegeContext privilegeContext);
|
public abstract void execute(PrivilegeContext privilegeContext) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import li.strolch.privilege.model.Restrictable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With this interface system actions, which are to be performed in an automated fashion, i.e. by cron jobs, can be
|
* With this interface system actions, which are to be performed in an automated fashion, i.e. by cron jobs, can be
|
||||||
* implemented and then the authorized execution can be delegated to {@link PrivilegeHandler#runAsSystem(String,
|
* implemented and then the authorized execution can be delegated to {@link PrivilegeHandler#runWithResult(String,
|
||||||
* SystemActionWithResult)}
|
* SystemActionWithResult)}
|
||||||
*
|
*
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
@ -48,5 +48,5 @@ public abstract class SystemActionWithResult<T> implements Restrictable {
|
||||||
*
|
*
|
||||||
* @return the result
|
* @return the result
|
||||||
*/
|
*/
|
||||||
public abstract T execute(PrivilegeContext privilegeContext);
|
public abstract T execute(PrivilegeContext privilegeContext) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,8 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
||||||
private void persistSessions() {
|
private void persistSessions() {
|
||||||
try {
|
try {
|
||||||
runAsAgent(ctx -> this.privilegeHandler.getPrivilegeHandler().persistSessions(ctx.getCertificate()));
|
runAsAgent(ctx -> this.privilegeHandler.getPrivilegeHandler().persistSessions(ctx.getCertificate()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to persist sessions", e);
|
||||||
} finally {
|
} finally {
|
||||||
this.persistSessionsTask = null;
|
this.persistSessionsTask = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,8 +176,10 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the agent is missing the privilege
|
* if the agent is missing the privilege
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException {
|
protected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||||
getContainer().getPrivilegeHandler().runAs(StrolchConstants.SYSTEM_USER_AGENT, runnable);
|
getContainer().getPrivilegeHandler().runAs(StrolchConstants.SYSTEM_USER_AGENT, runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,8 +194,11 @@ public abstract class ExecutionPolicy extends StrolchPolicy {
|
||||||
*
|
*
|
||||||
* @throws PrivilegeException
|
* @throws PrivilegeException
|
||||||
* if the agent is missing the privilege
|
* if the agent is missing the privilege
|
||||||
|
* @throws Exception
|
||||||
|
* if anything else goes wrong during execution
|
||||||
*/
|
*/
|
||||||
protected <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException {
|
protected <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable)
|
||||||
|
throws PrivilegeException, Exception {
|
||||||
return getContainer().getPrivilegeHandler().runWithResult(StrolchConstants.SYSTEM_USER_AGENT, runnable);
|
return getContainer().getPrivilegeHandler().runWithResult(StrolchConstants.SYSTEM_USER_AGENT, runnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue