1、 casservlet-classorg.jasig.cas.web.init.SafeDispatcherServletinit-paramparam-namepublishContextparam-valuefalse/init-paramload-on-startup1/servletservlet-mappingurl-pattern/login/servlet-mapping.!- 其他cas servlet mapping -所有映射到cas servlet上的请求都将经过/WEB-INF/cas-servlet.xml检查确定进入哪个Action,cas-servlet.xml中
2、最重要的两个bean就是handlerMappingB和handlerMappingChandlerMappingB配置了登陆流程进入的路径映射,而handlerMappingC则配置了其他的流程的路径映射。/WEB-INF/login-webflow.xml流程配置文件即是在handlerMappingB中通过/login映射进入的。Webflow依据一个生成的flowExecutionKey来确定一个流程实例走到了哪一步,每次页面流程运转总是需要提交这个 flowExecutionKey来告诉webflow它是从流程的哪个位置出发的有了以上理论作为依据,我们在下一节就可以根据自己的需要修改
3、流程,使 之支持远程登录了服务器登陆流程修改目标修改后的登陆流程活动图如下:图中橙色为我们修改的流程节点,这里我们增加了一个开始节点remoteLogin和一个结束节点remoteCallbackView,删除了原有的loginFormView节点、 viewGenericLoginSuccess以及renew节点(renew节点由于系统无此需求而删除),然后将所有这些节点的转向全部都转向到remoteCallbackView节点,因为登陆和显示登陆成功信息都应该是客户端完成的服务器端实现目标好了,原理到这里已经啰嗦完了,下一节讲如何着手修改CAS服务器端啦。修改需要基于几个基本原则:不影响原
4、有统一登陆界面功能客户端应尽量保持简单尽量保证原有功能的完整性和安全性对于第三点,必须事先说明:将登陆页面放到客户端本身就是降低了CAS安全性,这意味着作为服务向外发布的CAS服务器中的用户密码有可能由于客户端的不安全性而导致泄露,整个CAS系统成为了一个“水桶形态”,整个CAS体系的安全性将取决于所有客户端中安全性最低的一个。这也是CAS官方一直不推荐的方式。服务器端修改接下来我们讲解服务器端修改的详细过程:首先,修改/WEB-INF/web.xml,为cas增加一个/remoteLogin的映射:/remoteLoginproperty name=mappingspropsprop key
5、=/loginloginController/remoteLoginremoteController/propertyinterceptorslistref bean=localeChangeInterceptor /list/bean然后在cas-servlet.xml文件中添加我们上面所配置的remoteController的bean:- 增加远程控制者,允许以/remote请求启动remote控制流程 -remoteLoginController class=org.springframework.webflow.executor.mvc.FlowController p:flowExe
6、cutor-ref=remoteLoginFlowExecutordefaultFlowId=remoteLogin-webflowargumentHandlerbeanorg.springframework.webflow.executor.support.RequestParameterFlowExecutorArgumentHandlerflowExecutionKeyArgumentName=ltflow:executor id= registry-ref=remoteLoginFlowRegistryexecution-attributesalwaysRedirectOnPause
7、value=false/flow:executorregistry id=location path=/WEB-INF/remoteLogin-webflow.xmlregistry可以看到上面将请求指向了webflow配置文件/WEB-INF/remoteLogin-webflow.xml文件,我们需要创建此文件并配置其成为我们所需的流程,以下是remoteLogin-webflow.xml全文:?xml version=1.0 encoding=UTF-8flow xmlns=http:/www.springframework.org/schema/webflow xmlns:xsi=/w
8、ww.w3.org/2001/XMLSchema-instance xsi:schemaLocation= http:/www.springframework.org/schema/webflow/www.springframework.org/schema/webflow/spring-webflow-1.0.xsdstart-state idref=remoteLogin- 远程登陆主要Action -action-state id=action bean=remoteLoginActiontransition on=error to=remoteCallbackViewsubmitbin
9、dAndValidatecheckTicketGrantingTicketticketGrantingTicketExistsCheck/action-state- 远程回调页面,主要以JavaScript的方式回传一些参数用 -end-state id= view=decision-state id=if test=$flowScope.ticketGrantingTicketId != null then=hasServiceCheckelse=gatewayRequestCheck/decision-state$externalContext.requestParameterMapgat
10、eway != &&externalContext.requestParameterMap= null & flowScope.service !=nullredirect else=$flowScope.service !generateServiceTicket- The warn action makes the determination of whether to redirect directly to therequested service or display the confirmation page to go back to the server. -$flow
11、Scope.warnCookieValueshowWarningViewauthenticationViaFormActionsuccess method=sendTicketGrantingTicketsendTicketGrantingTicketActionserviceCheckgenerateServiceTicketAction to =gateway end state is the end state for when the user has requestedprivacy settings (to be warned) to be turned on. It delega
12、tes to a view defines in default_views.properties that display the Please click here to goto the service. message.casLoginConfirmView end state allows CAS to properly end the workflow while stillredirecting the user back to the service required.bean:dynamicRedirectViewSelectorviewServiceErrorViewvie
13、wServiceSsoErrorViewglobal-transitionstransition to= on-exception=org.springframework.webflow.execution.repository.NoSuchFlowExecutionException /org.jasig.cas.services.UnauthorizedSsoServiceExceptionorg.jasig.cas.services.UnauthorizedServiceException/global-transitions/flow以上文件根据原login-webflow.xml文件
14、修改,黄色背景为修改部分。可以看到,我们在流程中增加了remoteLogin Action节点和remoteCallback View节点,下面我们配置remoteLogin节点:在/WEB-INF/cas-servlet.xml文件中增加remoteLoginAction配置:com.baidu.cas.web.flow.RemoteLoginActionargumentExtractors-ref=argumentExtractorswarnCookieGenerator-ref=warnCookieGeneratorticketGrantingTicketCookieGenerator-
15、ref=ticketGrantingTicketCookieGenerator同时创建com.baidu.cas.web.flow.RemoteLoginAction类:/* 远程登陆票据提供Action.* 根据InitialFlowSetupAction修改.* 由于InitialFlowSetupAction为final类,因此只能将代码复制过来再进行修改.* * author GuoLin*/public class RemoteLoginAction extends AbstractAction /* CookieGenerator for the Warnings. */ NotN
16、ull private CookieRetrievingCookieGenerator warnCookieGenerator; /* CookieGenerator for the TicketGrantingTickets. */ private CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator; /* Extractors for finding the service. */ NotEmpty private List argumentExtractors; /* Boolean to note wh
17、ether weve set the values on the generators or not. */ private boolean pathPopulated = false; protected Event doExecute(final RequestContext context) throws Exception final HttpServletRequest request = WebUtils.getHttpServletRequest(context); if (!this.pathPopulated) final String contextPath = context.getExternalContext().getContextPath(); final String cookiePath = StringUtils.hasText(contextPath) ? contextPath :/;
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2