分享

CAS学习笔记(二)

 jackeyqing 2020-05-26

一、配置文件介绍

关于spring的配置信息只需放入WEB-INF/spring-configuration目录即可,cas启动时会自动加载。这个目录下的spring配置文件几乎不需要改动。

在web.xml中配置

 

在WEB-INF/spring-configuration中

1./WEB-INF/spring-configuration/applicationContext.xml
这个配置文件是cas的核心类配置,你不需要改动。

2./WEB-INF/spring-configuration/argumentExtractorsConfiguration.xml
这个配置文件主要是cas参数的提取。比如从应用端重定向到cas 服务器的url地址中的service参数,为什么cas认识,service起什么作用,换一参数名,是否可以?就是这里配置的类来处理的。但是这个你也不需要改动,cas默认是支持cas1.0,cas2.0及saml协议的。

3./WEB-INF/spring-configuration/propertyFileConfigurer.xml
加载cas.properties文件。

4./WEB-INF/spring-configuration/securityContext.xml
关于安全上下文配置,比如登出,认证等,一般情况下不需要改动它

5./WEB-INF/spring-configuration/ticketExpirationPolicies.xml
从文件名就可以知道,它是关于ticket的过期策略配置的,包括ST,TGT.

6./WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml
关于cookie的生成

7./WEB-INF/spring-configuration/ticketRegistry.xml
ticket的存储

8./WEB-INF/spring-configuration/uniqueIdGenerators.xml
ticket Id生成器

在WEB-INF/中

1./WEB-INF/cas-servlet.xml
spring mvc的启动类配置

2./WebContent/WEB-INF/deployerConfigContext.xml
cas的认证管理器,认证管理都在这个文件里,可以说进行cas开发,你需要更改的文件中,这是第一个。

3./WEB-INF/login-webflow.xml
spring web flow的流程配置文件。读懂了这个文件就可以了解cas的登录流程。

4./WEB-INF/restlet-servlet.xml
关于cas 的restlet对外接口服务的.

二、login-webflow配置信息

1、web.xml中,login-webflow的入口,如下/login,/remoteLogin

2、cas-servlet.xml中,在flow-registry里面注册webflow

 3、cas-servlet.xml中,配置主题信息,可以定位到对应的css、js、jsp路径

 

  上图,在cas.properties中,找到cas.viewResolver.basename

  通过配置文件知道页面信息配置在default_views.properties文件中

三、web-flow.xml流程介绍

3.1基本介绍

  1、on-start(start-state)流程开始,end-state流程结束 decision-state判断,类似于if,view-state对应jsp页面 action-state对应执行程序的某段

  2、<evaluate ="initialFlowSetupAction" />这些定义在cas-servlet.xml中

  3、view-state里面的view定义在default_views.properties中

3.2实例说明

<evaluate ="initialFlowSetupAction" />

这句话的意思是执行

org.jasig.cas.web.flow.InitialFlowSetupAction中的doExecute方法

其中的变量都由spring注入了

具体看对应的配置文件

然后下一个流程是

<decision-state id="ticketGrantingTicketExistsCheck">
  <if test="flowScope.ticketGrantingTicketId neq null" then="hasServiceCheck" else="gatewayRequestCheck" />
 </decision-state>

 

进行判断

flowScope.ticketGrantingTicketId

这个在org.jasig.cas.web.flow.InitialFlowSetupAction中由

context.getFlowScope().put(
            "ticketGrantingTicketId", this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));

 

这句话放入了,然后在这儿进行检测neq null是不为null的意思

then else都很好理解

view state

 

复制代码
复制代码
<view-state id="viewLoginForm" view="casLoginView" model="credentials">
        <var name="credentials" class="org.jasig.cas.authentication.principal.UsernamePasswordCredentials" />
        <binder>
            <binding property="username" />
            <binding property="password" />
        </binder>
        <on-entry>
            <set name="viewScope.commandName" value="'credentials'" />
        </on-entry>
  <transition on="submit" bind="true" validate="true" to="realSubmit">
            <set name="flowScope.credentials" value="credentials" />
            <evaluate ="authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)" />
        </transition>
 </view-state>
复制代码
复制代码

对应的是casLoginView.jsp

在这里对一些页面变量和对应的java类进行了绑定

action state

复制代码
复制代码
<action-state id="realSubmit">
        <evaluate ="authenticationViaFormAction.submit(flowRequestContext, flowScope.credentials, messageContext)" />
  <transition on="warn" to="warn" />
  <transition on="success" to="sendTicketGrantingTicket" />
  <transition on="error" to="viewLoginForm" />
 </action-state>
复制代码
复制代码

 

执行对应的方法,这儿执行org.jasig.cas.web.flow.AuthenticationViaFormAction中的

submit方法,并根据返回值到不同的分支

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多