Class JaasAuthenticationProvider

  extended by
      extended by
All Implemented Interfaces:
EventListener, Aware, InitializingBean, ApplicationEventPublisherAware, ApplicationListener<SessionDestroyedEvent>, AuthenticationProvider

public class JaasAuthenticationProvider
extends AbstractJaasAuthenticationProvider

An 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. The loginConfig property must be set to a given JAAS configuration file. This setter accepts a Spring Resource instance. It should point to a JAAS configuration file containing an index matching the loginContextName property.

For example: If this JaasAuthenticationProvider were configured in a Spring WebApplicationContext the xml to set the loginConfiguration could be as follows...

 <property name="loginConfig">

The loginContextName should coincide with a given index in the loginConfig specifed. The loginConfig file used in the JUnit tests appears as the following...

 JAASTest { required;
Using the example login configuration above, the loginContextName property would be set as JAASTest...
  <property name="loginContextName"> <value>JAASTest</value> </property>

When using JAAS login modules as the authentication source, sometimes the LoginContext will require CallbackHandlers. The JaasAuthenticationProvider 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 JaasAuthenticationProvider through the callbackHandlers property.

 <property name="callbackHandlers">
     <bean class=""/>
     <bean class=""/>
     <bean class=""/>

After calling LoginContext.login(), the JaasAuthenticationProvider 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( 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">
     <bean class=""/>
A configuration note: The JaasAuthenticationProvider uses the security properites "e;login.config.url.X"e; to configure jaas. If you would like to customize the way Jaas gets configured, create a subclass of this and override the configureJaas(Resource) method.

Field Summary
protected static org.apache.commons.logging.Log log
Constructor Summary
Method Summary
 void afterPropertiesSet()
          Validates the required properties are set.
protected  void configureJaas(Resource loginConfig)
          Hook method for configuring Jaas.
protected  LoginContext createLoginContext(CallbackHandler handler)
          Creates the LoginContext to be used for authentication.
 Resource getLoginConfig()
protected  void publishFailureEvent(UsernamePasswordAuthenticationToken token, AuthenticationException ase)
          Publishes the JaasAuthenticationFailedEvent.
 void setLoginConfig(Resource loginConfig)
          Set the JAAS login configuration file.
 void setRefreshConfigurationOnStartup(boolean refresh)
          If set, a call to Configuration#refresh() will be made by #configureJaas(Resource) method.
Methods inherited from class
authenticate, getApplicationEventPublisher, handleLogout, onApplicationEvent, publishSuccessEvent, setApplicationEventPublisher, setAuthorityGranters, setCallbackHandlers, setLoginContextName, setLoginExceptionResolver, supports
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected static final org.apache.commons.logging.Log log
Constructor Detail


public JaasAuthenticationProvider()
Method Detail


public void afterPropertiesSet()
                        throws Exception
Description copied from class: AbstractJaasAuthenticationProvider
Validates the required properties are set. In addition, if AbstractJaasAuthenticationProvider.setCallbackHandlers(JaasAuthenticationCallbackHandler[]) has not been called with valid handlers, initializes to use JaasNameCallbackHandler and JaasPasswordCallbackHandler.

Specified by:
afterPropertiesSet in interface InitializingBean
afterPropertiesSet in class AbstractJaasAuthenticationProvider


protected LoginContext createLoginContext(CallbackHandler handler)
                                   throws LoginException
Description copied from class: AbstractJaasAuthenticationProvider
Creates the LoginContext to be used for authentication.

Specified by:
createLoginContext in class AbstractJaasAuthenticationProvider
handler - The CallbackHandler that should be used for the LoginContext (never null).
the LoginContext to use for authentication.


protected void configureJaas(Resource loginConfig)
                      throws IOException
Hook method for configuring Jaas.

loginConfig - URL to Jaas login configuration
IOException - if there is a problem reading the config resource.


protected void publishFailureEvent(UsernamePasswordAuthenticationToken token,
                                   AuthenticationException ase)
Publishes the JaasAuthenticationFailedEvent. Can be overridden by subclasses for different functionality

publishFailureEvent in class AbstractJaasAuthenticationProvider
token - The authentication token being processed
ase - The excetion that caused the authentication failure


public Resource getLoginConfig()


public void setLoginConfig(Resource loginConfig)
Set the JAAS login configuration file.

loginConfig -
See Also:
JAAS Reference


public void setRefreshConfigurationOnStartup(boolean refresh)
If set, a call to Configuration#refresh() will be made by #configureJaas(Resource) method. Defaults to true.

refresh - set to false to disable reloading of the configuration. May be useful in some environments.
See Also: