hello,
I have a question about the default behaviour of org.springframework.security.authentication.Provid erManager.
From reading the Spring Security 3 book (see e.g. the flow diagram at page 40, introduced by "Let's get into a little more detail and look specifically at the classes involved in the processing of a web-based username and password authentication request:"), it seems to me that supposedly all the configured AuthenticationProviders are tried that support the current authentication method, and as soon as one of them does support it, it should either succesfully authenticate or fail the authentication by throwing an AuthenticationException. In either case, then the loop (of trying AuthenticationProviders) is stopped.
However when looking at the code (3.0.3 RELEASE), it does not seem to me this works like that. If I read the code correctly, in case of a succesful authentication it will indeed break out of the loop, but in case of an AuthenticationException (i.e. authentication failed), it will just happily loop on to try the next.
The relevant code is (slightly simplified)
Code:AuthenticationException lastException = null; Authentication result = null; for (AuthenticationProvider provider : getProviders()) { if (!provider.supports(toTest)) { continue; } try { result = provider.authenticate(authentication); if (result != null) { copyDetails(authentication, result); break; } } catch (AuthenticationException e) { lastException = e; } }
Could anyone please enlighten me how this works ?
Kind regards
Heikki Doeleman


Reply With Quote
