CAS单点登录示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CAS单点登录示例相关的知识,希望对你有一定的参考价值。

web.xml加入以下代码

技术分享
 1     <!-- ======================== 单点登录开始 ======================== -->
 2     <!-- 用于单点退出,该过滤器用于实现单点登出功能,可选配置-->
 3     <listener>
 4         <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
 5     </listener>
 6  
 7     <!-- 该过滤器用于实现单点登出功能,可选配置。 -->
 8     <filter>
 9         <filter-name>CAS Single Sign Out Filter</filter-name>
10         <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
11     </filter>
12     <filter-mapping>
13         <filter-name>CAS Single Sign Out Filter</filter-name>
14         <url-pattern>/*</url-pattern>
15     </filter-mapping>
16  
17     <!-- 该过滤器负责用户的认证工作,必须启用它 -->
18     <filter>
19         <filter-name>CASFilter</filter-name>
20         <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>                                    
21         <init-param>
22             <param-name>casServerLoginUrl</param-name>
23 <!-- //单点登陆服务器访问地址 -->
24             <param-value>http://192.168.1.116:8888/cas/login</param-value>
25         </init-param>         
26         <init-param>
27             <param-name>service</param-name>         
28 <!-- //接入系统的访问地址 -->
29       <param-value>http://localhost:8083/zjhrssmis</param-value>
30         </init-param>
31     </filter>
32     <filter-mapping>
33         <filter-name>CASFilter</filter-name>
34         <url-pattern>/*</url-pattern>
35     </filter-mapping>
36  
37     <!-- 该过滤器负责对Ticket的校验工作,必须启用它 -->
38     <filter>
39         <filter-name>CAS Validation Filter</filter-name>
40         <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
41         <init-param>
42             <param-name>casServerUrlPrefix</param-name>
43 <!-- //单点登陆服务器访问地址 -->
44             <param-value>http://192.168.1.116:8888/cas</param-value>
45         </init-param>
46         <init-param>
47             <param-name>service</param-name>
48 <!-- //接入系统的访问地址 -->
49             <param-value>http://localhost:8083/zjhrssmis</param-value>
50         </init-param>
51     </filter>
52     <filter-mapping>
53         <filter-name>CAS Validation Filter</filter-name>
54         <url-pattern>/*</url-pattern>
55     </filter-mapping>
56  
57     <!-- 该过滤器负责实现HttpServletRequest请求的包裹,
58              比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名,可选配置。 -->
59     <filter>
60         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
61         <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
62     </filter>
63     <filter-mapping>
64         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
65         <url-pattern>/*</url-pattern>
66     </filter-mapping>
67  
68     <!-- 该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。
69             比如AssertionHolder.getAssertion().getPrincipal().getName()。 -->
70     <filter>
71         <filter-name>CAS Assertion Thread Local Filter</filter-name>
72         <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
73     </filter>
74     <filter-mapping>
75         <filter-name>CAS Assertion Thread Local Filter</filter-name>
76         <url-pattern>/*</url-pattern>
77     </filter-mapping>
78  
79     <!-- 根据单点登录的结果设置本系统的用户信息 ,过滤器的位置随意建,名称随意定,与下述类名一致即可 -->
80     <filter>
81         <filter-name>userAdapterFilter</filter-name>
82         <filter-class>com.cas.UserAdapterFilter</filter-class>
83     </filter>
84     <filter-mapping>
85         <filter-name>userAdapterFilter</filter-name>
86         <url-pattern>/*</url-pattern>
87     </filter-mapping>
88 <!-- ======================== 单点登录结束 ======================== -->
web.xml

 

以上是关于CAS单点登录示例的主要内容,如果未能解决你的问题,请参考以下文章

cas客户端流程详解(源码解析)--单点登录

jfinal集成cas单点认证实践

单点登录3 手撕代码模拟CAS实现单点登录

discuz x2怎么实现cas单点登录?

cas有些请求路径不需要单点登录过滤器拦截

nginx cas单点登录受影响吗