org.springframework.security.authentication.dao
Class ReflectionSaltSource

java.lang.Object
  extended by org.springframework.security.authentication.dao.ReflectionSaltSource
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, SaltSource

public class ReflectionSaltSource
extends java.lang.Object
implements SaltSource, org.springframework.beans.factory.InitializingBean

Obtains a salt from a specified property of the User object.

This allows you to subclass User and provide an additional bean getter for a salt. You should use a synthetic value that does not change, such as a database primary key. Do not use username if it is likely to change.


Constructor Summary
ReflectionSaltSource()
           
 
Method Summary
 void afterPropertiesSet()
           
 java.lang.Object getSalt(UserDetails user)
          Performs reflection on the passed User to obtain the salt.
protected  java.lang.String getUserPropertyToUse()
           
 void setUserPropertyToUse(java.lang.String userPropertyToUse)
          The method name to call to obtain the salt.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReflectionSaltSource

public ReflectionSaltSource()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

getSalt

public java.lang.Object getSalt(UserDetails user)
Performs reflection on the passed User to obtain the salt.

The property identified by userPropertyToUse must be available from the passed User object. If it is not available, an AuthenticationServiceException will be thrown.

Specified by:
getSalt in interface SaltSource
Parameters:
user - which contains the method identified by userPropertyToUse
Returns:
the result of invoking user.userPropertyToUse(), or if the method doesn't exist, user.getUserPropertyToUse().
Throws:
AuthenticationServiceException - if reflection fails

getUserPropertyToUse

protected java.lang.String getUserPropertyToUse()

setUserPropertyToUse

public void setUserPropertyToUse(java.lang.String userPropertyToUse)
The method name to call to obtain the salt. Can be either a method name or a bean property name. If your UserDetails contains a UserDetails.getSalt() method, you should set this property to "getSalt" or "salt".

Parameters:
userPropertyToUse - the name of the getter to call to obtain the salt from the UserDetails

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object