注:版本是Springsecurity4.3.x.RELEASEjava
ProviderManager中有以下List-1的屬性,AuthenticationProvider就是被ProviderManager使用到的,以下List-2所示。git
List-1github
private List<AuthenticationProvider> providers
List-2spring
public Authentication authenticate(Authentication authentication) throws AuthenticationException { Class<? extends Authentication> toTest = authentication.getClass(); AuthenticationException lastException = null; Authentication result = null; boolean debug = logger.isDebugEnabled(); for (AuthenticationProvider provider : getProviders()) { if (!provider.supports(toTest)) { continue; } if (debug) { logger.debug("Authentication attempt using " + provider.getClass().getName()); } try { result = provider.authenticate(authentication); if (result != null) { copyDetails(authentication, result); break; } } catch (AccountStatusException e) { prepareException(e, authentication); // SEC-546: Avoid polling additional providers if auth failure is due to // invalid account status throw e; } catch (InternalAuthenticationServiceException e) { prepareException(e, authentication); throw e; } catch (AuthenticationException e) { lastException = e; } }
如List-2所示,會遍歷List-1中的AuthenticationProvider,逐個provider的authenticate方法。ide
圖1 CasAuthenticationProvider的authenticate方法時序圖debug
來一張圖,描述下CasAuthenticationFilter、ProviderManager等的調用關係吧,以下圖1所示,原圖見個人Github。3d
圖1 code