/** * When the negotiate logic is executing, one of more round trips with the client occur. When the * {@link NegotiateAuthenticationRealm negotiate realm} determines another handshake is needed, it throws the * exception: {@link AuthenticationInProgressException}. This custom strategy detects this exception, and * immediately re-throws it so classes higher up in the call stack will allow the handshake to proceed. Without this * added logic, the handshake would be halted after the first connection by the existing error handling. * * {@inheritDoc} */ @Override public AuthenticationInfo afterAttempt(final Realm realm, final AuthenticationToken token, final AuthenticationInfo singleRealmInfo, final AuthenticationInfo aggregateInfo, final Throwable t) { if (realm instanceof NegotiateAuthenticationRealm && t instanceof AuthenticationInProgressException) { // propagate exception upward as is, to signal continue is needed throw (AuthenticationInProgressException) t; } return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t); } }
/** * When the negotiate logic is executing, one of more round trips with the client occur. When the * {@link NegotiateAuthenticationRealm negotiate realm} determines another handshake is needed, it throws the * exception: {@link AuthenticationInProgressException}. This custom strategy detects this exception, and * immediately re-throws it so classes higher up in the call stack will allow the handshake to proceed. Without this * added logic, the handshake would be halted after the first connection by the existing error handling. * * {@inheritDoc} */ @Override public AuthenticationInfo afterAttempt(final Realm realm, final AuthenticationToken token, final AuthenticationInfo singleRealmInfo, final AuthenticationInfo aggregateInfo, final Throwable t) { if (realm instanceof NegotiateAuthenticationRealm && t instanceof AuthenticationInProgressException) { // propagate exception upward as is, to signal continue is needed throw (AuthenticationInProgressException) t; } return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t); } }
@Override public AuthenticationInfo afterAttempt( Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t ) throws AuthenticationException { AuthenticationInfo info = super.afterAttempt( realm, token, singleRealmInfo, aggregateInfo, t ); if ( t != null && info instanceof ShiroAuthenticationInfo ) { // Save the throwable so we can use it for correct log messages later ((ShiroAuthenticationInfo) info).addThrowable( t ); } return info; } }
@Override public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException { if (singleRealmInfo == null) { if (t.getClass().isAssignableFrom(LockedAccountException.class)) { throw Lang.makeThrow(LockedAccountException.class, t.getMessage()); } else if (t.getClass().isAssignableFrom(UnknownAccountException.class)) { throw Lang.makeThrow(UnknownAccountException.class, t.getMessage()); } else if (t.getClass().isAssignableFrom(IncorrectCredentialsException.class)) { throw Lang.makeThrow(IncorrectCredentialsException.class, t.getMessage()); } else if (t.getClass().isAssignableFrom(ExcessiveAttemptsException.class)) { throw Lang.makeThrow(ExcessiveAttemptsException.class, t.getMessage()); } throw Lang.makeThrow(AuthenticationException.class, "未知错误"); } return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t); }