org.springframework.ldap.support.authentication
Class DefaultValuesAuthenticationSourceDecorator

java.lang.Object
  extended by org.springframework.ldap.support.authentication.DefaultValuesAuthenticationSourceDecorator
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, AuthenticationSource

public class DefaultValuesAuthenticationSourceDecorator
extends java.lang.Object
implements AuthenticationSource, org.springframework.beans.factory.InitializingBean

Decorator on AuthenticationSource to have default authentication information be returned should the target return empty principal and credentials. Useful in combination with AcegiAuthenticationSource if users are to be allowed to read some information even though they are not logged in.

Note: The defaultUser should be an non-privileged user. This is important as this is the one that will be used when no user is logged in (i.e. empty principal is returned from the target AuthenticationSource).

Author:
Mattias Arthursson

Constructor Summary
DefaultValuesAuthenticationSourceDecorator()
          Constructor for bean usage.
DefaultValuesAuthenticationSourceDecorator(AuthenticationSource target, java.lang.String defaultUser, java.lang.String defaultPassword)
          Constructor to setup instance directly.
 
Method Summary
 void afterPropertiesSet()
           
 java.lang.String getCredentials()
          Checks if the target's principal is not empty; if not, the credentials from the target is returned - otherwise return the defaultPassword.
 java.lang.String getPrincipal()
          Checks if the target's principal is not empty; if not, this is returned - otherwise return the defaultUser.
 void setDefaultPassword(java.lang.String defaultPassword)
          Set the password of the default user.
 void setDefaultUser(java.lang.String defaultUser)
          Set the default user DN.
 void setTarget(AuthenticationSource target)
          Set the target AuthenticationSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultValuesAuthenticationSourceDecorator

public DefaultValuesAuthenticationSourceDecorator()
Constructor for bean usage.


DefaultValuesAuthenticationSourceDecorator

public DefaultValuesAuthenticationSourceDecorator(AuthenticationSource target,
                                                  java.lang.String defaultUser,
                                                  java.lang.String defaultPassword)
Constructor to setup instance directly.

Parameters:
target - the target AuthenticationSource.
defaultUser - dn of the user to use when the target returns an empty principal.
defaultPassword - password of the user to use when the target returns an empty principal.
Method Detail

getCredentials

public java.lang.String getCredentials()
Checks if the target's principal is not empty; if not, the credentials from the target is returned - otherwise return the defaultPassword.

Specified by:
getCredentials in interface AuthenticationSource
Returns:
the target's password if the target's principal is not empty, the defaultPassword otherwise.

getPrincipal

public java.lang.String getPrincipal()
Checks if the target's principal is not empty; if not, this is returned - otherwise return the defaultUser.

Specified by:
getPrincipal in interface AuthenticationSource
Returns:
the target's principal if it is not empty, the defaultUser otherwise.

setDefaultPassword

public void setDefaultPassword(java.lang.String defaultPassword)
Set the password of the default user.

Parameters:
defaultPassword - the password of the default user.

setDefaultUser

public void setDefaultUser(java.lang.String defaultUser)
Set the default user DN. This should be a non-privileged user, since it will be used when no authentication information is returned from the target.

Parameters:
defaultUser - DN of the default user.

setTarget

public void setTarget(AuthenticationSource target)
Set the target AuthenticationSource.

Parameters:
target - the target AuthenticationSource.

afterPropertiesSet

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


Copyright 2002-2006. All Rights Reserved.