login-webflow是當你在瀏覽器裏面輸入https://localhost:8080/cas/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方法,並根據返回值到不同的分支
這塊要弄清楚不容易,建議多看看相關資料,
裏面倒騰還是很多的。