资源下载
CAS server
CAS client
一、CAS server
1. 生成证书
生成一个别名为castest的证书。
此处需要特别注意口令(后续导入导出证书、CAS服务器端均要用到此口令)和“名字与姓氏”(为CAS跳转域名,否则会报错)
1
| keytool -genkey -alias castest -keyalg RSA -keystore {certificate_path}/{certificate_name}
|
2. 导出证书
1
| keytool -export -file {certificate_path}/{certificate_name}.crt -alias castest -keystore {certificate_path}/{certificate_name}
|
3. 安装证书
将证书导入到客户端JRE中(注意、是导入JRE中),如果security中已经存在cacerts,需要先将其删除。
1
| keytool -import -keystore "{jdk_path}\jre\lib\security\cacerts" -file {certificate_path}/cas-test.crt -alias cas-test
|
4. 配置tomcat
修改%TOMCAT_HOME%/conf/server.xml文件,支持https证书访问
1 2 3
| <Connector SSLEnabled="true" clientAuth="false" keystoreFile="{certificate_path}/{certificate_name}" keystorePass="{certificate_password}" maxThreads="150" port="8443" protocol="org.apache.coyote.http11.Http11Protocol" scheme="https" secure="true" sslProtocol="TLS"/>
|
5. 测试证书
访问https://localhost:8443/,成功则说明配置证书成功
6. 部署CAS server
从http://developer.jasig.org/cas/上下载cas服务器端cas-server-4.0.0-release.zip,在modules目录下找到cas-server-webapp-4.0.0.war,将其复制到%TOMCAT_HOME%\webapps下,并将名称改为cas.war
7. 测试CAS server
输入账号和密码
登录成功则说明CAS server配置成功,可通过https://localhost:8443/logout退出登录
二、CAS client
1. 添加证书映射域名
2. 创建CAS client项目
配置web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>Archetype Created Web Application</display-name>
<listener> <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> </listener> <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>
<filter> <filter-name>CASFilter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://sso.cas.com:8443/cas-server-webapp-4.0.0/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://localhost:8081</param-value> </init-param> </filter> <filter-mapping> <filter-name>CASFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<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://sso.cas.com:8443/cas-server-webapp-4.0.0/ </param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://localhost:8081</param-value> </init-param> </filter> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class> org.jasig.cas.client.util.HttpServletRequestWrapperFilter </filter-class> </filter> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<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 Assertion Thread Local Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<session-config> <session-timeout>2</session-timeout> </session-config> </web-app>
|
2. 导入CAS client核心jar包
从http://developer.jasig.org/cas-clients/上下载cas-client-3.1.12-release.zip,在modules目录下找到cas-client-core-3.1.12.jar、commons-collections-3.2.jar、commons-logging-1.1.jar复制到项目WEB-INF/lib下
3. 测试CAS client
配置好web容器后,启动cas client,访问http://localhost:8081/index.jsp,重定向至cas server(https://sso.cas.com:8443)认证页面,输入用户名casuser及密码Mellon,认证成功后跳回访问页。同时可以在CAS server日志上看到如下的验证信息
访问https://sso.cas.com:8443/cas-server-webapp-4.0.0/logout可以退出单点登录
三、其他认证方式
以上验证的用户名和密码是配置在{CAS_server}/webapp/WEB-INF/deployerConfigContext.xml中的
实际生产中用户认证信息往往配置在数据库中,下面介绍利用数据库配置认证方式
配置数据库认证方式
FAQ
1. service是如何存储的
Configuring CAS client for java in the web.xml