资源预览内容
第1页 / 共22页
第2页 / 共22页
第3页 / 共22页
第4页 / 共22页
第5页 / 共22页
第6页 / 共22页
第7页 / 共22页
第8页 / 共22页
第9页 / 共22页
第10页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
CAS 单点登陆配置手册1、 Yale CAS 简介CAS 是 Yale (耶鲁)大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登录方法,CAS 在 2004 年 12 月正式成为 JA-SIG 的一个项目。CAS 具有以下特点:开源的企业级单点登录解决方案。 CAS Server 为需要独立部署的 Web 应用。 CAS Client 支持非常多的客户端( 这里指单点登录系统中的各个 Web 应用) ,包括 Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。2、CAS 原理和协议从结构上看,CAS 包含两个部分: CAS Server 和 CAS Client。CAS Server 需要独立部署,主要负责对用户的认证工作;CAS Client 负责处理对客户端受保护资源的访问请求,需要登录时,重定向到 CAS Server。图 1 是 CAS 最基本的协议过程:图 1. CAS 基础协议CAS Client 与受保护的客户端应用部署在一起,以 Filter 方式保护受保护的资源。对于访问受保护资源的每个 Web 请求,CAS Client 会分析该请求的 Http 请求中是否包含 Service Ticket,如果没有,则说明当前用户尚未登录,于是将请求重定向到指定好的 CAS Server 登录地址,并传递 Service (也就是要访问的目的资源地址) ,以便登录成功过后转回该地址。用户在第 3 步中输入认证信息,如果登录成功, CAS Server 随机产生一个相当长度、唯一、不可伪造的 Service Ticket,并缓存以待将来验证,之后系统自动重定向到 Service 所在地址,并为客户端浏览器设置一个 Ticket Granted Cookie(TGC) ,CAS Client 在拿到 Service 和新产生的 Ticket 过后,在第 5,6 步中与 CAS Server 进行身份合适,以确保 Service Ticket 的合法性。在该协议中,所有与 CAS 的交互均采用 SSL 协议,确保, ST 和 TGC 的安全性。协议工作过程中会有 2 次重定向的过程,但是 CAS Client 与 CAS Server 之间进行 Ticket 验证的过程对于用户是透明的。3、CAS 服务端配置1准备环境JDK1.6apache-tomcat-6.0.14cas-server-3.4.22配置 server将 cas-server war 文件复制到 webapps 下,启动 tomcat,以相同用户名或密登录成功。3配置数据库访问方式复制 modules 下面所有 jar 文件到 cas-server 的 Web-inf/lib 下,并复制class12.jar(oracle 数据库驱动 )。修改配置数据源,在 deployerConfigContext.xml 中添加数据源。oracle.jdbc.driver.OracleDriverjdbc:oracle:thin:localhost:1521:orclaipaip修改登录验证方法,在 deployerConfigContext.xml 中注释原验证方式,改为数据库验证。重新启动,通过数据库验证用户成功.三种验证方法:相同用户名或密码用 select 语句验证指定表或字段MD5 加密配置,在 deployerConfigContext.xml 中添加加密算法在用户验证中加入4设置 cas 登录成功进入页面修改webappscasWEB-INFviewjspdefaultuicasGenericSuccess.jsp 页面,重定向到Aip 系统 protal 页面.5 CAS 服务端超时配置修改 cas server 下WEB-INFsping-configurationapplicationContext.xml,6 CAS 取消 HTTPS 验证配置6.1 修改 cas server 下WEB-INFdeployerConfigContext.xml 文件增加参数 p:requireSecure=false,是否需要安全验证,即 HTTPS,false 为不采用。6.2 修改 cas server 下WEB-INFspring-configurationticketGrantingTicketCookieGenerator.xml 文件Defines the cookie that stores the TicketGrantingTicket. You most likely should never modify these (especially the secure property).You can change the name if you want to make it harder for people to guess.参数 p:cookieSecure=true,TRUE 为采用 HTTPS 验证,与 deployerConfigContext.xml 的参数保持一致。参数 p:cookieMaxAge=-1,简单说是 COOKIE 的最大生命周期, -1 为无生命周期,即只在当前打开的 IE 窗口有效,IE 关闭或重新打开其它窗口,仍会要求验证。可以根据需要修改为大于 0 的数字,比如 3600 等,意思是在 3600 秒内,打开任意 IE 窗口,都不需要验证。6.3 修改 cas server 下WEB-INFspring-configurationwarnCookieGenerator.xml 文件两个参数与上面同理。7 CAS 安全性设置TGC 存活周期设置修改WEB-INFspring-configurationticketExpirationPolicies.xml 文件,通过TimeoutExpirationPolicy 来设置 CAS TGC 存活周期参数,参数默认是 120 分钟,在合适的范围内设置最小值,太短,会影响 SSO 体验,太长,会增加安全性风险。Service Ticket 有效设置通过在 web.xml 中设置下面的参数,能让 Service Ticket 在多少秒内失效。edu.yale.its.tp.cas.serviceTimeout 300 该参数在业务应用的条件范围内,越小越安全。 4、CAS 服务端扩展1扩展认证接口CAS Server 负责完成对用户的认证工作,它会处理登录时的用户凭证 (Credentials) 信息,用户名/密码对是最常见的凭证信息。CAS Server 可能需要到数据库检索一条用户帐号信息,也可能在 XML 文件中检索用户名 /密码,还可能通过 LDAP Server 获取等,在这种情况下,CAS 提供了一种灵活但统一的接口和实现分离的方式,实际使用中 CAS 采用哪种方式认证是与 CAS 的基本协议分离开的,用户可以根据认证的接口去定制和扩展。扩展 AuthenticationHandler CAS 提供扩展认证的核心是 AuthenticationHandler 接口,该接口定义如清单 1 下:清单 1. AuthenticationHandler 定义public interface AuthenticationHandler /* * Method to determine if the credentials supplied are valid. * param credentials The credentials to validate. * return true if valid, return false otherwise. * throws AuthenticationException An AuthenticationException can contain * details about why a particular authentication request failed. */ boolean authenticate(Credentials credentials) throws AuthenticationException; /* * Method to check if the handler knows how to handle the credentials * provided. It may be a simple check of the Credentials class or something * more complicated such as scanning the information contained in the * Credentials object. * param credentials The credentials to check. * return true if the handler supports the Credentials, false othewrise. */ boolean supports(Credentials credentials); 该接口定义了 2 个需要实现的方法, supports ()方法用于检查所给的包含认证信息的Credentials 是否受当前 AuthenticationHandler 支持;而 authenticate() 方法则担当验证认证信息的任务,这也是需要扩展的主要方法,根据情况与存储合法认证信息的介质进行交互,返回 boolean 类型的值,true 表示验证通过,false 表示验证失败。CAS3 中还提供了对 AuthenticationHandler 接口的一些抽象实现,比如,可能需要在执行authenticate() 方法前后执行某些其他操作,那么可以让自己的认证类扩展自清单 2 中的抽象类:清单 2. AbstractPreAndPostProcessingAuthenticationHandler 定义public abstract class AbstractPreAndPostProcessingAuthenticationHandler implements AuthenticateHandler protected Log log = LogFactory.getLog(this.getClass(); protected boolean preAuthenticate(final Credentials credentials) return true; protected boolean postAuthenticate(final Credentials credentials, final boolean authenticated) return authenticated; public final boolean authenticate(final Credentials credentials) throws AuthenticationException if (!preAuthenticate(credentials) return false; final boolean authenticated = doAuthentication(credentials); return postAuthenticate(credentials, authenticated); protected abstract boolean doAuthenticatio
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号