注:版本是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