CAS官网 https://www.apereo.org/cas html
服务器端下载地址: https://www.apereo.org/cas/download java
客户端下载地址:http://downloads.jasig.org/cas-clients/ web
先说一下个人环境,Server 和Client 都是在Windows下配置的,Linux应该也差很少。 spring
服务端版本:CAS Server 4.0.0 Release 客户端版本 :cas-client-3.2.1-release.zip chrome
都是使用Tomcat配置的。 数据库
才开始的时候在按照百度搜索的 http://www.th7.cn/Program/java/201409/281561.shtml 配置的,因为网络限制访问Server端口比较少,就把https去掉了。省去了证书的部分。修改了服务器的两个文件,就能够了。 浏览器
不采用https验证,服务器端须要配置 修改第一处: cas/WEB-INF/deployerConfigContext.xml <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient"/> 增长参数p:requireSecure="false",是否须要安全验证,即HTTPS,false为不采用。修改后为: <bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient" p:requireSecure="false"/> 修改第二处: cas/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml <bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator" p:cookieSecure="true" p:cookieMaxAge="-1" p:cookieName="CASTGC" p:cookiePath="/cas" /> 参数p:cookieSecure="true",同理为HTTPS验证相关,TRUE为采用HTTPS验证,FALSE为不采用https验证。 参数p:cookieMaxAge="-1",简单说是COOKIE的最大生命周期,-1为无生命周期,即只在当前打开的IE窗口有效,IE关闭或从新打开其它窗口,仍会要求验证。能够根据须要修改成大于0的数字,好比3600等,意思是在3600秒内,打开任意IE窗口,都不须要验证。 这里把 cookieSecure修改成false就好了
感受服务器端配置没什么难度,配置一次就经过了,主要就是数据库配置的时候略显复杂了一下。 安全
并且中间换了一次Tomcat,直接拷贝webapp下的项目就能够了,迁移仍是很是方便的。 服务器
感受难点在client,网上说的配置不是很全,饶了一个弯,最后仍是在官网的文档中找到的解决方案。 cookie
org.jasig.cas.client.authentication.AuthenticationFilter配置中
必填参数
casServerLoginUrl - Defines the location of the CAS server login URL, i.e. https://localhost:8443/cas/login
service or serverName
service - the service URL to send to the CAS server,e.g. https://localhost:8443/yourwebapp/index.html
serverName - the server name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e.https://localhost:8443 (you must include the protocol, but port is optional if it's a standard port).
service和serverName两个参数二选其一,刚刚开始的时候我填写的http://localhost:8088,后来发现该页面是登陆页面,用户须要再登陆一下,而后本身编写了根据用户名登陆的页面,userLogin.jsp。
而后将serverName配置成http://localhost:8088/userLogin.jsp,可是发现登陆以后提示404,这是chrome提示的错误,而IE浏览器直接就是卡在SSO的登陆页面,坑人。。
而后仔细查看地址发现单点登陆成功以后跳转的地址为:http://localhost:8088/userLogin.jsp/,与正确的地址多了一个斜线,百度了一下,发现有一个noFilter的参数,在web.xml文件中配置该参数以后不生效,依旧不生效,没办法了,看源码,查过源码以后肯定确实没有改参数,这个应该是旧版本的问题,最后只能求助官网的文档了,发现不光能够配置serverName,还能够将serverName替换成service,按照官方的文档将serverName换成service,值仍是原来的值,一切就OK了。