1. generate keystore
command : keytool -genkey -alias testtomcat -keyalg RSA -keystore "C:\Users\rocky\testsso\testtomcat.keystore"
password : 123456
2. setting the tomcat server.xml
3. download and extract cas-server-4.0.0-release.zip
~you can find cas-server-webapp-4.0.0.war in the modules package.
~copy it to tomcat webapps package and rename to cas.war.
~execute the startup.bat command as the administrator user.
~https://localhost:8443/cas
~login with user( username : casuser; password : Mellon)
-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
update 2016-04-06
1. java jdk不支持以ip建立证书,所以需要虚拟一个域名,如cas.server.com
2. 生成证书
keytool -genkeypair -keyalg RSA -keysize 2048 -sigalg SHA1withRSA -validity 36500 -alias cas.server.com -keystore C:/Users/rocky/testsso/tomcat.keystore -dname "CN=cas.server.com,OU=cdv,O=cdv,L=bj,ST=bj,C=CN"
3. 导出证书
keytool -exportcert -alias cas.server.com -keystore C:/Users/rocky/testsso/tomcat.keystore -file C:/Users/rocky/testsso/tomcat.cer -rfc
4. tomcat 配置 cas, 浏览器添加证书
(区别于上面绝对路径方式引用, 现采用相对路径方式)将生成的tomcat.keystore 拷贝到tomcat目录下。
将第三步导出的tomcat.crt 导入到浏览器
5. 将tomcat.crt拷贝到cas client所在的机器, 并导入到jdk中(C:\Program Files\Java\jdk1.7.0_15\jre\lib\security\cacerts可以删除,这时导入的文件会重新生成该文件, C:\Program Files\Java\jre7\lib\security该路径下也有cacerts文件,可一并覆盖)
keytool -import -alias cacerts -keystore cacerts -file C:/Users/rocky/testsso/tomcat.cer -trustcacerts
6.创建cas client工程(web工程)casclient,配置xml文件,并导入相关jar包
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>ssoclient</display-name> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> </listener> <filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://cas.server.com:8443/cas/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>cas.server.com:8081</param-value> </init-param> </filter> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://cas.server.com:8443/cas/</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>cas.server.com:8081</param-value> </init-param> <init-param> <param-name>redirectAfterValidation</param-name> <param-value>false</param-value> </init-param> </filter> <filter> <filter-name>CAS HttpServletRequest WrapperFilter</filter-name> <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class> </filter> <filter> <filter-name>CAS Assertion Thread Local Filter</filter-name> <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS HttpServletRequest WrapperFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Assertion Thread Local Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
记得,在tomcat的server.xml中要修改相关port,如果在同一台机器上实验,开多个tomcat,也应修改相关port,防止port冲突。
7. 浏览器输入http://cas.server.com:8081/ssoclient/index.jsp, 可以看到地址栏变了,进入cas server的login页面,输出对的username 和 password, 会跳回到client的index.jsp页面。
http://cas.server.com:8082/ssoclient2/index.jsp ,不在需要cas server登录, 直接看到index.jsp页面