CAS學習筆記(二)—— cas server端的login-webflow詳細流程


一、配置文件介紹

關於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 expression="initialFlowSetupAction" />這些定義在cas-servlet.xml中

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

3.2實例說明

<evaluate expression="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 expression="authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)" />
        </transition>
 </view-state>
復制代碼

對應的是casLoginView.jsp

在這里對一些頁面變量和對應的java類進行了綁定

action state

復制代碼
<action-state id="realSubmit">
        <evaluate expression="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方法,並根據返回值到不同的分支

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM