public abstract class AbstractService<T extends ServiceArgument,U extends ServiceResult> extends Object implements Service<T,U>
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
AbstractService() |
| Modifier and Type | Method and Description |
|---|---|
U |
doService(T argument)
This method is final as it enforces that the argument is valid, and catches all exceptions and enforces that a
service result is returned.
|
protected Certificate |
getCertificate()
Returns the
Certificate of the user who is performing this service |
protected <V> V |
getComponent(Class<V> clazz)
Returns the reference to the
StrolchComponent with the given name, if it exists. |
protected ComponentContainer |
getContainer()
Returns the reference to the
ComponentContainer |
PrivilegeContext |
getPrivilegeContext()
Return the
PrivilegeContext to perform further privilege authorization validation |
PrivilegeHandler |
getPrivilegeHandler()
Returns the reference to the
PrivilegeHandler |
String |
getPrivilegeName() |
Object |
getPrivilegeValue() |
protected StrolchRealm |
getRealm(String realm)
Returns the
StrolchRealm with the given name. |
protected abstract U |
getResultInstance()
This method is called if the service execution fails and an instance of the expected
ServiceResult is
required to return to the caller |
protected RuntimeConfiguration |
getRuntimeConfiguration()
Returns the Strolch
RuntimeConfiguration |
protected abstract U |
internalDoService(T arg)
Internal method to perform the
Service. |
protected boolean |
isArgumentRequired()
Returns true if this Service requires an argument
|
protected StrolchTransaction |
openArgOrUserTx(ServiceArgument arg)
Opens a
StrolchTransaction by evaluating if the given argument has a realm defined, if not, then the
realm from the user certificate is used. |
protected StrolchTransaction |
openArgOrUserTx(ServiceArgument arg,
String action)
Opens a
StrolchTransaction by evaluating if the given argument has a realm defined, if not, then the
realm from the user certificate is used. |
protected StrolchTransaction |
openTx(String realm)
Opens a
StrolchTransaction for the given realm, the action for the TX is this implementation's class
name. |
protected StrolchTransaction |
openTx(String realm,
String action)
Opens a
StrolchTransaction for the given realm. |
protected StrolchTransaction |
openUserTx()
Opens a
StrolchTransaction where the realm retrieved using
ComponentContainer.getRealm(Certificate), the action for the TX is this implementation's class name. |
protected StrolchTransaction |
openUserTx(String action)
Opens a
StrolchTransaction where the realm retrieved using
ComponentContainer.getRealm(Certificate). |
protected void |
runAs(String username,
PrivilegedRunnable runnable)
Performs the given
PrivilegedRunnable as a system user with the given username |
protected void |
runAs(String username,
SystemAction action)
Performs the given
SystemAction as a system user with the given username |
protected void |
runAsAgent(PrivilegedRunnable runnable)
Performs the given
PrivilegedRunnable as the privileged system user
StrolchConstants.SYSTEM_USER_AGENT |
protected void |
runAsAgent(SystemAction action)
Performs the given
SystemAction as the privileged system user StrolchConstants.SYSTEM_USER_AGENT |
protected <V> V |
runAsAgentWithResult(PrivilegedRunnableWithResult<V> runnable)
Performs the given
PrivilegedRunnableWithResult as the privileged system user
StrolchConstants.SYSTEM_USER_AGENT |
protected <V> V |
runAsAgentWithResult(SystemActionWithResult<V> action)
Performs the given
SystemAction as the privileged system user StrolchConstants.SYSTEM_USER_AGENT |
protected <V> V |
runWithResult(String username,
PrivilegedRunnableWithResult<V> runnable)
Performs the given
PrivilegedRunnableWithResult as a system user with the given username |
protected <V> V |
runWithResult(String username,
SystemActionWithResult<V> action)
Performs the given
SystemAction as a system user with the given username |
void |
setContainer(ComponentContainer container)
Called by the
ServiceHandler to set a reference to the ComponentContainer to be used during
service execution |
void |
setPrivilegeContext(PrivilegeContext privilegeContext)
Called by the
ServiceHandler to set the PrivilegeContext before this service is performed |
public final void setPrivilegeContext(PrivilegeContext privilegeContext)
ServiceHandler to set the PrivilegeContext before this service is performedprivilegeContext - the privilegeContext to setpublic final PrivilegeContext getPrivilegeContext()
PrivilegeContext to perform further privilege authorization validationprotected final Certificate getCertificate()
Certificate of the user who is performing this servicepublic final void setContainer(ComponentContainer container)
ServiceHandler to set a reference to the ComponentContainer to be used during
service executioncontainer - the container to setprotected final ComponentContainer getContainer()
ComponentContainerpublic PrivilegeHandler getPrivilegeHandler() throws IllegalArgumentException
PrivilegeHandlerIllegalArgumentExceptionprotected final <V> V getComponent(Class<V> clazz)
StrolchComponent with the given name, if it exists. If it does not exist, an
IllegalArgumentException is thrownclazz - IllegalArgumentException - if the component does not existprotected final RuntimeConfiguration getRuntimeConfiguration()
RuntimeConfigurationRuntimeConfigurationprotected final StrolchRealm getRealm(String realm) throws StrolchException
StrolchRealm with the given name. If the realm does not exist, then a
StrolchException is thrownrealm - the name of the StrolchRealm to returnStrolchRealm with the given nameStrolchException - if the StrolchRealm does not exist with the given nameprotected StrolchTransaction openTx(String realm) throws StrolchException
StrolchTransaction for the given realm, the action for the TX is this implementation's class
name. This transaction should be used in a try-with-resource clause so it is properly closedrealm - the name of the realm to returnStrolchTransactionStrolchException - if the StrolchRealm does not exist with the given nameprotected StrolchTransaction openArgOrUserTx(ServiceArgument arg) throws StrolchException
StrolchTransaction by evaluating if the given argument has a realm defined, if not, then the
realm from the user certificate is used. The action for the TX is this implementation's class name. This
transaction should be used in a try-with-resource clause so it is properly closedarg - the ServiceArgumentStrolchTransactionStrolchException - if the StrolchRealm does not exist with the given nameprotected StrolchTransaction openArgOrUserTx(ServiceArgument arg, String action) throws StrolchException
StrolchTransaction by evaluating if the given argument has a realm defined, if not, then the
realm from the user certificate is used. The action for the TX is this implementation's class name. This
transaction should be used in a try-with-resource clause so it is properly closedarg - the ServiceArgumentaction - the action to use for the opened TXStrolchTransactionStrolchException - if the StrolchRealm does not exist with the given nameprotected StrolchTransaction openTx(String realm, String action) throws StrolchException
StrolchTransaction for the given realm. This transaction should be used in a try-with-resource
clause so it is properly closedrealm - the name of the realmaction - the action to use for the opened TXStrolchTransactionStrolchException - if the StrolchRealm does not exist with the given nameprotected StrolchTransaction openUserTx() throws StrolchException
StrolchTransaction where the realm retrieved using
ComponentContainer.getRealm(Certificate), the action for the TX is this implementation's class name. This
transaction should be used in a try-with-resource clause so it is properly closedStrolchTransactionStrolchException - if the StrolchRealm does not exist with the given nameprotected StrolchTransaction openUserTx(String action) throws StrolchException
StrolchTransaction where the realm retrieved using
ComponentContainer.getRealm(Certificate). This transaction should be used in a try-with-resource clause
so it is properly closedaction - the action to use for the opened TXStrolchTransactionStrolchException - if the StrolchRealm does not exist with the given nameprotected void runAs(String username, SystemAction action) throws PrivilegeException
SystemAction as a system user with the given usernameusername - the name of the system user to perform the action asaction - the action to performPrivilegeExceptionprotected <V> V runWithResult(String username, SystemActionWithResult<V> action) throws PrivilegeException
SystemAction as a system user with the given usernameusername - the name of the system user to perform the action asaction - the action to performPrivilegeExceptionprotected void runAs(String username, PrivilegedRunnable runnable) throws PrivilegeException
PrivilegedRunnable as a system user with the given usernameusername - the name of the system user to perform the action asrunnable - the runnable to performPrivilegeExceptionprotected <V> V runWithResult(String username, PrivilegedRunnableWithResult<V> runnable) throws PrivilegeException
PrivilegedRunnableWithResult as a system user with the given usernameusername - the name of the system user to perform the action asrunnable - the runnable to performPrivilegeExceptionprotected void runAsAgent(SystemAction action) throws PrivilegeException
SystemAction as the privileged system user StrolchConstants.SYSTEM_USER_AGENTusername - the name of the system user to perform the action asaction - the action to performPrivilegeExceptionprotected <V> V runAsAgentWithResult(SystemActionWithResult<V> action) throws PrivilegeException
SystemAction as the privileged system user StrolchConstants.SYSTEM_USER_AGENTusername - the name of the system user to perform the action asaction - the action to performPrivilegeExceptionprotected void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException
PrivilegedRunnable as the privileged system user
StrolchConstants.SYSTEM_USER_AGENTaction - the action to performPrivilegeExceptionprotected <V> V runAsAgentWithResult(PrivilegedRunnableWithResult<V> runnable) throws PrivilegeException
PrivilegedRunnableWithResult as the privileged system user
StrolchConstants.SYSTEM_USER_AGENTaction - the action to performPrivilegeExceptionpublic final U doService(T argument)
internalDoService(ServiceArgument)doService in interface Service<T extends ServiceArgument,U extends ServiceResult>argument - the argument for the serviceprotected boolean isArgumentRequired()
protected abstract U getResultInstance()
ServiceResult is
required to return to the callerServiceResult returned by this implementationprotected abstract U internalDoService(T arg) throws Exception
Service. The implementor does not need to handle exceptions as this is
done in the doService(ServiceArgument) which calls this methodarg - the ServiceArgument containing the arguments to perform the concrete serviceServiceResult which denotes the execution state of this ServiceException - if something went wrong. The caller will catch and handle the ServiceResultpublic String getPrivilegeName()
getPrivilegeName in interface RestrictableRestrictable.getPrivilegeName()public Object getPrivilegeValue()
getPrivilegeValue in interface RestrictableRestrictable.getPrivilegeValue()Copyright © 2011–2016 Strolch. All rights reserved.