001package org.tynamo.shiro.extension.authc.pam;
002
003import org.apache.shiro.authc.AuthenticationException;
004import org.apache.shiro.authc.AuthenticationInfo;
005import org.apache.shiro.authc.AuthenticationToken;
006import org.apache.shiro.authc.pam.FirstSuccessfulStrategy;
007import org.apache.shiro.realm.Realm;
008
009/**
010 * {@link org.apache.shiro.authc.pam.AuthenticationStrategy} implementation that throws the first exception it gets
011 * and ignores all subsequent realms. If there is no exceptions it works as the {@link FirstSuccessfulStrategy}
012 *
013 * WARN: This approach works fine as long as there is ONLY ONE Realm per Token type.
014 *
015 * @see FirstSuccessfulStrategy
016 * @since 0.4.5
017 */
018public class FirstExceptionStrategy extends FirstSuccessfulStrategy {
019
020        @Override
021        public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException {
022                if ((t != null) && (t instanceof AuthenticationException)) throw (AuthenticationException) t;
023                return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t);
024        }
025
026}