Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

net.sf.acegisecurity.providers.dao
Class PasswordDaoAuthenticationProvider  view PasswordDaoAuthenticationProvider download PasswordDaoAuthenticationProvider.java

java.lang.Object
  extended bynet.sf.acegisecurity.providers.dao.PasswordDaoAuthenticationProvider
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, net.sf.acegisecurity.providers.AuthenticationProvider, org.springframework.beans.factory.InitializingBean

public class PasswordDaoAuthenticationProvider
extends java.lang.Object
implements net.sf.acegisecurity.providers.AuthenticationProvider, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

An net.sf.acegisecurity.providers.AuthenticationProvider implementation that retrieves user details from a PasswordAuthenticationDao.

This AuthenticationProvider is capable of validating net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken requests containing the correct username, password and when the user is not disabled.

Unlike DaoAuthenticationProvider, the responsibility for password validation is delegated to PasswordAuthenticationDao.

Upon successful validation, a UsernamePasswordAuthenticationToken will be created and returned to the caller. The token will include as its principal either a String representation of the username, or the net.sf.acegisecurity.UserDetails that was returned from the authentication repository. Using String is appropriate if a container adapter is being used, as it expects String representations of the username. Using UserDetails is appropriate if you require access to additional properties of the authenticated user, such as email addresses, human-friendly names etc. As container adapters are not recommended to be used, and UserDetails implementations provide additional flexibility, by default a UserDetails is returned. To override this default, set the setForcePrincipalAsString(boolean) 55 to true.

Caching is handled via the UserDetails object being placed in the UserCache. This ensures that subsequent requests with the same username and password can be validated without needing to query the PasswordAuthenticationDao. It should be noted that if a user appears to present an incorrect password, the PasswordAuthenticationDao will be queried to confirm the most up-to-date password was used for comparison.

If an application context is detected (which is automatically the case when the bean is started within a Spring container), application events will be published to the context. See net.sf.acegisecurity.providers.dao.event.AuthenticationEvent for further information.


Field Summary
private  PasswordAuthenticationDao authenticationDao
           
private  org.springframework.context.ApplicationContext context
           
private  boolean forcePrincipalAsString
           
private  UserCache userCache
           
 
Constructor Summary
PasswordDaoAuthenticationProvider()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
 net.sf.acegisecurity.Authentication authenticate(net.sf.acegisecurity.Authentication authentication)
          Performs authentication with the same contract as AuthenticationManager.authenticate(Authentication)>AuthenticationManager.authenticate(Authentication) 55 .
protected  net.sf.acegisecurity.Authentication createSuccessAuthentication(java.lang.Object principal, net.sf.acegisecurity.Authentication authentication, net.sf.acegisecurity.UserDetails user)
          Creates a successful net.sf.acegisecurity.Authentication object.
 org.springframework.context.ApplicationContext getContext()
           
 PasswordAuthenticationDao getPasswordAuthenticationDao()
           
 UserCache getUserCache()
           
private  net.sf.acegisecurity.UserDetails getUserFromBackend(java.lang.String username, java.lang.String password)
           
 boolean isForcePrincipalAsString()
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          Set the ApplicationContext that this object runs in.
 void setForcePrincipalAsString(boolean forcePrincipalAsString)
           
 void setPasswordAuthenticationDao(PasswordAuthenticationDao authenticationDao)
           
 void setUserCache(UserCache userCache)
           
 boolean supports(java.lang.Class authentication)
          Returns true if this AuthenticationProvider supports the indicated Authentication object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

private org.springframework.context.ApplicationContext context

authenticationDao

private PasswordAuthenticationDao authenticationDao

userCache

private UserCache userCache

forcePrincipalAsString

private boolean forcePrincipalAsString
Constructor Detail

PasswordDaoAuthenticationProvider

public PasswordDaoAuthenticationProvider()
Method Detail

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Description copied from interface: org.springframework.context.ApplicationContextAware
Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ResourceLoaderAware's setResourceLoader.

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware

getContext

public org.springframework.context.ApplicationContext getContext()

setForcePrincipalAsString

public void setForcePrincipalAsString(boolean forcePrincipalAsString)

isForcePrincipalAsString

public boolean isForcePrincipalAsString()

setPasswordAuthenticationDao

public void setPasswordAuthenticationDao(PasswordAuthenticationDao authenticationDao)

getPasswordAuthenticationDao

public PasswordAuthenticationDao getPasswordAuthenticationDao()

setUserCache

public void setUserCache(UserCache userCache)

getUserCache

public UserCache getUserCache()

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Description copied from interface: org.springframework.beans.factory.InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

authenticate

public net.sf.acegisecurity.Authentication authenticate(net.sf.acegisecurity.Authentication authentication)
                                                 throws net.sf.acegisecurity.AuthenticationException
Description copied from interface: net.sf.acegisecurity.providers.AuthenticationProvider
Performs authentication with the same contract as AuthenticationManager.authenticate(Authentication)>AuthenticationManager.authenticate(Authentication) 55 .

Specified by:
authenticate in interface net.sf.acegisecurity.providers.AuthenticationProvider

supports

public boolean supports(java.lang.Class authentication)
Description copied from interface: net.sf.acegisecurity.providers.AuthenticationProvider
Returns true if this AuthenticationProvider supports the indicated Authentication object.

Returning true does not guarantee an AuthenticationProvider will be able to authenticate the presented instance of the Authentication class. It simply indicates it can support closer evaluation of it. An AuthenticationProvider can still return null from the AuthenticationProvider.authenticate(Authentication)>AuthenticationProvider.authenticate(Authentication) 55 method to indicate another AuthenticationProvider should be tried.

Selection of an AuthenticationProvider capable of performing authentication is conducted at runtime the ProviderManager.

Specified by:
supports in interface net.sf.acegisecurity.providers.AuthenticationProvider

createSuccessAuthentication

protected net.sf.acegisecurity.Authentication createSuccessAuthentication(java.lang.Object principal,
                                                                          net.sf.acegisecurity.Authentication authentication,
                                                                          net.sf.acegisecurity.UserDetails user)
Creates a successful net.sf.acegisecurity.Authentication object.

Protected so subclasses can override. This might be required if multiple credentials need to be placed into a custom Authentication object, such as a password as well as a ZIP code.

Subclasses will usually store the original credentials the user supplied (not salted or encoded passwords) in the returned Authentication object.


getUserFromBackend

private net.sf.acegisecurity.UserDetails getUserFromBackend(java.lang.String username,
                                                            java.lang.String password)