CAS实现SSO 学习(三)

本文详细介绍如何配置ASP.NET WebForm客户端使用CAS单点登录系统,包括下载安装.NET CAS客户端、配置示例网站及调试过程,并探讨了CAS Logout机制的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(三)实现 ASP.NET WebForm Client

1. 下载.NET CAS client。

.NET CAS Client 下载地址:https://wiki.jasig.org/display/CASC/.Net+Cas+Client

下载“dotnet-client-1.0.2-bin.zip”并解压缩。

2. 配置 CAS DotNetClient

以管理员身份启动Visual Studio(目的为了随后可以直接将网站发布到IIS),打开“DotNetCasClient.vs2010.sln”解决方案。

(1)项目“DotNetCasProxyDemoApp”暂时用不到,从解决方案中移除。

(2)将“DotNetCasClient”项目中“Properties”文件夹下的“AssemblyInfo.cs”删除,将“AssemblyInfo.cs.tmpl”重命名为“AssemblyInfo.cs”。

(3)打开将“DotNetCasClient”项目中“Properties”文件夹下的“AssemblyInfo.cs”,将所有“$WCREV$”替换成“0”(或其它表示版本的数字)。

(4)将“ExampleWebSite”项目设置为启动项。

(5)将“ExampleWebSite”项目根文件夹下的“web.config.sample”重命名为“web.config”

(6)打开“web.config”文件,找到“casClientConfig”节点,将“casServerLoginUrl”属性设置为“https://10.58.8.219:8443/cas/login”,将“casServerUrlPrefix”属性设置为“https://10.58.8.219:8443/cas/”,

将“serverName”属性设置为“http://sso.centanet.com:8102”,


说明:10.58.8.219是前面我们配置好的CAS服务器IP地址;“serverName”属性中8102为运行该项目时IISExpress自动分配的端口号,其中192.168.0.153为客户端IP地址。注意:“serverName”属性中网络地址最后不要加“/”。
(7)从“web.config”文件中找到“”节点,将“loginUrl”属性设置为“https://10.58.8.219:8443/cas/login”,将“path”属性设置为“/”。

(8)保存全部修改,重新编译解决方案。

3. 调试 CAS DotNetClient

(1)鼠标右击“DotNetCasClient”项目根目录下的“Default.aspx”,选择“在浏览器中查看...”


(2)单击“Authenticated Users Only”连接

(3)输入用户名、密码(均为“admin”,或均为“bob”),CAS自动完成登录并重定向回原有网站。

至此,基于ASP.NET WebForm的CAS客户端已经完全调试通过。

 

6. 关于DotNetClient注销问题

关于DotNet注销网上有很多介绍的材料。我这里就不再多说什么了。留下个链接供大家参考。《解释CAS Logout问题

为了便于查看,将《解释CAS Logout问题》一文的主要内容放在下面便于查阅:

CAS Logout是一个非常费解的问题,我在这里简单解释一下:

假设有webapp1, webapp2, cas server,webapp1, webapp2均受cas server保护。

 

第1种不能logout的情况:

1)登录了WebApp1,redirect到caserver,casserver认证后,再redirect到webapp1,ok!

2)http方式 lougout casserver1,即http://yale_casserver:8080/cas/lougout,显示logout成功

3)访问webapp2,还能访问!这是非常正常的一种情况,因为你不通过https来注销,casserver怎么“杀”掉它通过https发给你的TGC Cookie?

 

第2种不能logout的情况:

1)登录了WebApp1,redirect到caserver,casserver认证后,再redirect到webapp1,ok!

2)https方式 lougout casserver1,即https://yale_casserver:8443/cas/lougout,显示logout成功

3)访问webapp1,还能访问!访问webapp2,不能访问,重定向到casserver要求登录!这也是非常正常的一种情况,因为你已经能够访问,你继续可以继续访问,CASLogout不能阻止你访问webapp1,它只能阻止你访问webapp2,因为你已经被允许访问webapp1,而webapp2则还没有,如果你在(1)的时候,顺带也访问webapp2,那么你的注销将毫无作用了,CAS无法阻止你访问这两个webapp,因为你有Service Ticket。

如果你对此费解,那时因为你已为Logout就是退出系统,那我只能表示遗憾,因为CAS Logout的作用不是这样,它的作用是阻止你继续通过TGC(它简单地清楚了IE的TGC Cookie)来获取ST,阻止你获取通向其他web应用的Ticket。

所以,用完webapp1的时候,注销,然后再关闭掉IE就彻底Logout了。


参考http://www.cnblogs.com/zhenyulu/archive/2013/01/22/2870936.html

3. 调试 CAS DotNetClient

(1)鼠标右击“DotNetCasClient”项目根目录下的“Default.aspx”,选择“在浏览器中查看...”

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、付费专栏及课程。

余额充值