org.apache.shiro.authc.pam
Class FirstSuccessfulStrategy

java.lang.Object
  extended by org.apache.shiro.authc.pam.AbstractAuthenticationStrategy
      extended by org.apache.shiro.authc.pam.FirstSuccessfulStrategy
All Implemented Interfaces:
AuthenticationStrategy

public class FirstSuccessfulStrategy
extends AbstractAuthenticationStrategy

AuthenticationStrategy implementation that only accepts the account data from the first successfully consulted Realm and ignores all subsequent realms. This is slightly different behavior than AtLeastOneSuccessfulStrategy, so please review both to see which one meets your needs better.

Since:
0.9
See Also:
AtLeastOneSuccessfulAuthenticationStrategy

Constructor Summary
FirstSuccessfulStrategy()
           
 
Method Summary
 AuthenticationInfo beforeAllAttempts(Collection<? extends Realm> realms, AuthenticationToken token)
          Returns null immediately, relying on this class's merge implementation to return only the first info object it encounters, ignoring all subsequent ones.
protected  AuthenticationInfo merge(AuthenticationInfo info, AuthenticationInfo aggregate)
          Returns the specified aggregate instance if is non null and valid (that is, has principals and they are not empty) immediately, or, if it is null or not valid, the info argument is returned instead.
 
Methods inherited from class org.apache.shiro.authc.pam.AbstractAuthenticationStrategy
afterAllAttempts, afterAttempt, beforeAttempt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FirstSuccessfulStrategy

public FirstSuccessfulStrategy()
Method Detail

beforeAllAttempts

public AuthenticationInfo beforeAllAttempts(Collection<? extends Realm> realms,
                                            AuthenticationToken token)
                                     throws AuthenticationException
Returns null immediately, relying on this class's merge implementation to return only the first info object it encounters, ignoring all subsequent ones.

Specified by:
beforeAllAttempts in interface AuthenticationStrategy
Overrides:
beforeAllAttempts in class AbstractAuthenticationStrategy
Parameters:
realms - the Realms that will be consulted during the authentication process for the specified token.
token - the Principal/Credential representation to be used during authentication for a corresponding subject.
Returns:
an empty AuthenticationInfo object that will populated with data from multiple realms.
Throws:
AuthenticationException - if the strategy implementation does not wish the Authentication attempt to execute.

merge

protected AuthenticationInfo merge(AuthenticationInfo info,
                                   AuthenticationInfo aggregate)
Returns the specified aggregate instance if is non null and valid (that is, has principals and they are not empty) immediately, or, if it is null or not valid, the info argument is returned instead.

This logic ensures that the first valid info encountered is the one retained and all subsequent ones are ignored, since this strategy mandates that only the info from the first successfully authenticated realm be used.

Overrides:
merge in class AbstractAuthenticationStrategy


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.