Class SecurityContextLoginModule
java.lang.Object
org.springframework.security.authentication.jaas.SecurityContextLoginModule
- All Implemented Interfaces:
LoginModule
An implementation of
LoginModule that uses a Spring Security
SecurityContext to
provide authentication.
This LoginModule provides opposite functionality to the
JaasAuthenticationProvider API, and should not really be used in conjunction
with it.
The JaasAuthenticationProvider allows Spring Security to authenticate against
Jaas.
The SecurityContextLoginModule allows a Jaas based application to authenticate against
Spring Security. If there is no Authentication in the SecurityContextHolder the
login() method will throw a LoginException by default. This functionality can be
changed with the ignoreMissingAuthentication option by setting it to "true".
Setting ignoreMissingAuthentication=true will tell the SecurityContextLoginModule to
simply return false and be ignored if the authentication is null.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanabort()Abort the authentication process by forgetting the Spring SecurityAuthentication.booleancommit()Authenticate theSubject(phase two) by adding the Spring SecurityAuthenticationto theSubject's principals.voidinitialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) Initialize thisLoginModule.booleanlogin()Authenticate theSubject(phase one) by extracting the Spring SecurityAuthenticationfrom the currentSecurityContext.booleanlogout()Log out theSubject.voidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.
-
Constructor Details
-
SecurityContextLoginModule
public SecurityContextLoginModule()
-
-
Method Details
-
abort
public boolean abort()Abort the authentication process by forgetting the Spring SecurityAuthentication.- Specified by:
abortin interfaceLoginModule- Returns:
- true if this method succeeded, or false if this
LoginModuleshould be ignored.
-
commit
public boolean commit()Authenticate theSubject(phase two) by adding the Spring SecurityAuthenticationto theSubject's principals.- Specified by:
commitin interfaceLoginModule- Returns:
- true if this method succeeded, or false if this
LoginModuleshould be ignored.
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-
initialize
public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) Initialize thisLoginModule. Ignores the callback handler, since the code establishing theLoginContextlikely won't provide one that understands Spring Security. Also ignores thesharedStateandoptionsparameters, since none are recognized.- Specified by:
initializein interfaceLoginModule- Parameters:
subject- theSubjectto be authenticated.callbackHandler- is ignoredsharedState- is ignoredoptions- are ignored
-
login
Authenticate theSubject(phase one) by extracting the Spring SecurityAuthenticationfrom the currentSecurityContext.- Specified by:
loginin interfaceLoginModule- Returns:
- true if the authentication succeeded, or false if this
LoginModuleshould be ignored. - Throws:
LoginException- if the authentication fails
-
logout
public boolean logout()Log out theSubject.- Specified by:
logoutin interfaceLoginModule- Returns:
- true if this method succeeded, or false if this
LoginModuleshould be ignored.
-