首页 > 编程知识 正文

cas单点登录,uboot源码分析

时间:2023-05-06 01:33:26 阅读:31602 作者:1135

上述文章介绍了Springboot如何集成Cas身份验证,但在编写代码时存在疑问:

1 )我们获取认证内容的时候是securitycontextholder.get context ) ),但是这个内容是什么时候放的,放的内容是什么?

2 )我们定制的用户详细服务结果是如何使用的,与认证有什么关系?

现在让我们带着这两个问题,沿着源代码流程往下看。 源代码可能与SpringSecurity的版本有关。 我看到的版本是4.2.3

1费用评估过滤器

主要类是CasAuthenticationFilter,他的定义如下

publicclasscasauthenticationfilterextendsabstractauthenticationprocessingfilter { }首先,abstractauthenticationprocessingfilter

实际上,对于两个步骤,首先调用attemptAuthentication尝试认证,在第二步获取认证结果作为参数,然后执行认证成功后的过程,这两个步骤分别是子类casauthentic ation

2身份验证逻辑

@ overridepublicauthenticationattemptauthentication (finalhttpservletrequestrequest,finalhttpservletresponseresponse (tereresponse ) io exception {//iftherequestisaproxyrequestprocessitandreturnnulltoindicatethe//requesthasbeenprocessedif (proxyreceptoretor common utils.readandrespondtoproxyreceptorrequest (请求,响应,this.proxygrantingticketstorage ); 返回空值; } finalbooleanserviceticketrequest=serviceticketrequest (请求,响应); finalstringusername=serviceticketrequest? cas _ stateful _ identifier : cas _ stateless _ identifier; 字符串密码=obtain artifact (request ); if (密码==空) logger.debug (' failedtoobtainanartifact (cas ticket ) ); password=' '; } finalusernamepasswordauthenticationtokenauthrequest=newusernamepasswordauthenticationtoken (username,password ); auth request.set details (authentication detailssource.build details ) request ); return this.getauthenticationmanager ().authenticate ) ) authrequest; }这里没有具体的认证逻辑。 实现是最后一句

this.getAuthenticationManager ().authenticate ) (authrequest ); 具体的认证逻辑由AuthenticationManager执行。 具体实施如下:

对于为身份验证提供多个提供程序的cas,请使用CasAuthenticationProvider;

3财务提供商的主要逻辑

私有身份验证令牌密钥验证(金融身份验证) )。 throwsauthenticationexception { try } finalassertionassertion=this.ticket validator.validate (authentic ation.getcredenation ) 用户详细信息检查器. check (用户详细信息); returnnewcasauthenticationtoken (this.key,userDetails,authentication.getCredentials ), authorities mapper.mapauthher } catch (finalticketvalidationexceptione ) thrownewbadcredentialsexception (e.getmessage ) }这里拿着ticketValidator.validate检查cas的ticket。 检查成功后,此值作为CasAuthenticationToken的属性返回

CasAuthenticationToken; loadUserByAssertion还使用我们定义的用户详细信息服务获取一些用户信息,并将其用作财务工具的属性

认证到此为止。 然后查看认证成功后的过程,并返回第一个CasAuthenticationFilter逻辑

4successfulAuthentication

其实重要的逻辑在这里。 上述认证结果表明,CasAuthenticationToken位于安全上下文中; 整个逻辑到此结束

上面的两个疑问也解决了;

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。