首页  :: 新随笔  :: 管理

cas server端的login-webflow详细流程

Posted on 2011-08-07 14:04  季枫  阅读(12777)  评论(0编辑  收藏  举报

login-webflow是当你在浏览器里面输入https://uia.comsys.net.cn/login?param_list

后,cas server端如何处理的.

它实际上是spring-webflow的应用

有关spring-webflow的详细介绍,

网上铺天盖地,我就不啰嗦了

cas server端的web.xml文件里面有

 

 

 <servlet>
  
<servlet-name>cas</servlet-name>
  
<servlet-class>
   org.jasig.cas.web.init.SafeDispatcherServlet
  
</servlet-class>
  
<init-param>
   
<param-name>publishContext</param-name>
   
<param-value>false</param-value>
  
</init-param>
  
<load-on-startup>1</load-on-startup>
 
</servlet>

这个是login-webflow的入口servlet,映射的url-pattern之一就是



 

<servlet-mapping>
  
<servlet-name>cas</servlet-name>
  
<url-pattern>/login</url-pattern>
 
</servlet-mapping>

即login

spring webflow必须在flow-registry里面注册,

这个是在cas-servlet.xml里面注册的

<webflow:flow-registry id="flowRegistry" flow-builder-services="builder">
        
<webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login" />
</webflow:flow-registry> 

 

这句话把login-webflow.xml进行了注册

同时呢

对应的view properties在propertyFileConfigurer.xml中指定了

 

<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
  p:location
="/WEB-INF/cas.properties" />

打开cas.properties



 

cas.themeResolver.defaultThemeName=default
cas.viewResolver.basename=default_views

 

对应了default.properties

         default_views.properties

这两个properties里面放了对应的css js 和jsp的路径,大家一定要注意。

OK,基本的配置就是这些,

下面我们重点来关注下login-webflow.xml

里面是一个具体的spring webflow流程

涉及到的结点有on-start 流程开始

end-state流程结束 decision-state判断,类似于if

view-state对应jsp页面 action-state对应执行程序的某段

里面的<evaluate expression="initialFlowSetupAction" />这些定义在cas-servlet.xml中

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

下面简单介绍下里面的语句说明

<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方法,并根据返回值到不同的分支

这块要弄清楚不容易,建议多看看相关资料,

里面倒腾还是很多的。

 

智读 | 成都会领科技有限公司官网 | 智读App下载 | 每天听本书的博客 | |