You need to specify your own authentication strategy in the modular RewalmAuthenticator. The ModularRealmAuthenticator uses AtLeastOneSuccessfulStrategy by default, and AtLeastOneSuccessfulStrategy ignores exceptions and continues to try to log in using all available areas.
We had a similar tynamo project scenario , and to solve this problem I implemented my own authentication strategy called FirstExceptionStrategy, which works with several areas and throws the first exception. This approach works fine as long as there is only one Realm per Token type .
The implementations are pretty simple:
public class FirstExceptionStrategy extends FirstSuccessfulStrategy { @Override public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t) throws AuthenticationException { if ((t != null) && (t instanceof AuthenticationException)) throw (AuthenticationException) t; return super.afterAttempt(realm, token, singleRealmInfo, aggregateInfo, t); } }
I repeat, this only works if ONLY ONE Realm per Token type exists.
For more information about my specific scenario, see here: http://jira.codehaus.org/browse/TYNAMO-154
source share