public class SecurityManager.ContextSecurityManager
extends java.lang.Object
| Constructor and Description |
|---|
ContextSecurityManager() |
| Modifier and Type | Method and Description |
|---|---|
(package private) boolean |
addToken(ContextKey key,
java.lang.Object token)
Adds a token to the context map.
|
private void |
assignContext(SecurityContext context)
Assign the current thread to the given security context, and add a
unique identifier for this thread to the thread ID map.
|
private SecurityContext |
createSecurityContext(SecurityCache sc,
java.lang.String pid,
java.lang.String uid)
Private worker method that creates a new security context.
|
void |
dropInitialSecurityContext()
Releases the initial security context assigned to the calling thread.
|
private void |
endContext(SecurityContextStack cts,
SecurityContext ctx)
Worker routine to centralize unassignment and cleanup (if this was the
final usage) of the given context.
|
(package private) void |
forceSecurityContext(SecurityContextStack stack,
boolean create)
Initializes the security context switching for the calling thread using the given context
stack as the source of the initial and effective contexts.
|
javax.net.ssl.SSLContext |
getSecureSocketContext()
Initializes and returns a valid SSL environment.
|
javax.net.ssl.SSLContext |
getSecureSocketContext(BootstrapConfig config)
Initializes and returns a valid SSL environment.
|
java.lang.Object |
getToken(ContextKey key)
Gets the token from the context map.
|
boolean |
hasContext()
Detects if there is a valid context associated with the current thread.
|
boolean |
hasToken(ContextKey key)
Checks whether the specified token is in the context map.
|
private void |
logContext(SecurityCache cache,
SecurityContext ctx)
Creates an audit record for security context switch event.
|
private void |
logGoingContext(SecurityContext ctx)
Creates an audit record for a terminated security context.
|
private void |
logNewContext(SecurityCache cache,
SecurityContext ctx)
Creates an audit record for security context creation event.
|
(package private) void |
popAllSecurityContext()
Terminates all security contexts associated with the current thread,
including the initial context.
|
void |
popAndRestoreSecurityContext()
Restores the initial security context of the calling thread when it is
done with the user request.
|
private void |
popContextWorker()
Restores the initial security context of the calling thread when it is
done with the user request.
|
void |
pushAndSwitchSecurityContext(java.lang.Object key)
Temporarily switches to a user context to serve the associated request.
|
void |
pushAndSwitchSecurityContextBySessionId(java.lang.Object sessionId)
Temporarily switches to a user context to serve the associated request.
|
(package private) void |
pushContextWorker(java.lang.Object key)
Temporarily switches to a user context to serve the associated request.
|
(package private) boolean |
removeToken(ContextKey key)
Remove a token from the context map.
|
void |
resetContext()
Reset the effective security context associated with the current thread.
|
void |
setHeadless()
Mark this context in headless mode.
|
void |
setInitialSecurityContext()
Initializes security context switching for the calling thread.
|
private void |
setInitialSecurityContextWorker(boolean unique,
SecurityContextStack stack)
Drops any current context (if any) and establishes an initial context
for the thread.
|
void |
setUniqueInitialSecurityContext()
Initializes security context switching for the calling thread making
sure that the context is newly created and is not shared with any other
thread.
|
private boolean |
unassignContext(SecurityContext context)
Unassign the current thread from the given security context, and remove
its entry from the thread ID map.
|
public void setHeadless()
boolean addToken(ContextKey key, java.lang.Object token)
key - token key to be used as a key in the maptoken - an arbitrary object to be kept in the entrytrue if the token is added successfullypublic boolean hasToken(ContextKey key)
key - token key to be used as a key in the maptrue if the token is foundpublic java.lang.Object getToken(ContextKey key)
key - token key to be used as a key in the mapnullboolean removeToken(ContextKey key)
key - token key to be used as a key in the maptrue if the token was removed successfullypublic boolean hasContext()
true if there is a valid security context.private void assignContext(SecurityContext context)
context - Security context to be assigned.private boolean unassignContext(SecurityContext context)
context - Security context to be unassigned.public void resetContext()
throws RestrictedUseException
RestrictedUseException - If called outside of expected code.public void setInitialSecurityContext()
throws RestrictedUseException
This call immediately exits if called from the client.
If this call is made repeatedly, it checks whether the security cache is refreshed compared to the generation of the cache used to create the initial security context currently in use. If this is the case, the old security context is released and replaced with the current one.
Restricted use. This method checks the caller to be:
RestrictedUseException - if called improperlypublic void setUniqueInitialSecurityContext()
throws RestrictedUseException
This call is supposed to be repeatable for permanent threads to allow proper security cache refresh function.
This call immediately exits if called from the client.
If this call is made repeatedly, it checks whether the security cache is refreshed compared to the generation of the cache used to create the initial security context currently in use. If this is the case, the old security context is released and replaced with the current one.
Restricted use. This method checks the caller to be:
RestrictedUseException - if called improperlyvoid forceSecurityContext(SecurityContextStack stack, boolean create)
This does not check or enforce session limits (e.g. max number of user sessions) because it relies upon an already existing security context. In other words, we are not adding a new user-level session but instead we are just properly initializing additional threads.
stack - Context stack to use instead of creating a new one. This allows the caller to
override the initial and effective contexts.create - true to add a new session for the effective context. The new session
will not be associated with any network session nor will there be an
authentication process. Instead, the previously authenticated effective context
will be used to pattern a new session.private void setInitialSecurityContextWorker(boolean unique,
SecurityContextStack stack)
unique - true to instantiate a new context that is not
associated with the current server account and does not share
any context-local data. false to get the standard
server-wide initial context which is associated with the
server's account AND shares context-local data with all other
server threads that also share this initial context. This
parameter is only honored if the context parameter
is null.stack - Optional context stack to use instead of creating a new one.
This allows the caller to override the initial and effective
contexts.public void dropInitialSecurityContext()
If called improperly, has no effect.
public javax.net.ssl.SSLContext getSecureSocketContext()
throws java.security.NoSuchAlgorithmException,
java.security.KeyStoreException,
java.security.UnrecoverableKeyException,
java.security.KeyManagementException,
ConfigurationException,
java.security.NoSuchProviderException
java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.KeyManagementExceptionConfigurationExceptionjava.security.NoSuchProviderExceptionpublic javax.net.ssl.SSLContext getSecureSocketContext(BootstrapConfig config) throws java.security.NoSuchAlgorithmException, java.security.KeyStoreException, java.security.UnrecoverableKeyException, java.security.KeyManagementException, ConfigurationException, java.security.NoSuchProviderException
config - Bootstrap configuration information used to initialize the
secure socket context.java.security.NoSuchAlgorithmExceptionjava.security.KeyStoreExceptionjava.security.UnrecoverableKeyExceptionjava.security.KeyManagementExceptionConfigurationExceptionjava.security.NoSuchProviderExceptionpublic void pushAndSwitchSecurityContext(java.lang.Object key)
throws RestrictedUseException
The use count for the target security context is incremented by 1.
key - security context keyRestrictedUseException - If called improperly.public void pushAndSwitchSecurityContextBySessionId(java.lang.Object sessionId)
throws RestrictedUseException
The use count for the target security context is incremented by 1.
sessionId - session idRestrictedUseException - If called improperly.void pushContextWorker(java.lang.Object key)
throws RestrictedUseException
The use count for the target security context is incremented by 1.
key - security context keyRestrictedUseException - If called improperly.public void popAndRestoreSecurityContext()
throws RestrictedUseException
The use count for the current security context is decremented by 1. If it becomes 0, it gets deleted immediately.
RestrictedUseException - If called from an unauthorized location.void popAllSecurityContext()
throws RestrictedUseException
setUniqueInitialSecurityContext(). If this
is not used, then the unique initial contexts will never be cleaned up
and there will be a memory leak.
The use count for the all security contexts is decremented by 1. If it becomes 0, it gets deleted immediately.
RestrictedUseException - If called from an unauthorized location.private void popContextWorker()
throws RestrictedUseException
The use count for the current security context is decremented by 1. If it becomes 0, it gets deleted immediately.
RestrictedUseException - If called improperly.private void endContext(SecurityContextStack cts, SecurityContext ctx)
cts - The context stack for the current thread.ctx - The context to end.private SecurityContext createSecurityContext(SecurityCache sc, java.lang.String pid, java.lang.String uid)
sc - SecurityCache where new security context belongspid - process ID for new security contextuid - user ID for new security contextSecurityContextprivate void logNewContext(SecurityCache cache, SecurityContext ctx)
cache - security cache where to log this eventctx - security contextprivate void logContext(SecurityCache cache, SecurityContext ctx)
cache - security cache where to log this eventctx - coming security context, may be nullprivate void logGoingContext(SecurityContext ctx)
ctx - security context