您的位置:首页 > 编程语言 > Java开发

CAS服务器和客户端配置 证书的生成,导出,导入到jdk

2013-01-15 14:31 501 查看
生成证书:
用JDK自带的keytool生成证书
命令:

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

导出证书

命令:
keytool -export -file d:/keys/small.crt -alias smalllove -keystore d:/keys/smallkey
将证书导入jdk

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

说明证书已导入到jdk中

服务器配置:
1.下载CAS的服务端,解压,把解压后的文件中modules文件夹中的cas-server-webapp-*.war文件拷贝到tomcat的webapps下面更改名字为cas.war(可以不更改,这里只是为了方便)
2.修改修改tomcat的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"/>设置的密码

3.访问https://yourhost:8443/cas出现

登陆成功后:

服务器配置成功了嘿嘿!!
客户端配置:新建两个web工程client1 client2
配置:web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter>

<filter-name>CAS Authentication Filter</filter-name>

<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>

<init-param>

<!-- CAS服务端登录地址 -->

<param-name>casServerLoginUrl</param-name>

<param-value>https://localhost/cas/</param-value>

</init-param>

<init-param>

<!-- 当前网站域名 -->

<param-name>serverName</param-name>

<param-value>http://localhost:8080</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>CAS Authentication Filter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

导入jar包:

cas-client-core-3.1.10.jar

commons-logging-1.1.jar
http://localhost:8080/client1

进行访问 index.jsp 页面 ; 但是此时会被 web.xml 中配置的 filter 拦截:

进而跳转到 指定的 casServerLoginUrl 进行验证

然后输入 用户名,密码 如果验证成功, 将会成功跳转到 index.jsp

访问 http://localhost:8080/client2/

此时不需要 验证 直接跳转到 index.jsp 中

简单的CAS功能就这样了,我还在继续学习中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: