|
Spring Security Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.security.context.SecurityContextHolder
public class SecurityContextHolder
Associates a given SecurityContext
with the current execution thread.
This class provides a series of
static methods that delegate to an instance of SecurityContextHolderStrategy
. The
purpose of the class is to provide a convenient way to specify the strategy that should be used for a given JVM.
This is a JVM-wide setting, since everything in this class is static
to facilitate ease of use in
calling code.
To specify which strategy should be used, you must provide a mode setting. A mode setting is one of the
three valid MODE_
settings defined as static final
fields, or a fully qualified classname
to a concrete implementation of SecurityContextHolderStrategy
that provides a
public no-argument constructor.
There are two ways to specify the desired strategy mode String
. The first is to specify it via
the system property keyed on SYSTEM_PROPERTY
. The second is to call setStrategyName(String)
before using the class. If neither approach is used, the class will default to using MODE_THREADLOCAL
,
which is backwards compatible, has fewer JVM incompatibilities and is appropriate on servers (whereas MODE_GLOBAL
is definitely inappropriate for server use).
HttpSessionContextIntegrationFilter
Field Summary | |
---|---|
static String |
MODE_GLOBAL
|
static String |
MODE_INHERITABLETHREADLOCAL
|
static String |
MODE_THREADLOCAL
|
static String |
SYSTEM_PROPERTY
|
Constructor Summary | |
---|---|
SecurityContextHolder()
|
Method Summary | |
---|---|
static void |
clearContext()
Explicitly clears the context value from the current thread. |
static SecurityContext |
getContext()
Obtain the current SecurityContext . |
static int |
getInitializeCount()
Primarily for troubleshooting purposes, this method shows how many times the class has reinitialized its SecurityContextHolderStrategy . |
static void |
setContext(SecurityContext context)
Associates a new SecurityContext with the current thread of execution. |
static void |
setStrategyName(String strategyName)
Changes the preferred strategy. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String MODE_THREADLOCAL
public static final String MODE_INHERITABLETHREADLOCAL
public static final String MODE_GLOBAL
public static final String SYSTEM_PROPERTY
Constructor Detail |
---|
public SecurityContextHolder()
Method Detail |
---|
public static void clearContext()
public static SecurityContext getContext()
SecurityContext
.
null
)public static int getInitializeCount()
SecurityContextHolderStrategy
.
setStrategyName(String)
to switch to an alternate
strategy.public static void setContext(SecurityContext context)
SecurityContext
with the current thread of execution.
context
- the new SecurityContext
(may not be null
)public static void setStrategyName(String strategyName)
strategyName
- the fully qualified classname of the strategy that should be used.public String toString()
toString
in class Object
|
Spring Security Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |