CAS环境搭建

cas环境搭建

本文主要记录自己的搭建过程及遇到的问题。当然借鉴了其他的博客。
原址(http://blog.csdn.net/small_love/article/details/6664831

1、生成证书:

证书对于实现此单点登录非常之重要,证书是服务器端和客户端安全通信的凭证,本教程只是演示,所有用了JDK自带的证书生成工具keytool。当然在实际项目中你可以到专门的证书认证中心购买证书。
中文官方网站:http://www.verisign.com/cn/

(1)用JDK自带的keytool生成证书

keytool -genkey -alias smalllove -keyalg RSA -keystore D:/keys/smallkey.keystore

此命令是生成一个证书,其中 smalllove 是证书别名 。
执行过程不赘述, 其中名字与姓氏这一写域名,可在C:\Windows\System32\drivers\etc\hosts文件中映射一个虚拟域名,例如sso.test
(2)导出证书

C:>keytool -export -file d:/keys/small.crt -alias smalllove -keystore d:/keys/smallkey.keystore]

(3)把证书导入到客户端JDK中。

keytool -import -keystore C:\Java\jdk1.6.0_21\lib\security\cacerts -file D:/keys/small.crt -alias smalllove

keytool -import -keystore C:\Java\jdk1.6.0_21\jre\lib\security\cacerts -file D:/keys/small.crt -alias smalllove 。

未执行以上命令可能会出现以下错误

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

**以上的步骤可能出现的错误

keytool错误: java.io.IOException: Keystore was tampered with, or password was incorrect

该错误的解决方法是,把%JAVA_HOME%\lib\security下的cacerts文件删除掉,再执行。
或者使用密码为changeit。(原因未知)

2、配置服务端

(1)
下载CAS的服务端的war文件,拷贝到%TOMCAT_HOME%\webapps下,并修改文件名为:cas.war。
源码下载地址:https://github.com/Jasig/cas/releases
( 2)
修改%TOMCAT_HOME%\conf\server.xml文件
去掉此文件83到93行之间的注释,修改为:

<Connector port="8443" 
protocol="HTTP/1.1" 
SSLEnabled="true"  
maxThreads="150" 
scheme="https" 
secure="true" 
clientAuth="false"
sslProtocol="TLS"      
keystoreFile="D:/keys/smallkey"   <!--生成的证书的位置-->  
keystorePass="smalllove"/>       <!--生成证书时设置的密码-->

**由于Tomcat使用两种方式来实现SSL,如果protocol不指明的是JSSE 或者是APR话,可能报错如下:

严重: Failed to initialize end point associated with ProtocolHandler [“http-apr-8443”] java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR

即使用APR实现SSL认证,但是本机没有安装。
以下为摘自官网的解释:

Tomcat can use two different implementations of SSL:
- the JSSE implementation provided as part of the Java runtime (since
1.4)
- the APR implementation, which uses the OpenSSL engine by default.
The exact configuration details depend on which implementation is being used. If you configured Connector by specifying generic protocol=”HTTP/1.1” then the implementation used by Tomcat is chosen automatically. If the installation uses APR - i.e. you have installed the Tomcat native library - then it will use the APR SSL implementation, otherwise it will use the Java JSSE implementation.
To define a Java (JSSE) connector, regardless of whether the APR library is loaded or not, use one of the following:

<!-- Define a HTTP/1.1 Connector on port 8443, JSSE BIO implementation -->
<Connector protocol="org.apache.coyote.http11.Http11Protocol" port="8443" .../>
<!-- Define a HTTP/1.1 Connector on port 8443, JSSE NIO implementation -->
<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="8443" .../>

Alternatively, to specify an APR connector (the APR library must be available) use:

<!-- Define a HTTP/1.1 Connector on port 8443, APR implementation -->
<Connector protocol="org.apache.coyote.http11.Http11AprProtocol" port="8443" .../>

请参照tomcat6:SSL1.


(3)以上配置完成,启动tomcat.
浏览器访问http://yourhost:8443/cas出现一下页面 登录界面。
账号密码可在Tomcat目录下\webapps\cas\WEB-INF的deployerConfigContext.xml中找到

 <bean id="primaryAuthenticationHandler".../>

修改为数据库存储,可参考http://blog.csdn.net/frinder/article/details/7969925,未操作过。

配置客户端

可参照http://blog.csdn.net/small_love/article/details/6664831

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值