您的位置:首页 > 其它

CAS环境搭建

2015-10-21 10:45 260 查看

cas环境搭建

本文主要记录自己的搭建过程及遇到的问题。当然借鉴了其他的博客。

原址(/article/1971721.html

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".../>


修改为数据库存储,可参考/article/8927558.html,未操作过。

配置客户端

可参照/article/1971721.html
脚注内容.

http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: