Yale cas安装

看了网上很多CAS安装的步骤,结合自己的经验总结如下:

一、配置Tomcat,启用SSL协议。

1.在CAS要安装的机器上(也就是服务端)为Tomcat生成用于SSL通讯的密钥:keytool -genkey -alias tomcat -keyalg RSA,输入密钥密码和相应参数,(注意:第一个参数CN一定要输入CAS安装机器名,其他参数就随便了),结果是在用户目录中创建了名为.keystore的密钥文件。

2.从服务端导出密钥文件:keytool -export -file server.crt -alias tomcat,输入上一步中的密码,结果在当前目录生成server.crt密钥文件。(注意:这个文件是要导入客户端的JVM上的)

3.为客户端的JVM导入密钥:keytool -import -keystore $JAVA_HOME/jre/lib/security/cacerts -file server.crt -alias tomcat,输入密码(注意:这里的密码不是上面设定的密码,而是changeit),将创建cacerts文件。

4.修改服务端的Tomcat配置文件server.xml,去掉对于SSL的注释,即开放8443端口,注意这里需要在connector字段中加入keystorePass="password"参数,password即为上面几步中涉及到的密码,keystoreFile=".keystorePath",.keystorePath即为在第一步中生成的文件.keystore的全路径,如/usr/java/bin/.keystore。

5.启动Tomcat,测试https://server:8443/是否是需经过验证方可访问(注意:server为服务端的IP地址或机器名)

二、部署CAS Server 2.0.12到Tomcat

1.一种简单的方法是将下载包中的cas.war文件直接复制到Tomcat的webapps目录下。

2.另外一种方法,从sourceforge上找到ESUP-Portail CAS Generic Handler项目,利用esup-cas-quick-start生成一个最简的TOMCAT,详见我的下一篇文章。

3.启动Tomcat,测试https://server:8443/cas,是否可访问CAS主页面(注意:server为服务端的IP地址或机器名)

三、部署CAS Client 2.0.11到Servlet-Examples

1.利用Servlet-Examples实例进行测试,将下载包中的casclient.jar文件复制到Servlet-Examples中WEB-INF目录的lib下,这里需要手工建立lib目录。

2.修改Servlet-Examples的配置文件web.xml,加入以下的过滤器:

<!-- CAS Filters -->
    <filter>
        <filter-name>CASFilter</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://server:8443/cas/login</param-value>
        </init-param><!--这里的server是服务端的IP-->
        <init-param>
            <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
            <param-value>https://serName:8443/cas/proxyValidate</param-value>
        </init-param><!--这里的serName是服务端的主机名,而且必须是-->
        <init-param>
          <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
          <param-value>client:port</param-value><!--client:port就是需要CAS需要拦截的地址和端口,一般就是这个TOMCAT所启动的IP和port-->
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>CASFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

四、测试

1.启动Tomcat,定位到Servlet-Examples应用,点击Execute;

2.浏览器跳转至CAS登录首页,注意在URL中已经附上了Servlet-Examples的Service名

3.输入用户名和密码,这里没有对其验证条件做修改,因此只要用户名和密码相同即可通过验证。

4.验证通过后浏览器又重新定位至Servlet-Examples并显示该Servlet的内容。

5.点击Http Header的Servlet应用,可以看到里面对当前用户的用户名信息做了记录。

6.以后访问Servlet-Examples应用都无需再次输入用户名和密码了。

至此,CAS Server和Client已经在Tomcat上成功部署与配置,并达到了预期的SSO效果。 

cas 配置client 1.0 &2.0 及proxy DEMO 说明 1 cas server 搭建 1.1 资源准备 cas server 下载 http://www.ja-sig.org/downloads/cas/cas-server-3.3.1-release.zip 1.2 解压后打开cas-server-3.3.1-release\cas-server-3.3.1\modules ,将cas-server-webapp-3.3.1.war 重命名为cas.war,并将war包拷贝到tomcat5.5以上版本的webapps目录下(在此对server jdbc支持不做详细解读,测试使用CAS simaple提供的默认用户名 密码 cas/cas) 2 证书生成及导入 2.1 Server端证书配置 2.2 2.2.1 证书生成导入 2.2.1.1 keytool -delete -alias tomcatsso -keystore cacerts -storepass changeit 2.2.1.2 keytool -list -keystore cacerts -storepass changeit 2.2.1.3 keytool -genkey -keyalg RSA -alias tomcatsso -dname "cn=www.test.com" -keystore cacerts -storepass changeit 2.2.1.4 keytool -export -alias tomcatsso -file tomcatsso.crt -keystore cacerts -storepass changeit 2.2.1.5 keytool -import -alias tomcatsso -file tomcatsso.crt -keystore cacerts -storepass changeit 2.2.1.6 keytool -list -keystore cacerts -storepass changeit 说明:在生成key的过程,"cn=www.test.com" 中的www.test.com为Server端的域名(必填)。 2.2.2 TOMCAT 配置SSL支持 2.2.2.1 将cacerts文件复制到TOMCAT的conf目录下修改server.xml <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" /> <Connector port="443" minSpareThreads="5" maxSpareThreads="75" enableLookups="true" disableUploadTimeout="true" acceptCount="100" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" clientAuth="false" sslProtocol="TLS" keystoreFile="conf/cacerts" keystorePass="changeit" truststoreFile="conf/cacerts"/> 启动Tomcat测试https://www.test.com:443 2.2.3 客户端证书导入 2.2.3.1 .\jre\lib\security>keytool -import -alias tomcatsso -file tomcatsso.crt -keystore cacerts -storepass changeit 3 cas client 1.0配置说明 <?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"> <description>cas1 demo</description> <!-- cas filter --> <filter> <filter-name>CAS Filter</filter-name> <filter-class> edu.yale.its.tp.cas.client.filter.CASFilter </filter-class> <!-- server login url --> <init-param> <param-name> edu.yale.its.tp.cas.client.filter.loginUrl </param-name> <param-value> https://www.test.com:8443/cas/login </param-value> </init-param> <!-- server validate url --> <init-param> <param-name> edu.yale.its.tp.cas.client.filter.validateUrl </param-name> <param-value> https://www.test.com:8443/cas/proxyValidate </param-value> </init-param> <!-- local web url --> <init-param> <param-name> edu.yale.its.tp.cas.client.filter.serverName </param-name> <param-value>www.teste.com:8080</param-value> </init-param> </filter> <!-- CAS Filter mapping --> <filter-mapping> <filter-name>CAS Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 4 cas client 2.0配置说明 <?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"> <description>cas client test</description> <!--CAS Authentication FILTER --> <filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class> org.jasig.cas.client.authentication.AuthenticationFilter </filter-class> <!-- cas server LOGIN URL --> <!-- https://www.test.com:8443/cas/login--> <init-param> <param-name>casServerLoginUrl</param-name> <param-value> https://www.test.com:8443/cas/login </param-value> </init-param> <!-- local web URL --> <init-param> <param-name>serverName</param-name> <param-value>http://www.testd.com:8080</param-value> </init-param> </filter> <!-- CAS Validation FILTER --> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class> org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter </filter-class> <!-- CAS SERVER URL --> <!-- https://www.test.com:8443/cas --> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://www.test.com:8443/cas</param-value> </init-param> <!-- LOCAL web URL --> <init-param> <param-name>serverName</param-name> <param-value>http://www.testd.com:8080</param-value> </init-param> <!-- if validation false throw exception ; default true--> <init-param> <param-name>exceptionOnValidationFailure</param-name> <param-value>false</param-value> </init-param> </filter> <!-- cas security username on request.getRemoteUser() --> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class> org.jasig.cas.client.util.HttpServletRequestWrapperFilter </filter-class> </filter> <!-- CAS SINGLE SIGN OUT FILTER --> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class> org.jasig.cas.client.session.SingleSignOutFilter </filter-class> </filter> <filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/index.jsp</url-pattern> </filter-mapping> <!-- SingleSignOutHttpSessionListener LISTENER --> <listener> <listener-class> org.jasig.cas.client.session.SingleSignOutHttpSessionListener </listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 5 cas client 2.0 proxy 配置说明 proxy 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"> <description>cas client test</description> <!--CAS Authentication FILTER --> <filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class> org.jasig.cas.client.authentication.AuthenticationFilter </filter-class> <!-- cas server LOGIN URL --> <!-- http://www.test.com:8880 --> <init-param> <param-name>casServerLoginUrl</param-name> <param-value> https://www.test.com:8443/cas/login </param-value> </init-param> <!-- local web URL --> <init-param> <param-name>serverName</param-name> <param-value>http://www.teste.com:8080</param-value> </init-param> </filter> <!-- CAS Validation FILTER --> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class> org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter </filter-class> <!-- CAS SERVER URL --> <!-- http://www.test.com:8880 --> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://www.test.com:8443/cas</param-value> </init-param> <!-- LOCAL web URL --> <init-param> <param-name>serverName</param-name> <param-value>http://www.teste.com:8080</param-value> </init-param> <!-- if validation false throw exception ; default true--> <init-param> <param-name>exceptionOnValidationFailure</param-name> <param-value>false</param-value> </init-param> <!-- the URL to watch for PGTIOU/PGT responses from the CAS server --> <init-param> <param-name>allowedProxyChains</param-name> <param-value>http://www.testd.com:8080/testd</param-value> </init-param> </filter> <!-- cas security username on request.getRemoteUser() --> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class> org.jasig.cas.client.util.HttpServletRequestWrapperFilter </filter-class> </filter> <!-- CAS SINGLE SIGN OUT FILTER --> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class> org.jasig.cas.client.session.SingleSignOutFilter </filter-class> </filter> <filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/index.jsp</url-pattern> </filter-mapping> <!-- SingleSignOutHttpSessionListener LISTENER --> <listener> <listener-class> org.jasig.cas.client.session.SingleSignOutHttpSessionListener </listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> non proxy 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"> <description>cas client test</description> <!--CAS Authentication FILTER --> <filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class> org.jasig.cas.client.authentication.AuthenticationFilter </filter-class> <!-- cas server LOGIN URL --> <!-- https://www.test.com:8443/cas/login--> <init-param> <param-name>casServerLoginUrl</param-name> <param-value> https://www.test.com:8443/cas/login </param-value> </init-param> <!-- local web URL --> <init-param> <param-name>serverName</param-name> <param-value>http://www.testd.com:8080</param-value> </init-param> </filter> <!-- CAS Validation FILTER --> <filter> <filter-name>CAS Validation Filter</filter-name> <filter-class> org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter </filter-class> <!-- CAS SERVER URL --> <!-- https://www.test.com:8443/cas --> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://www.test.com:8443/cas</param-value> </init-param> <!-- LOCAL web URL --> <init-param> <param-name>serverName</param-name> <param-value>http://www.testd.com:8080</param-value> </init-param> <!-- if validation false throw exception ; default true--> <init-param> <param-name>exceptionOnValidationFailure</param-name> <param-value>false</param-value> </init-param> <!-- validation callback validate url --> <init-param> <param-name>proxyCallbackUrl</param-name> <param-value>http://www.teste.com:8080/teste</param-value> </init-param> <!-- proxyreceptor url --> <init-param> <param-name>proxyReceptorUrl</param-name> <param-value>/proxy/test.jsp</param-value> </init-param> </filter> <!-- cas security username on request.getRemoteUser() --> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class> org.jasig.cas.client.util.HttpServletRequestWrapperFilter </filter-class> </filter> <!-- CAS SINGLE SIGN OUT FILTER --> <filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class> org.jasig.cas.client.session.SingleSignOutFilter </filter-class> </filter> <filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/index.jsp</url-pattern> </filter-mapping> <!-- SingleSignOutHttpSessionListener LISTENER --> <listener> <listener-class> org.jasig.cas.client.session.SingleSignOutHttpSessionListener </listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 6 demo 部署及说明 拷贝demo目录下的文件到 相应的发布目录(tomcat/webapps)下,使用解压工具解压,打开对应demo的web.xml,将www.test.com 及 www.testd.com 、www.teste.com 修改为相应的路径 启动TOMCAT ,祝贺你CAS 部署成功了! 7 Cas 非HTTPS支持(不赞成使用) cas client 部分修改 打开edu.yale.its.tp.cas.client.filter类,注释此 if (!pv.isAuthenticationSuccesful()) // throw new ServletException( // "CAS authentication error: " + pv.getErrorCode() + ": " + pv.getErrorMessage()); Cas server 部分修改 打开 cas-server-webapp-3.3.1\WebRoot\WEB-INF\spring-configuration\ticketGrantingTicketCookieGenerator.xml 文件 将 p:cookieSecure="true" 值改为 p:cookieSecure="false" 备注:此文仅供参考,作者仅希望通过此文引导新手,相互交流,若有疑问或意见请与作者联系! 利剑 2008-12-16 QQ:349566018 E-mail:mygw@163.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值