This commit is contained in:
Luke Taylor 2007-12-07 12:32:54 +00:00
parent 382dc50f3c
commit a569ff01e2
2 changed files with 40 additions and 31 deletions

View File

@ -28,10 +28,11 @@ public abstract class AbstractAuthenticationManager implements AuthenticationMan
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
/** /**
* <p>An implementation of the <code>authenticate</code> method that calls the abstract method * An implementation of the <code>authenticate</code> method that calls the abstract method
* <code>doAuthenticatation</code> to do its work.</p> * <code>doAuthenticatation</code> to do its work.
* <p>If doAuthenticate throws an <code>AuthenticationException</code> then the exception is populated * <p>
* with the failed <code>Authentication</code> object that failed.</p> * If doAuthenticate throws an <code>AuthenticationException</code> then the exception is populated
* with the failed <code>Authentication</code> object that failed.
* *
* @param authRequest the authentication request object * @param authRequest the authentication request object
* *

View File

@ -82,18 +82,23 @@ import java.util.Properties;
* provides a non-null response, or a new <code>AuthenticationException</code>, the last * provides a non-null response, or a new <code>AuthenticationException</code>, the last
* <code>AuthenticationException</code> received will be used. If no provider returns a non-null response, or indicates * <code>AuthenticationException</code> received will be used. If no provider returns a non-null response, or indicates
* it can even process an <code>Authentication</code>, the <code>ProviderManager</code> will throw a * it can even process an <code>Authentication</code>, the <code>ProviderManager</code> will throw a
* <code>ProviderNotFoundException</code>.</p> * <code>ProviderNotFoundException</code>.
* *
* <p>If a valid <code>Authentication</code> is returned by an <code>AuthenticationProvider</code>, the * <p>
* <code>ProviderManager</code> will publish an {@link * If a valid <code>Authentication</code> is returned by an <code>AuthenticationProvider</code>, the
* org.springframework.security.event.authentication.AuthenticationSuccessEvent}. If an <code>AuthenticationException</code> is * <code>ProviderManager</code> will publish an
* detected, the final <code>AuthenticationException</code> thrown will be used to publish an appropriate failure * {@link org.springframework.security.event.authentication.AuthenticationSuccessEvent}. If an
* event. By default <code>ProviderManager</code> maps common exceptions to events, but this can be fine-tuned by * <code>AuthenticationException</code> is detected, the final <code>AuthenticationException</code> thrown will be
* providing a new <code>exceptionMappings</code><code>java.util.Properties</code> object. In the properties object, * used to publish an appropriate failure event. By default <code>ProviderManager</code> maps common exceptions to
* each of the keys represent the fully qualified classname of the exception, and each of the values represent the * events, but this can be fine-tuned by providing a new <code>exceptionMappings</code><code>java.util.Properties</code>
* name of an event class which subclasses {@link * object. In the properties object, each of the keys represent the fully qualified classname of the exception, and
* org.springframework.security.event.authentication.AbstractAuthenticationFailureEvent} and provides its constructor.</p> * each of the values represent the name of an event class which subclasses
* {@link org.springframework.security.event.authentication.AbstractAuthenticationFailureEvent}
* and provides its constructor.
* *
*
* @author Ben Alex
* @version $Id$
* @see ConcurrentSessionController * @see ConcurrentSessionController
*/ */
public class ProviderManager extends AbstractAuthenticationManager implements InitializingBean, public class ProviderManager extends AbstractAuthenticationManager implements InitializingBean,
@ -161,13 +166,16 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
protected void doAddExtraDefaultExceptionMappings(Properties exceptionMappings) {} protected void doAddExtraDefaultExceptionMappings(Properties exceptionMappings) {}
/** /**
* Attempts to authenticate the passed {@link Authentication} object.<p>The list of {@link * Attempts to authenticate the passed {@link Authentication} object.
* AuthenticationProvider}s will be successively tried until an <code>AuthenticationProvider</code> indicates it * <p>
* is capable of authenticating the type of <code>Authentication</code> object passed. Authentication will then * The list of {@link AuthenticationProvider}s will be successively tried until an
* be attempted with that <code>AuthenticationProvider</code>.</p> * <code>AuthenticationProvider</code> indicates it is capable of authenticating the type of
* <p>If more than one <code>AuthenticationProvider</code> supports the passed <code>Authentication</code> * <code>Authentication</code> object passed. Authentication will then be attempted with that
* <code>AuthenticationProvider</code>.
* <p>
* If more than one <code>AuthenticationProvider</code> supports the passed <code>Authentication</code>
* object, only the first <code>AuthenticationProvider</code> tried will determine the result. No subsequent * object, only the first <code>AuthenticationProvider</code> tried will determine the result. No subsequent
* <code>AuthenticationProvider</code>s will be tried.</p> * <code>AuthenticationProvider</code>s will be tried.
* *
* @param authentication the authentication request object. * @param authentication the authentication request object.
* *
@ -175,8 +183,7 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
* *
* @throws AuthenticationException if authentication fails. * @throws AuthenticationException if authentication fails.
*/ */
public Authentication doAuthentication(Authentication authentication) public Authentication doAuthentication(Authentication authentication) throws AuthenticationException {
throws AuthenticationException {
Iterator iter = providers.iterator(); Iterator iter = providers.iterator();
Class toTest = authentication.getClass(); Class toTest = authentication.getClass();
@ -189,7 +196,7 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
if (provider.supports(toTest)) { if (provider.supports(toTest)) {
logger.debug("Authentication attempt using " + provider.getClass().getName()); logger.debug("Authentication attempt using " + provider.getClass().getName());
Authentication result = null; Authentication result;
try { try {
result = provider.authenticate(authentication); result = provider.authenticate(authentication);
@ -270,14 +277,15 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
/** /**
* Sets the {@link AuthenticationProvider} objects to be used for authentication. * Sets the {@link AuthenticationProvider} objects to be used for authentication.
* *
* @param newList * @param providers the list of authentication providers which will be used to process authentication requests.
* *
* @throws IllegalArgumentException DOCUMENT ME! * @throws IllegalArgumentException if the list is empty or null, or any of the elements in the list is not an
* AuthenticationProvider instance.
*/ */
public void setProviders(List newList) { public void setProviders(List providers) {
checkIfValidList(newList); checkIfValidList(providers);
Iterator iter = newList.iterator(); Iterator iter = providers.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Object currentObject = iter.next(); Object currentObject = iter.next();
@ -285,12 +293,12 @@ public class ProviderManager extends AbstractAuthenticationManager implements In
"Can only provide AuthenticationProvider instances"); "Can only provide AuthenticationProvider instances");
} }
this.providers = newList; this.providers = providers;
} }
/** /**
* Set the {@link ConcurrentSessionController} to be used for limiting user's sessions. The {@link * Set the {@link ConcurrentSessionController} to be used for limiting users' sessions. The {@link
* NullConcurrentSessionController} is used by default * NullConcurrentSessionController} is used by default.
* *
* @param sessionController {@link ConcurrentSessionController} * @param sessionController {@link ConcurrentSessionController}
*/ */