`
linliangyi2007
  • 浏览: 1013182 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

JA-SIG(CAS)学习笔记1

阅读更多
实验背景:
系统环境: Windows XP  |  SUN JDK1.6U4 | Tomcat6.0.14 | CAS Server 3.1.1 + CAS Client 2.1.1
主机完整名称: Linly
浏览器: FireFox V2.0.0.11

实验步骤:
STEP 1,搭建Java Web服务器环境
安装 JDK + Tomcat 6.0.14 , HTTP端口8080 , HTTPS端口8443
JAVA_HOME = D:\Java\jdk1.6.0_04
CATALINA_HOME = D:\Java\apache-tomcat-6.0.14
安装完毕,启动Tomcat ,在浏览器上 测试 http://Linly:8080/

出现上述界面,表明系统STEP1成功搭建。

STEP 2,使用Java Keytool工具为系统生成HTTPS证书,并为系统注册
(Java Keytool相关资料可参阅:Java keytool 安全证书学习笔记), 在DOS窗体运行以下指令(建议编写一个BAT批处理文件执行)

cls
rem please set the env JAVA_HOME before run this bat file
rem delete alia tomcat if it is existed
keytool -delete -alias tomcatsso -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
keytool -delete -alias tomcatsso -storepass changeit
(注释: 清除系统中可能存在的名字为tomcatsso 的同名证书)
rem list all alias in the cacerts
keytool -list -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
(注释: 列出系统证书仓库中存在证书名称列表)
rem generator a key
keytool -genkey -keyalg RSA -alias tomcatsso -dname "cn=linly" -storepass changeit
(注释:指定使用RSA算法,生成别名为tomcatsso的证书,存贮口令为changeit,证书的DN为"cn=linly" ,这个DN必须同当前主机完整名称一致哦,切记!!!)rem export the key
keytool -export -alias tomcatsso -file %java_home%/jre/lib/security/tomcatsso.crt -storepass changeit
(注释: 从keystore中导出别名为tomcatsso的证书,生成文件tomcatsso.crt)rem import into trust cacerts
keytool -import -alias tomcatsso -file %java_home%/jre/lib/security/tomcatsso.crt -keystore %java_home%/jre/lib/security/cacerts -storepass changeit
(注释:将tomcatsso.crt导入jre的可信任证书仓库。注意,安装JDK是有两个jre目录,一个在jdk底下,一个是独立的jre,这里的目录必须同Tomcat使用的jre目录一致,否则后面Tomcat的HTTPS通讯就找不到证书了)
rem list all alias in the cacerts
keytool -list -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
(注释:列出jre可信任证书仓库中证书名单,验证先前的导入是否成功,如果导入成功,应该在列表中能找到tomcatsso这个别名,如下图)[/quote]

同时,在D:\Java\jdk1.6.0_04\jre\lib\security目录下能找到“tomcatsso.crt”这个文件;在C:\Documents and Settings\Linly目录下能找到“.keystore”文件。
满足上述条件则STEP2部署完成。

STEP 3,配置Tomcat的HTTPS服务
编辑D:\Java\apache-tomcat-6.0.14\conf下的server.xml文件,在connector的配置位置添加以下的配置:
引用
<Connector protocol="org.apache.coyote.http11.Http11Protocol"
           port="8443" minSpareThreads="5" maxSpareThreads="75"
           enableLookups="true" disableUploadTimeout="true"
           acceptCount="100"  maxThreads="200"
           scheme="https" secure="true" SSLEnabled="true"
           keystoreFile="C:/Documents and Settings/new/.keystore" keystorePass="changeit"
           truststoreFile="D:/Java/jdk1.6.0_04/jre/lib/security/cacerts"
           clientAuth="false" sslProtocol="TLS"/>


启动Tomcat,访问https://linly:8443/,出现以下界面说明HTTPS配置生效:


STEP 4,为HelloWorldExample程序配置CAS过滤器
访问http://linly:8080/examples/servlets/servlet/HelloWorldExample,出现以下界面说明应用正常启动:

编辑D:\Java\apache-tomcat-6.0.14\webapps\examples\WEB-INF下的web.xml文件,添加如下信息:
引用
<filter>
<filter-name>CAS Filter</filter-name>
<filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>
<init-param>
  <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
  <param-value>https://Linly:8443/cas/login</param-value>
</init-param>
<init-param>
  <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
  <param-value>https://Linly:8443/cas/serviceValidate</param-value>
</init-param>
<init-param>
  <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
  <param-value>Linly:8080</param-value>
</init-param>
</filter>


引用

<filter-mapping>
<filter-name>CAS Filter</filter-name>
<url-pattern>/servlets/servlet/HelloWorldExample</url-pattern>
</filter-mapping>


拷贝casclient.jar文件到目录D:\Java\apache-tomcat-6.0.14\webapps\examples\WEB-INF\lib下。
由于我们使用的是Tomcat6.0.14,因此,还要拷贝commons-logging-1.0.4.jar到该目录下。

STEP 5,部署JA-SIG(CAS)服务器
拷贝cas.war到D:\Java\apache-tomcat-6.0.14\webapps目录下。启动Tomcat,访问网址http://linly:8080/cas/index.jsp,出现以下画面:

输入用户名/密码 :linly/linly(任意两个相同的字窜),点击“登录”,出现以下画面:

表示CAS服务器配置运行成功。


STEP 6,测试JA-SIG(CAS)部署结果
启动Tomcat。
测试使用浏览器登陆以下网址:http://linly:8080/examples/servlets/servlet/HelloWorldExample,页面将弹出以下认证框,点击“确定”


页面将重定向到JA-SIG的SSO登录认证页面



输入用户名=密码,如:linly/linly,则通过验证,进入应用的入口界面,如下:


细心的用户将发现,此时的URL不再是:
http://linly:8080/examples/servlets/servlet/HelloWorldExample,
URL的尾端带上了一个ticket参数:
http://linly:8080/examples/servlets/servlet/HelloWorldExample?ticket=ST-2-qTcfDrdFb0bWndWgaqZD
到此,JA-SIG(CAS)服务器的初步SSO部署宣告成功。









65
2
分享到:
评论
20 楼 xjq19861009 2008-11-06  
其他都没什么问题 就最后一步输入同样的用户名和密码 就报下面的错误 谢谢帮我看看

 javax.servlet.ServletException: Unable to validate ProxyTicketValidator [[edu.yale.its.tp.cas.client.ProxyTicketValidator proxyList=[null] [edu.yale.its.tp.cas.client.ServiceTicketValidator casValidateUrl=[https://cuytr:8443/CAS/serviceValidate] ticket=[ST-1-7YW9lw0fMbTeW0P1wHxx] service=[http%3A%2F%2Fcuytr%3A8080%2FConairOA%2F] renew=false]]]
	edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:381)


root cause 

edu.yale.its.tp.cas.client.CASAuthenticationException: Unable to validate ProxyTicketValidator [[edu.yale.its.tp.cas.client.ProxyTicketValidator proxyList=[null] [edu.yale.its.tp.cas.client.ServiceTicketValidator casValidateUrl=[https://cuytr:8443/CAS/serviceValidate] ticket=[ST-1-7YW9lw0fMbTeW0P1wHxx] service=[http%3A%2F%2Fcuytr%3A8080%2FConairOA%2F] renew=false]]]
	edu.yale.its.tp.cas.client.CASReceipt.getReceipt(CASReceipt.java:52)
	edu.yale.its.tp.cas.client.filter.CASFilter.getAuthenticatedUser(CASFilter.java:455)
	edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:378)


root cause 

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
	com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
	com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
	sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
	sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
	edu.yale.its.tp.cas.util.SecureURL.retrieve(SecureURL.java:84)
	edu.yale.its.tp.cas.client.ServiceTicketValidator.validate(ServiceTicketValidator.java:212)
	edu.yale.its.tp.cas.client.CASReceipt.getReceipt(CASReceipt.java:50)
	edu.yale.its.tp.cas.client.filter.CASFilter.getAuthenticatedUser(CASFilter.java:455)
	edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:378)


root cause 

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	sun.security.validator.PKIXValidator.doBuild(Unknown Source)
	sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
	sun.security.validator.Validator.validate(Unknown Source)
	com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
	com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(Unknown Source)
	com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
	com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
	sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
	sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
	edu.yale.its.tp.cas.util.SecureURL.retrieve(SecureURL.java:84)
	edu.yale.its.tp.cas.client.ServiceTicketValidator.validate(ServiceTicketValidator.java:212)
	edu.yale.its.tp.cas.client.CASReceipt.getReceipt(CASReceipt.java:50)
	edu.yale.its.tp.cas.client.filter.CASFilter.getAuthenticatedUser(CASFilter.java:455)
	edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:378)


root cause 

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
	java.security.cert.CertPathBuilder.build(Unknown Source)
	sun.security.validator.PKIXValidator.doBuild(Unknown Source)
	sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
	sun.security.validator.Validator.validate(Unknown Source)
	com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
	com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(Unknown Source)
	com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
	com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
	com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
	sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
	sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
	edu.yale.its.tp.cas.util.SecureURL.retrieve(SecureURL.java:84)
	edu.yale.its.tp.cas.client.ServiceTicketValidator.validate(ServiceTicketValidator.java:212)
	edu.yale.its.tp.cas.client.CASReceipt.getReceipt(CASReceipt.java:50)
	edu.yale.its.tp.cas.client.filter.CASFilter.getAuthenticatedUser(CASFilter.java:455)
	edu.yale.its.tp.cas.client.filter.CASFilter.doFilter(CASFilter.java:378)



19 楼 cunsky 2008-10-19  
linliangyi2007 写道

cas配置中必须使用完整的计算机域名,不能使用ip或localhost。

不能使用 localhost吗。我但到大多数资料都是用localhost。用计算机名的话。tomcat里面都得改那些啊
18 楼 macun 2008-09-25  
请问下关于cas的client 3.1.1 的配置,如果配置代理应该如何配置?因为项目中要用到cas。现在我们是这样配置的:
<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>
org.jasig.cas.client.session.SingleSignOutFilter
</filter-class>
</filter>
<filter>
<filter-name>CAS Authentication Filter</filter-name>
<filter-class>
org.jasig.cas.client.authentication.AuthenticationFilter
</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>http://cxn:8080/cas/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://cxn:8080</param-value>
</init-param>
</filter>
<filter>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<filter-class>
org.jasig.cas.client.util.HttpServletRequestWrapperFilter
</filter-class>
</filter>
<filter>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<filter-class>
org.jasig.cas.client.util.AssertionThreadLocalFilter
</filter-class>
</filter>
<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>http://cxn:8080/cas</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://cxn:8080</param-value>
</init-param>
<init-param>
<param-name>allowAnyProxy</param-name>
<param-value>true</param-value>
</init-param>
</filter>
但是没有配置代理,即得到pgt,应该怎么配置?
请发到我的邮箱chengxiuna@126.com
谢谢!
17 楼 redez 2008-09-23  
cas配置中为什么必须使用完整的计算机域名,而不能使用ip。是在代码里规定的吗?如果是的话是那段代码
16 楼 linliangyi2007 2008-05-28  
cas配置中必须使用完整的计算机域名,不能使用ip或localhost。
15 楼 lsqlister 2008-05-11  
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching localhost found
是什么原因啊?
14 楼 lsqlister 2008-05-11  
<filter>
<filter-name>CAS Filter</filter-name>
<filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
<param-value>https://Linly:8443/cas/login</param-value>
</init-param>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
<param-value>https://Linly:8443/cas/serviceValidate</param-value>
</init-param>
<init-param>
<param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
<param-value>Linly:8080</param-value>
</init-param>
</filter>
里面的Linly变为localhost,出现404错误。

请问:<param-value>Linly:8080</param-value> 具体什么功能啊
13 楼 liuho 2008-05-08  
我觉着在%JAVA_HOME%/中包含空格是导致执行命令是出现路径错误的原因,建议jdk装在不包含空格的路径中或者在%JAVA_HOME%/绝对路径下执行命令
12 楼 flymichael 2008-05-07  
博主,如何在自己的AuthenticationHandler里获得session,也就是说怎么得到request对象?
11 楼 flymichael 2008-04-25  
主机部署casserver,客户端部署在另一台机器上,客户端导入了服务端证书和自己的证书,都部署了SSL,访问时,casserver验证通过,但是客户端页面抛出异常
10 楼 flymichael 2008-04-25  
博主,有个异常请教

javax.net.ssl.SSLHandshakeException:java.security.cert.CertificateException: No subject alternative names present
9 楼 flymichael 2008-04-25  
说明一下,执行的时候需要把%JAVA_HOME%替换成绝对路径
8 楼 flymichael 2008-04-23  
在C:\Program Files\Java\jdk1.6.0_03\jre\lib\security目录下操作可完成
7 楼 flymichael 2008-04-23  
反复手写过,错误依旧,博主是否自己手测过???
6 楼 flymichael 2008-04-23  
我发现凡是用到%JAVA_HOME%/jre/lib/security/cacerts这句都报错,不管是哪个指令下的
错误显示如下:
keytool错误:java.lang.RuntimeException:用法错误,Files\Java\jdk1.6.0_03/jre/lib/security/cacerts 不是合法的命令
带下划线部分是%JAVA_HOME%,dos窗口显示部分应属正常,前后斜杠不一致,测试一下错误依旧,郁闷中。。。
5 楼 linliangyi2007 2008-04-21  
楼上的兄弟是不是命令行没打全,或者一半的时候被折行了。
4 楼 flymichael 2008-04-21  
keytool -delete -alias tomcatsso -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
这句话报keytool错误,java.lang.RuntimeException运行期错误,
JAVA_HOME%/jre/lib/security/cacerts 不是合法命令
3 楼 linliangyi2007 2008-03-06  
楼上的兄弟看的真细,确实楼掉了过滤器的url配置,真不好意思!
补上了,多谢多谢!
2 楼 猫尾摆摆 2008-03-06  
第四步似乎有问题,按照你的配置,是不会出现网页受保护的提示的,而且也不是通过https连接。

应该加上
<filter-mapping>
<filter-name>CAS Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
1 楼 猫尾摆摆 2008-03-06  
第四步似乎有问题,按照你的配置,是不是出现网页受保护的提示的,而且也是通过https连接。

应该加上
<filter-mapping> 
    <filter-name>CAS Filter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping>

相关推荐

    JA-SIG(CAS)学习笔记3.doc

    JA-SIG CAS是其最初的开发者,它允许用户通过一个统一的登录界面访问多个相互独立的应用系统,从而简化了用户的登录体验。 CAS Server是CAS的核心组件,它负责处理用户的认证请求。在我们讨论的环境中,CAS Server ...

    CAS 开发综合笔记

    4. **JA-SIG CAS学习笔记**: "JA-SIG(CAS)学习笔记2"和"JA-SIG(CAS)学习笔记3"涵盖了CAS的基本概念、架构和配置,以及如何与Java应用集成。JA-SIG是一个高等教育软件联盟,其文档对于理解CAS的教育背景和应用...

    cas配置详解

    在《JA-SIG(CAS)学习笔记1.doc》中,可能会涵盖CAS的基本架构和组件。CAS服务器作为中心验证服务,处理用户的登录请求,验证用户凭证,并向服务提供授权票证(Ticket Granting Ticket, TGT)。客户端应用则通过验证...

    CAS整合LDAP实现单点登录学习笔记.pdf

    具体到本次学习笔记中,可以看到提到了如何使用CAS 3.2.1的版本,并且涉及到整合JA-SIG CAS的开发。文档中提到的步骤包括用户从客户端访问服务,服务重定向到CAS服务器的登录界面,用户在CAS服务器登录后获得票据,...

    CAS整合LDAP实现单点登录学习笔记.doc

    CAS(Central Authentication Service)是基于Java的开源SSO协议实现,由JA-SIG组织开发,旨在简化Web应用的认证流程。 CAS的核心设计愿景是提供一个统一的认证入口点,使得所有应用系统可以通过这个中心服务验证...

    基于Struts的图书信息管理系统设计实现分析.doc

    【基于Struts的图书信息管理系统设计实现分析】 ...[5] JA-SIG(CAS)学习笔记[EB/OL]. .java 本系统设计充分考虑了实际操作的便捷性和系统的可扩展性,为其他类似信息管理系统的开发提供了参考。

Global site tag (gtag.js) - Google Analytics