Class AbstractJaasAuthenticationProvider
- All Implemented Interfaces:
- EventListener,- org.springframework.beans.factory.Aware,- org.springframework.beans.factory.InitializingBean,- org.springframework.context.ApplicationEventPublisherAware,- org.springframework.context.ApplicationListener<SessionDestroyedEvent>,- AuthenticationProvider
- Direct Known Subclasses:
- DefaultJaasAuthenticationProvider,- JaasAuthenticationProvider
AuthenticationProvider implementation that retrieves user details from a
 JAAS login configuration.
 
 This AuthenticationProvider is capable of validating
 UsernamePasswordAuthenticationToken
 requests contain the correct username and password.
 
 This implementation is backed by a
 
 JAAS configuration that is provided by a subclass's implementation of
 createLoginContext(CallbackHandler).
 
 When using JAAS login modules as the authentication source, sometimes the  LoginContext will require CallbackHandlers. The
 AbstractJaasAuthenticationProvider uses an internal CallbackHandler  to wrap the JaasAuthenticationCallbackHandlers configured
 in the ApplicationContext. When the LoginContext calls the internal CallbackHandler,
 control is passed to each JaasAuthenticationCallbackHandler for each Callback
 passed.
 
 JaasAuthenticationCallbackHandlers are passed to the
 AbstractJaasAuthenticationProvider through the
 callbackHandlers property.
 
 <property name="callbackHandlers">
   <list>
     <bean class="org.springframework.security.authentication.jaas.TestCallbackHandler"/>
     <bean class="org.springframework.security.authentication.jaas.JaasNameCallbackHandler"/>
     <bean class="org.springframework.security.authentication.jaas.JaasPasswordCallbackHandler"/>
  </list>
 </property>
 
 
 After calling LoginContext.login(), the AbstractJaasAuthenticationProvider will
 retrieve the returned Principals from the Subject
 (LoginContext.getSubject().getPrincipals). Each returned principal is then passed to
 the configured AuthorityGranters. An AuthorityGranter is a mapping between a
 returned Principal, and a role name. If an AuthorityGranter wishes to grant an
 Authorization a role, it returns that role name from it's
 AuthorityGranter.grant(java.security.Principal) method. The returned role will
 be applied to the Authorization object as a GrantedAuthority.
 
AuthorityGranters are configured in spring xml as follows...
 <property name="authorityGranters">
   <list>
     <bean class="org.springframework.security.authentication.jaas.TestAuthorityGranter"/>
   </list>
  </property>
 - 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidValidates the required properties are set.@Nullable Authenticationauthenticate(Authentication auth) Attempts to login the user given the Authentication objects principal and credentialprotected abstract LoginContextcreateLoginContext(CallbackHandler handler) Creates the LoginContext to be used for authentication.protected org.springframework.context.ApplicationEventPublisherprotected voidHandles the logout by getting the security contexts for the destroyed session and invokingLoginContext.logout()for any which contain aJaasAuthenticationToken.voidprotected voidPublishes theJaasAuthenticationFailedEvent.protected voidPublishes theJaasAuthenticationSuccessEvent.voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) voidsetAuthorityGranters(AuthorityGranter[] authorityGranters) Set the AuthorityGranters that should be consulted for role names to be granted to the Authentication.voidsetCallbackHandlers(JaasAuthenticationCallbackHandler[] callbackHandlers) Set the JAASAuthenticationCallbackHandler array to handle callback objects generated by the LoginContext.login method.voidsetLoginContextName(String loginContextName) Set the loginContextName, this name is used as the index to the configuration specified in the loginConfig property.voidsetLoginExceptionResolver(LoginExceptionResolver loginExceptionResolver) booleanReturnstrueif thisAuthenticationProvidersupports the indicatedAuthenticationobject.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListenersupportsAsyncExecution
- 
Field Details- 
logprotected final org.apache.commons.logging.Log log
 
- 
- 
Constructor Details- 
AbstractJaasAuthenticationProviderpublic AbstractJaasAuthenticationProvider()
 
- 
- 
Method Details- 
afterPropertiesSetValidates the required properties are set. In addition, ifsetCallbackHandlers(JaasAuthenticationCallbackHandler[])has not been called with valid handlers, initializes to useJaasNameCallbackHandlerandJaasPasswordCallbackHandler.- Specified by:
- afterPropertiesSetin interface- org.springframework.beans.factory.InitializingBean
- Throws:
- Exception
 
- 
authenticateAttempts to login the user given the Authentication objects principal and credential- Specified by:
- authenticatein interface- AuthenticationProvider
- Parameters:
- auth- The Authentication object to be authenticated.
- Returns:
- The authenticated Authentication object, with it's grantedAuthorities set.
- Throws:
- AuthenticationException- This implementation does not handle 'locked' or 'disabled' accounts. This method only throws a AuthenticationServiceException, with the message of the LoginException that will be thrown, should the loginContext.login() method fail.
 
- 
createLoginContextCreates the LoginContext to be used for authentication.- Parameters:
- handler- The CallbackHandler that should be used for the LoginContext (never- null).
- Returns:
- the LoginContext to use for authentication.
- Throws:
- LoginException
 
- 
handleLogoutHandles the logout by getting the security contexts for the destroyed session and invokingLoginContext.logout()for any which contain aJaasAuthenticationToken.- Parameters:
- event- the session event which contains the current session
 
- 
onApplicationEvent- Specified by:
- onApplicationEventin interface- org.springframework.context.ApplicationListener<SessionDestroyedEvent>
 
- 
publishFailureEventprotected void publishFailureEvent(UsernamePasswordAuthenticationToken token, AuthenticationException ase) Publishes theJaasAuthenticationFailedEvent. Can be overridden by subclasses for different functionality- Parameters:
- token- The authentication token being processed
- ase- The exception that caused the authentication failure
 
- 
publishSuccessEventPublishes theJaasAuthenticationSuccessEvent. Can be overridden by subclasses for different functionality.- Parameters:
- token- The token being processed
 
- 
setAuthorityGrantersSet the AuthorityGranters that should be consulted for role names to be granted to the Authentication.- Parameters:
- authorityGranters- AuthorityGranter array
- See Also:
 
- 
setCallbackHandlersSet the JAASAuthenticationCallbackHandler array to handle callback objects generated by the LoginContext.login method.- Parameters:
- callbackHandlers- Array of JAASAuthenticationCallbackHandlers
 
- 
setLoginContextNameSet the loginContextName, this name is used as the index to the configuration specified in the loginConfig property.- Parameters:
- loginContextName-
 
- 
setLoginExceptionResolver
- 
supportsDescription copied from interface:AuthenticationProviderReturnstrueif thisAuthenticationProvidersupports the indicatedAuthenticationobject.Returning truedoes not guarantee anAuthenticationProviderwill be able to authenticate the presentedAuthenticationobject. It simply indicates it can support closer evaluation of it. AnAuthenticationProvidercan still returnnullfrom theAuthenticationProvider.authenticate(Authentication)method to indicate anotherAuthenticationProvidershould be tried.Selection of an AuthenticationProvidercapable of performing authentication is conducted at runtime by theProviderManager.- Specified by:
- supportsin interface- AuthenticationProvider
- Returns:
- trueif the implementation can more closely evaluate the- Authenticationclass presented
 
- 
setApplicationEventPublisherpublic void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) - Specified by:
- setApplicationEventPublisherin interface- org.springframework.context.ApplicationEventPublisherAware
 
- 
getApplicationEventPublisherprotected org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
 
-