前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Springsecurity之CasAuthenticationProvider

Springsecurity之CasAuthenticationProvider

作者头像
克虏伯
发布2019-04-15 10:21:38
9990
发布2019-04-15 10:21:38
举报

    注:版本是Springsecurity4.3.x.RELEASE

    ProviderManager中有如下List-1的属性,AuthenticationProvider就是被ProviderManager使用到的,如下List-2所示。

List-1

代码语言:javascript
复制
private List<AuthenticationProvider> providers

List-2

代码语言:javascript
复制
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方法。

                                   图1 CasAuthenticationProvider的authenticate方法时序图

  • 步骤2中会判断是否支持。
  • 步骤4中,通过Cas20ServiceTicketValidator,将得到的ticket发送到CAS server,进行认证,之后CAS server会返还一些信息。
  • 步骤6和步骤7,用步骤4得到的数据,去调用UserDetailsService的loadUserByUsername。
  • 步骤3的最后,会创建CasAuthenticationToken,并返回。

    来一张图,描述下CasAuthenticationFilter、ProviderManager等的调用关系吧,如下图1所示,原图见我的Github

                                                                   图1 

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/11/12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档