资源预览内容
第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
亲,该文档总共7页全部预览完了,如果喜欢就下载吧!
资源描述
CAS 支持客户端自定义登陆页面支持客户端自定义登陆页面(服务器篇)(服务器篇)修改需要基于几个基本原则:1、不影响原有统一登陆界面功能。2、客户端应尽量保持简单。3、尽量保证原有功能的完整性和安全性?对于第三点,必须事先说明:将登陆页面放到客户端本身就是降低了 CAS安全性,这意味着作为服务向外发布的 CAS 服务器中的用户密码有可能由于客户端的不安全性而导致泄露,整个 CAS 系统成为了一个“水桶形态”,整个CAS 体系的安全性将取决于所有客户端中安全性最低的一个。这也是 CAS 官方一直不推荐的方式。接下来我们讲解服务器端修改的详细过程:首先,修改/WEB-INF/web.xml,为 cas 增加一个/remoteLogin 的映射:cas/remoteLogin然后修改 cas-servlet.xml 文件,增加我们对/remoteLogin 映射的处理,需要增加一个新流程:loginControllerremoteLoginController然后在 cas-servlet.xml 文件中添加我们上面所配置的 remoteController 的bean:可以看到上面将请求指向了 webflow 配置文件/WEB-INF/remoteLogin-webflow.xml 文件,我们需要创建此文件并配置其成为我们所需的流程,以下是 remoteLogin-webflow.xml 全文:以上文件根据原 login-webflow.xml 文件修改,粗体为修改部分。可以看到,我们在流程中增加了 remoteLogin Action 节点和 remoteCallback View 节点,下面我们配置 remoteLogin 节点:在/WEB-INF/cas-servlet.xml 文件中增加 remoteLoginAction 配置:同时创建 com.baidu.cas.web.flow.RemoteLoginAction 类:/* 远程登陆票据提供 Action.* 根据 InitialFlowSetupAction 修改.* 由于 InitialFlowSetupAction 为 final 类,因此只能将代码复制过来再进行修改.* * author GuoLin*/public class RemoteLoginAction extends AbstractAction /* CookieGenerator for the Warnings. */NotNullprivate CookieRetrievingCookieGenerator warnCookieGenerator;/* CookieGenerator for the TicketGrantingTickets. */NotNullprivate CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator;/* Extractors for finding the service. */NotEmptyprivate List argumentExtractors;/* Boolean to note whether 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 : “/“;logger.info(“Setting path for cookies to: “ + cookiePath);this.warnCookieGenerator.setCookiePath(cookiePath);this.ticketGrantingTicketCookieGenerator.setCookiePath(cookiePath);this.pathPopulated = true;context.getFlowScope().put(“ticketGrantingTicketId“, this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request);context.getFlowScope().put(“warnCookieValue“,Boolean.valueOf(this.warnCookieGenerator.retrieveCookieValue(request);final Service service = WebUtils.getService(this.argumentExtractors, context);if (service != null context.getFlowScope().put(“service“, service);/ 客户端必须传递 loginUrl 参数过来,否则无法确定登陆目标页面if (StringUtils.hasText(request.getParameter(“loginUrl“) context.getFlowScope().put(“remoteLoginUrl“, request.getParameter(“loginUrl“); else request.setAttribute(“remoteLoginMessage“, “loginUrl parameter must be supported.“);return error();/ 若参数包含 submit 则进行提交,否则进行验证if (StringUtils.hasText(request.getParameter(“submit“) return result(“submit“); else return result(“checkTicketGrantingTicket“);public void setTicketGrantingTicketCookieGenerator(final CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator) this.ticketGrantingTicketCookieGenerator = ticketGrantingTicketCookieGenerator;public void setWarnCookieGenerator(final CookieRetrievingCookieGenerator warnCookieGenerator) this.warnCookieGenerator = warnCookieGenerator;public void setArgumentExtractors(final List argumentExtractors) this.argumentExtractors = argumentExtractors;以上粗体为修改部分,要求客户端必须传入 loginUrl 参数,且当客户端传入 submit 参数时,直接为其提交用户名密码;然后再配置remoteCallbackView 显示节点,修改 src/default_views.properties 文件,增加 remoteCallbackView 配置:# 配置远程回调页面remoteCallbackView.(class)=org.springframework.web.servlet.view.JstlViewremoteCallbackView.url=/WEB-INF/view/jsp/default/ui/remoteCallbackView.jsp创建/WEB-INF/view/jsp/default/ui/remoteCallbackView.jsp 文件:var remoteUrl = “$remoteLoginUrl?validated=true“;/ 构造错误消息var errorMessage = “;errorMessage = “/ 构造 servicevar service = “;service = “/ 跳转回去window.location.href = remoteUrl + errorMessage + service;$remoteLoginMessage以上文件注意粗体部分 validated=true,这里我们与客户端约定,当客户端登陆页面后带有参数 validated=true 时,不进行票据认证请求。这是因为,客户端登陆页面为 http:/clienthost/login.jsp,那么当用户访问URL http:/clienthost/login.jsp 时,客户端会重定向到 CAS 中央服务器请求 TGT 认证,但认证失败后 CAS 中央认证服务器会重定向到客户端登陆页面并显示登陆框,此时客户端必须以某种规则避免重新请求中央认证服务器认证, 在这里我们与客户端约定,当回发的请求为登陆页面且带有参数在这里我们与客户端约定,当回发的请求为登陆页面且带有参数validated=truevalidated=true 时即不转发时即不转发 TGTTGT 认证请求,即认证请求,即 http:/clienthost/login.jsp?validated=truehttp:/clienthost/login.jsp?validated=true 请求客户端不会重新发送请求客户端不会重新发送 TGTTGT认证请求给中央认证服务器认证请求给中央认证服务器。到此,服务器端修改完成,下一篇介绍客户端如何构建。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号