|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gcube.common.core.contexts.GCUBEContext
org.gcube.common.core.contexts.GCUBEServiceContext
public abstract class GCUBEServiceContext
Partial implementation of contexts for gCube services.
A GCUBEServiceContext exposes the configuration of the service and manages
the lifetime of its Running Instance on the GHN, notifying interesting parties
of key lifetime events. It also acts as a GCUBEServiceSecurityManager and a
GCUBEScopeManager in the rest of the
service implementation .
Typically, the creation of the context is cached.
The following example illustrates a simple but thread-safe caching pattern
for a hypothetical subclass MyServiceContext:
class MyServiceContext {
...
static private MyServiceContext cache = new MyServiceContext();//cache on load
...
private MyServiceContext(){} //force caching
...
public static MyServiceContext getContext() {
return cache;
}
| Nested Class Summary | |
|---|---|
static class |
GCUBEServiceContext.IllegalStateTransitionException
Illegal state transition exception (runtime). |
class |
GCUBEServiceContext.RILifetimeEvent
RI lifetime event. |
static class |
GCUBEServiceContext.RILifetimeTopic
Enumerates RI lifetime topics. |
static class |
GCUBEServiceContext.ServiceSecurityStatus
enum of the security status available |
protected class |
GCUBEServiceContext.Stager
A Consumer for staging INITIALISED RIs. |
static class |
GCUBEServiceContext.StateTransitionException
Illegal state transition exception (runtime). |
static class |
GCUBEServiceContext.Status
Enumerates the possible statuses of the service. |
| Nested classes/interfaces inherited from interface org.gcube.common.core.security.GCUBEServiceSecurityManager |
|---|
GCUBEServiceSecurityManager.LifetimeConsumer, GCUBEServiceSecurityManager.LifetimeEvent, GCUBEServiceSecurityManager.LifetimeTopic |
| Nested classes/interfaces inherited from interface org.gcube.common.core.security.GCUBESecurityManager |
|---|
GCUBESecurityManager.AuthMethod, GCUBESecurityManager.AuthMode, GCUBESecurityManager.DelegationMode |
| Nested classes/interfaces inherited from interface org.gcube.common.core.scope.GCUBEScopeManager |
|---|
GCUBEScopeManager.IllegalScopeException |
| Field Summary | |
|---|---|
static String |
AUTHENTICATION_MANAGER_JNDI_NAME
Name of Authentication Manager JNDI environment. |
static String |
AUTHORISATION_MANAGER_JNDI_NAME
Name of Authorisation Manager JNDI environment. |
static String |
CONFIG_DIR_JNDI_NAME
Name of the configuration directory JNDI environment. |
protected static long |
LISTENER_UPDATE_INTERVAL
Interval for the scheduling of the local credentials listener. |
protected GCUBEProducer<GCUBEServiceContext.RILifetimeTopic,GCUBEServiceContext> |
LTEventProducer
Embedded GCUBEProducer for RI lifetime events. |
static String |
PERSISTENCE_MANAGER_JNDI_NAME
Name of Persistence Manager JNDI environment. |
static String |
PLUGIN_MANAGER_JNDI_NAME
Name of Plugin Manager JNDI environment. |
static String |
PROFILE_FILE_NAME
Name of Service Profile JNDI environment. |
static String |
PROPAGATE_CALLER_CREDENTIALS_JNDI_NAME
Use Caller Credentials property JNDI environment. |
static String |
PUBLISHED_HOST_JNDI_NAME
The name of the host to publish in the local profiles, if different from the container's one |
static String |
PUBLISHED_PORT_JNDI_NAME
The name of the port to publish in the local profiles, if different from the container's one |
static String |
RIPROFILE_FILENAME
Name of the RI serialisation file. |
static String |
SECURITY_MANAGER_JNDI_NAME
Name of Security Manager JNDI environment. |
static String |
START_SCOPES_JNDI_NAME
Name of Start Scopes JNDI environment. |
| Fields inherited from class org.gcube.common.core.contexts.GCUBEContext |
|---|
logger, timers |
| Fields inherited from interface org.gcube.common.core.scope.GCUBEScopeManager |
|---|
CLASS_HEADER_NAME, DEFAULT, NAME_HEADER_NAME, SCOPE_HEADER_NAME, SCOPE_NS |
| Constructor Summary | |
|---|---|
protected |
GCUBEServiceContext()
Creates and preinitialises an instance. |
| Method Summary | |
|---|---|
Set<GCUBEScope> |
addScope(GCUBEScope... scopes)
Adds one or more scopes to the service instance. |
GCUBEServiceAuthenticationController |
getAuthenticationManager()
|
GCUBEServiceAuthorizationController |
getAuthorizationManager()
|
SecurityCredentials |
getCallerCredentials()
If security is enabled, it extracts credentials from the current request. |
SecurityCredentials |
getCredentials()
It returns the credentials for outgoing calls currently set in the current thread. |
GCUBEException |
getDefaultException(String msg,
Throwable cause)
Returns the default exception |
GCUBEException |
getDefaultException(Throwable cause)
Returns the default exception |
File |
getFile(String path,
boolean... writeMode)
Gives read or write access to a File. |
String |
getID()
Returns the service identifier. |
GCUBERunningInstance |
getInstance()
Returns the GCUBERunningInstance resource of the service. |
protected abstract String |
getJNDIName()
Return the name of the port-type in the JNDI configuration |
GCUBELog |
getLogger()
Returns the context's logger. |
RI |
getManagementBean()
Return the management bean of the Running Instance. |
String |
getName()
Returns the name of the service. |
File |
getPersistenceRoot()
Returns the root of persistence of the Running Instance on the local file system. |
File |
getPersistentFile(String path,
boolean... writeMode)
Gives read or write access to a File that will persist across redployments of the Running Instance. |
GCUBEPluginManager<?> |
getPluginManager()
Returns the plugin manager. |
GCUBEAuthzPolicy |
getPolicy()
Returns the current authorisation policy. |
Object |
getProperty(String prop,
boolean... required)
Resolve a configuration property against the naming service. |
GCUBEScope |
getScope()
Gets the scope for outgoing calls in the current thread. |
GCUBEScopeManager |
getScopeManager()
Returns the inner scope manager used by the context. |
GCUBEServiceSecurityManager |
getSecurityManager()
Returns the GCUBEServiceSecurityManager
to which the context will delegate security-related functionality. |
GCUBEService |
getService()
Returns the GCUBEService resource of the service. |
String |
getServiceClass()
Returns the name of the service. |
SecurityCredentials |
getServiceCredentials()
If security is enabled, it returns the service credentials. |
GCUBEServiceContext.ServiceSecurityStatus |
getServiceSecurityStatus()
|
GCUBEScope[] |
getStartScopes()
Gets the start scopes of the RI. |
GCUBEServiceContext.Status |
getStatus()
Returns the current status of the service. |
void |
initialise(GCUBEServiceContext ctxt)
Initialise the manager with the context of the associated service. |
boolean |
isSecurityEnabled()
Indicates whether the manager is operating in a secure context. |
boolean |
needServiceCredentials()
Indicates whether the service makes use of service credentials. |
void |
notifyStateChange()
Notifies of a change to the persistent state of the RI. |
protected void |
onFailure()
Invoked when the Running Instance fails. |
protected void |
onInitialisation()
Invoked when the Running Instance has completed initialisation. |
protected void |
onReady()
Invoked when the Running Instance is ready to operate. |
protected void |
onShutdown()
Invoked when the Running Instance is going down. |
protected void |
onStateChange()
Invoked upon a change to the RI's stateful resources, if any. |
protected void |
onUpdate()
Invoked when the Runnning Instance is updated. |
void |
prepareCall(Remote remote,
String clazz,
String name,
GCUBEScope... scope)
Sets the scope for an outgoing call to a target gCube service. |
void |
propagateCallerCredentials(boolean propagateCallerCredentials)
Indicates whether the service, without any further configurationm, makes use of caller credentials: by default is true and, if false, the service will use its own credentials (without further configuration) to perform calls |
Set<GCUBEScope> |
removeScope(GCUBEScope... scopes)
Removes one or more scopes from the service instance. |
void |
setAuthMethod(GCUBESecurityManager.AuthMethod m)
Adds an authentication method to be used in this security context |
void |
setScope(GCUBEScope scope)
Sets the scope of outgoing calls in the current thread. |
void |
setScope(Thread thread,
GCUBEScope... scope)
Deprecated. |
void |
setScope(Thread thread,
GCUBEScope scope)
Deprecated. |
void |
setSecurity(Remote s,
GCUBESecurityManager.AuthMode e,
GCUBESecurityManager.DelegationMode d)
If security is enabled, sets the desired level of encryption and the mode of credential delegation on the stub of a remote porttype. |
void |
setStatus(GCUBEServiceContext.Status status)
Sets the current status of the service. |
void |
subscribe(GCUBEServiceSecurityManager.LifetimeConsumer c,
GCUBEServiceSecurityManager.LifetimeTopic... topics)
Subscribes a GCUBEServiceSecurityManager.LifetimeConsumer. |
void |
subscribeLifetTime(Consumer consumer,
GCUBEServiceContext.RILifetimeTopic... topics)
Subscribes a consumer to RI lifetime events for one or more RI lifetime topics. |
void |
unsubscribe(GCUBEServiceSecurityManager.LifetimeConsumer c,
GCUBEServiceSecurityManager.LifetimeTopic... topics)
Unsubscribes a GCUBEServiceSecurityManager.LifetimeConsumer. |
void |
unsubscribeLifetTime(Consumer consumer,
GCUBEServiceContext.RILifetimeTopic... topics)
Unsubscribes a consumer from RI lifetime events for one or more RI lifetime topics. |
void |
useCallerCredentials(Thread... thread)
If security is enabled, it indicates that outgoing calls in a given thread must use the credentials associated with the incoming call. |
void |
useCredentials(GSSCredential credentials)
Deprecated. |
void |
useCredentials(SecurityCredentials credentials)
If security is enabled, it sets given credentials for outgoing calls in the current thread. |
void |
useCredentials(Thread thread,
SecurityCredentials... credentials)
If security is enabled, it sets given credentials for outgoing calls in a given thread. |
void |
useServiceCredentials(Thread... thread)
If security is enabled, it indicates that outgoing calls in the current thread must use service credentials. |
| Methods inherited from class org.gcube.common.core.contexts.GCUBEContext |
|---|
debugContext, getJNDIContext, getResource, getTiming, printContext, resetTimer, setJNDIContext |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String CONFIG_DIR_JNDI_NAME
public static final String PROFILE_FILE_NAME
public static final String PERSISTENCE_MANAGER_JNDI_NAME
public static final String PLUGIN_MANAGER_JNDI_NAME
public static final String START_SCOPES_JNDI_NAME
public static final String PUBLISHED_HOST_JNDI_NAME
public static final String PUBLISHED_PORT_JNDI_NAME
public static final String RIPROFILE_FILENAME
protected static final long LISTENER_UPDATE_INTERVAL
public static final String SECURITY_MANAGER_JNDI_NAME
public static final String AUTHENTICATION_MANAGER_JNDI_NAME
public static final String AUTHORISATION_MANAGER_JNDI_NAME
public static final String PROPAGATE_CALLER_CREDENTIALS_JNDI_NAME
protected GCUBEProducer<GCUBEServiceContext.RILifetimeTopic,GCUBEServiceContext> LTEventProducer
GCUBEProducer for RI lifetime events.
| Constructor Detail |
|---|
protected GCUBEServiceContext()
| Method Detail |
|---|
public GCUBELog getLogger()
protected abstract String getJNDIName()
public GCUBEService getService()
GCUBEService resource of the service.
public GCUBERunningInstance getInstance()
GCUBERunningInstance resource of the service.
public RI getManagementBean()
public File getFile(String path,
boolean... writeMode)
throws IllegalArgumentException
File.
Write access induces backups and read access relies on backups to recover from failures.
getFile in class GCUBEContextpath - the file path.writeMode - (optional) the access mode, true for write access and false for read access (default).
IllegalArgumentException - if access is in write mode and the path is to a folder.
public File getPersistentFile(String path,
boolean... writeMode)
throws IllegalArgumentException
File that will persist across redployments of the Running Instance.
path - the file path.writeMode - (optional) the access mode, true for write access and false for read access (default).
IllegalArgumentException - if access is in write mode and the path is to a folder.GCUBEContext.getFile(String, boolean...)public File getPersistenceRoot()
public Object getProperty(String prop,
boolean... required)
throws RuntimeException
getProperty in class GCUBEContextprop - the property.required - (optional) true if the property is required, false or omitted if property is optional.
The only implication is a different handling of failure and logging. Failure in resolving optional properties results in a runtime
exception and fatal log entry, whereas failure in resolving optional properties results in a null result and warning
in the log.
null if the property was optional and could not be resolved.
RuntimeException - if the property is required but cannot be resolved.public String getID()
public String getServiceClass()
public String getName()
getName in class GCUBEContext
public void setStatus(GCUBEServiceContext.Status status)
throws GCUBEServiceContext.IllegalStateTransitionException,
GCUBEServiceContext.StateTransitionException
status - the status.
GCUBEServiceContext.IllegalStateTransitionException - if the transition from the current state to the required state is illegal.
GCUBEServiceContext.StateTransitionExceptionpublic GCUBEServiceContext.ServiceSecurityStatus getServiceSecurityStatus()
public GCUBEServiceContext.Status getStatus()
public GCUBEException getDefaultException(String msg,
Throwable cause)
msg - the fault message.cause - (optional) the cause of the fault.
GCUBEFault.public GCUBEException getDefaultException(Throwable cause)
cause - the cause of the fault.
GCUBEFault.public GCUBEServiceSecurityManager getSecurityManager()
GCUBEServiceSecurityManager
to which the context will delegate security-related functionality.
If not otherwise configured, it returns a GCUBESimpleServiceSecurityManager
suitable for services which, when deployed in a secure environment, either propagate caller credentials or else do not use security altogether.
Services which instead need to use their own credentials can configure the service to use a GCUBEServiceSecurityManagerImpl
or, if available, an alternative implementation of the GCUBEServiceSecurityManager interface.
public void setSecurity(Remote s,
GCUBESecurityManager.AuthMode e,
GCUBESecurityManager.DelegationMode d)
throws Exception
setSecurity in interface GCUBESecurityManagers - the stub.e - the encryption level.d - the delegation mode.
Exception - if the settings could not be enforced.public boolean isSecurityEnabled()
isSecurityEnabled in interface GCUBESecurityManagertrue if security is enabled, false otherwise.public SecurityCredentials getCredentials()
getCredentials in interface GCUBESecurityManagerpublic GCUBEAuthzPolicy getPolicy()
getPolicy in interface GCUBEServiceSecurityManager
public void initialise(GCUBEServiceContext ctxt)
throws Exception
initialise in interface GCUBEServiceSecurityManagerctxt - the context.
Exception
public SecurityCredentials getServiceCredentials()
throws Exception
getServiceCredentials in interface GCUBEServiceSecurityManagernull if security is not enabled.
Exception - if security is enabled, but service credentials could not be produced.
public SecurityCredentials getCallerCredentials()
throws Exception
getCallerCredentials in interface GCUBEServiceSecurityManagernull if security is not enabled.
Exception - if security is enabled, but credentials could not be extracted from incoming call.
public void useCredentials(SecurityCredentials credentials)
throws Exception
useCredentials in interface GCUBESecurityManagercredentials - the credentials.
Exception - if security is enabled, but credentials are corrupt.
public void useCredentials(Thread thread,
SecurityCredentials... credentials)
throws Exception
useCredentials in interface GCUBESecurityManagerthread - the thread.credentials - (optional) the credentials. If omitted, it delegates the credentials used for
the current thread to the given thread.
Exception - if security is enabled, but credentials are corrupt.public boolean needServiceCredentials()
needServiceCredentials in interface GCUBEServiceSecurityManagertrue if it does, false if it does not.public void propagateCallerCredentials(boolean propagateCallerCredentials)
propagateCallerCredentials in interface GCUBEServiceSecurityManagerpublic void setAuthMethod(GCUBESecurityManager.AuthMethod m)
setAuthMethod in interface GCUBESecurityManagerm - the authentication method
@Deprecated
public void useCredentials(GSSCredential credentials)
throws Exception
useCredentials in interface GCUBESecurityManagercredentials - the credentials.
Exception - if security is enabled, but credentials are corrupt.
public void subscribe(GCUBEServiceSecurityManager.LifetimeConsumer c,
GCUBEServiceSecurityManager.LifetimeTopic... topics)
GCUBEServiceSecurityManager.LifetimeConsumer..
subscribe in interface GCUBEServiceSecurityManagerc - the consumer.
public void unsubscribe(GCUBEServiceSecurityManager.LifetimeConsumer c,
GCUBEServiceSecurityManager.LifetimeTopic... topics)
GCUBEServiceSecurityManager.LifetimeConsumer..
unsubscribe in interface GCUBEServiceSecurityManagerc - the consumer.public GCUBEServiceAuthenticationController getAuthenticationManager()
public GCUBEServiceAuthorizationController getAuthorizationManager()
public void useCallerCredentials(Thread... thread)
throws Exception
An invocation of this method is equivalent to:
context.useCredentials(context.getCallerCredentials()) or context.useCredentials(thread, context.getCallerCredentials())
thread - (optional) the thread. If omitted, the current thread is assumed.
Exception - if security is enabled but the caller credentials could not be used.
public void useServiceCredentials(Thread... thread)
throws Exception
An invocation of this method is equivalent to:
context.useCredentials(context.getServiceCredentials(name)) or
context.useCredentials(thread,context.getServiceCredentials(name))
* @param thread (optional) the thread. If omitted, the current thread is assumed.
Exception - if security is enabled but service credentials could not be produced.public GCUBEScope[] getStartScopes()
public GCUBEScopeManager getScopeManager()
public GCUBEScope getScope()
getScope in interface GCUBEScopeManager
public void prepareCall(Remote remote,
String clazz,
String name,
GCUBEScope... scope)
prepareCall in interface GCUBEScopeManagerremote - the stub of the target port-type.clazz - the gCube class of the target service.name - the gCube name of the target service.scope - (optional) the scope of the call. If omitted, the scope associated with the current thread will be used.GCUBERemotePortTypeContext.getProxy(Remote, org.gcube.common.core.contexts.GCUBEServiceContext),
GCUBERemotePortTypeContext.getProxy(Remote, GCUBEScope, org.gcube.common.core.security.GCUBESecurityManager...),
GCUBERemotePortTypeContext.getProxy(Remote, GCUBEScopeManager, org.gcube.common.core.security.GCUBESecurityManager...)
public void setScope(GCUBEScope scope)
throws GCUBEScopeManager.IllegalScopeException
setScope in interface GCUBEScopeManagerscope - the scope.
GCUBEScopeManager.IllegalScopeException
@Deprecated
public void setScope(Thread thread,
GCUBEScope scope)
throws GCUBEScopeManager.IllegalScopeException
GCUBEScopeManager.IllegalScopeException
@Deprecated
public void setScope(Thread thread,
GCUBEScope... scope)
throws GCUBEScopeManager.IllegalScopeException
setScope in interface GCUBEScopeManagerthread - the thread.scope - (optional) the scope. If omitted, it defaults to the scope of the current thread.
GCUBEScopeManager.IllegalScopeExceptionpublic Set<GCUBEScope> addScope(GCUBEScope... scopes)
scopes - the scopes.
IllegalArgumentException - if no scopes are provided in input.public Set<GCUBEScope> removeScope(GCUBEScope... scopes)
scopes - the scopes.
IllegalArgumentException - if no scopes are provided in input.public GCUBEPluginManager<?> getPluginManager()
public void subscribeLifetTime(Consumer consumer,
GCUBEServiceContext.RILifetimeTopic... topics)
throws Exception
consumer - the consumer.topics - the topics of interest.
Exception - if the subscription could not be completed.
public void unsubscribeLifetTime(Consumer consumer,
GCUBEServiceContext.RILifetimeTopic... topics)
consumer - the consumer.topics - the topics.public void notifyStateChange()
protected void onInitialisation()
throws Exception
Exception - if the callback did not complete successfully.
protected void onReady()
throws Exception
Exception - if the callback did not complete successfully.
protected void onShutdown()
throws Exception
Exception - if the callback did not complete successfully.
protected void onFailure()
throws Exception
Exception - if the callback did not complete successfully.
protected void onUpdate()
throws Exception
Exception - if the callback did not complete successfully.
protected void onStateChange()
throws Exception
Exception - if the callback did not complete successfully.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||