Tomcat下配置与使用CAS实现单点登录

 

 

配置Tomcat使用SSL安全认证
因为 CAS使用的是https协议,所以要求Tomcat支持该协议。实现步骤如下:
第一步:进入Dos命令行窗口,并进入到<%CATALINA_HOME%>目录下
第二步:生成密匙,命令如下:
Java代码 复制代码
  1. keytool -genkey -alias 别名 -keyalg RSA -keypass changeit -storepass changeit -<SPAN class=hilite3>keystore</SPAN> <SPAN class=hilite2>server</SPAN>.<SPAN class=hilite3>keystore</SPAN>   
  2. 例:keytool -genkey -alias <SPAN class=hilite1>cas</SPAN><SPAN class=hilite2>server</SPAN> -keyalg RSA -keypass changeit -storepass changeit -<SPAN class=hilite3>keystore</SPAN> <SPAN class=hilite2>server</SPAN>.<SPAN class=hilite3>keystore</SPAN>   
  3. 如附图所示.  

姓名必须填写为服务器端主机名,如果本机则填写localhost
完成之后会在Tomcat根目录下生成一个 server. keystore的文件。
第三步:生成证书
Java代码 复制代码
  1. keytool -export -alias <SPAN class=hilite1>cas</SPAN><SPAN class=hilite2>server</SPAN> -storepass changeit -file <SPAN class=hilite2>server</SPAN>.cer -<SPAN class=hilite3>keystore</SPAN> <SPAN class=hilite2>server</SPAN>.<SPAN class=hilite3>keystore</SPAN>  

完成之后,会在Tomcat目录下生成一个名为 server.cer的证书
第四步:导入证书
Java代码 复制代码
  1. keytool -import -trustcacerts -alias <SPAN class=hilite2>server</SPAN> -file <SPAN class=hilite2>server</SPAN>.cer -<SPAN class=hilite3>keystore</SPAN> cacerts -storepass changeit  

将生成的 cascerts文件copy到<%JAVA_HOME%>/jre/lib/security目录下
第五步:配置Tomcat
打开<%CATALINA_HOME%>/config/ server.xml
找到<Connector port="8443" ... />节点。默认该节点是被注释掉的,去掉注释,并修改内容为:
Java代码 复制代码
  1. <Connector protocol="org.apache.coyote.http11.Http11Protocol"  
  2.             port="8443" maxHttpHeaderSize="8192"  
  3.             maxThreads="150" minSpareThreads="25" maxSpareThreads="75"  
  4.             enableLookups="false" disableUploadTimeout="true"  
  5.             acceptCount="100" scheme="https" secure="true"  
  6.             clientAuth="false" sslProtocol="TLS"  
  7.             <SPAN class=hilite3>keystore</SPAN>Pass="changeit" <SPAN class=hilite3>keystore</SPAN>File="/<SPAN class=hilite2>server</SPAN>.<SPAN class=hilite3>keystore</SPAN>" />  

第六步:测试
访问:Https://localhost:8443/ 如果能出现Tomcat管理首页,则证明SSL配置成功

集成 CAS
第一步:下载 CAS ServerCAS Client
http://www.ja-sig.org/downloads/ cas/ cas- server-3.1.1-release.zip
http://www.ja-sig.org/downloads/ cas-clients/ cas-client-java-2.1.1.zip
第二步:部署 CAS Server
将下载的 cas- server-3.1.1-release.zip文件解压,将/modules/ cas- server-webapp-3.1.1.war拷贝到<%CATALINA_HOME%>/webapps/目录下,并改名为 cas.war
启动Tomcat,访问https://localhost:8443/ cas/login 弹出登录页面,则证明部署成功。
第三步:集成到本系统
将下载的 cas-client-java-2.1.1.zip文件解压,将/dist/ casclient.jar文件拷贝到本系统的WEB-INF/lib目录下
修改web.xml配置,添加以下内容:
Java代码 复制代码
  1. <filter>   
  2. <filter-name><SPAN class=hilite1>CAS</SPAN>Filter</filter-name>   
  3. <filter-class>   
  4. edu.yale.its.tp.<SPAN class=hilite1>cas</SPAN>.client.filter.<SPAN class=hilite1>CAS</SPAN>Filter   
  5. </filter-class>   
  6. <init-param>   
  7. <param-name>   
  8. edu.yale.its.tp.<SPAN class=hilite1>cas</SPAN>.client.filter.loginUrl   
  9. </param-name>   
  10. <param-value>   
  11. <A href="https://localhost:8443/cas/login" target=_blank>https://localhost:8443/<SPAN class=hilite1>cas</SPAN>/login</A>   
  12. </param-value>   
  13. </init-param>   
  14. <init-param>   
  15. <param-name>   
  16. edu.yale.its.tp.<SPAN class=hilite1>cas</SPAN>.client.filter.validateUrl   
  17. </param-name>   
  18. <param-value>   
  19. <A href="https://localhost:8443/cas/proxyValidate" target=_blank>https://localhost:8443/<SPAN class=hilite1>cas</SPAN>/proxyValidate</A>   
  20. </param-value>   
  21. </init-param>   
  22. <init-param>   
  23. <param-name>   
  24. edu.yale.its.tp.<SPAN class=hilite1>cas</SPAN>.client.filter.<SPAN class=hilite2>server</SPAN>Name   
  25. </param-name>   
  26. <param-value>localhost:8080</param-value>   
  27. </init-param>   
  28. </filter>   
  29. <filter-mapping>   
  30. <filter-name><SPAN class=hilite1>CAS</SPAN>Filter</filter-name>   
  31. <url-pattern>/*</url-pattern>   
  32. </filter-mapping>  

第四步:原理描述
本系统所有请求被 CAS过滤器拦截到,过滤器会将页面重定向 CAS ServerCAS Server会判断用户是否已经登录,如果未登录,则定位到登录页面( CAS Server内的)。登录成功后,再重定向到用户先前访问的本系统页面。此时session里有一个名为的edu.yale.its.tp. cas.client.filter.user属性。它存储的就是用户的登录名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值