单点登陆(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一。SSO的定义是在多个应用系统中,用户只须要登陆一次就能够访问全部相互信任的应用系统。java
咱们目前的系统存在诸多子系统,而这些子系统是分别部署在不一样的服务器中,那么使用传统方式的session是没法解决的,咱们须要使用相关的单点登陆技术来解决。mysql
CAS 是 Yale 大学发起的一个开源项目,旨在为 Web 应用系统提供一种可靠的单点登陆方法,CAS 在 2004 年 12 月正式成为 JA-SIG 的一个项目。CAS 具备如下特色:web
CAS下载:https://www.apereo.org/projects/casspring
【1】开源的企业级单点登陆解决方案。sql
【2】CAS Server 为须要独立部署的 Web 应用。数据库
【3】CAS Client 支持很是多的客户端(这里指单点登陆系统中的各个 Web 应用),包括 Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。express
从结构上看,CAS 包含两个部分: CAS Server 和 CAS Client。CAS Server 须要独立部署,主要负责对用户的认证工做;CAS Client 负责处理对客户端受保护资源的访问请求,须要登陆时,重定向到 CAS Server。下图是 CAS 最基本的协议过程:apache
咱们须要作的就是将该CAS的war包部署以后经过修改配置文件修改进行定制化。api
SSO单点登陆访问流程主要有如下步骤:浏览器
1. 访问服务:SSO客户端发送请求访问应用系统提供的服务资源。
2. 定向认证:SSO客户端会重定向用户请求到SSO服务器。
3. 用户认证:用户身份认证。
4. 发放票据:SSO服务器会产生一个随机的Service Ticket。
5. 验证票据:SSO服务器验证票据Service Ticket的合法性,验证经过后,容许客户端访问服务。
6. 传输用户信息:SSO服务器验证票据经过后,传输用户认证结果信息给客户端。
Cas服务端其实就是一个war包。cas-server-webapp-4.0.0.war 将其更名为cas.war放入tomcat目录下的webapps下。启动tomcat自动解压war包。浏览器输入http://localhost:8080/cas/login ,可看到登陆页面
这里有个固定的用户名和密码 casuser /Mellon
登陆成功后会跳到登陆成功的提示页面
若是咱们不但愿用8080端口访问CAS, 能够修改端口
(1)修改TOMCAT的端口
打开tomcat 目录 conf\server.xml 找到下面的配置,将端口进行自行修改
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
将端口8080,改成9100
(2)修改CAS配置文件
修改cas的WEB-INF/cas.properties
server.name=http://localhost:9100
修改或添加WEB-INF\deployerConfigContext.xml中id="primaryAuthenticationHandler"的属性,在map标签中添加entry标签能够添加新的用户名和密码
<bean id="primaryAuthenticationHandler" class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">
<property name="users"> <map> <entry key="casuser" value="Mellon"/> </map> </property> </bean>
CAS默认使用的是HTTPS协议,若是使用HTTPS协议须要SSL安全证书(需向特定的机构申请和购买) 。若是对安全要求不高或是在开发测试阶段,可以使用HTTP协议。咱们这里讲解经过修改配置,让CAS使用HTTP协议。
(1)修改cas的WEB-INF/deployerConfigContext.xml
找到下面的配置
<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient"/>
这里须要增长参数p:requireSecure="false",requireSecure属性意思为是否须要安全验证,即HTTPS,false为不采用
(2)修改cas的/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml
找到下面配置
<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator" p:cookieSecure="true" p:cookieMaxAge="-1" p:cookieName="CASTGC" p:cookiePath="/cas" />
参数p:cookieSecure="true",同理为HTTPS验证相关,TRUE为采用HTTPS验证,FALSE为不采用https验证。
参数p:cookieMaxAge="-1",是COOKIE的最大生命周期,-1为无生命周期,即只在当前打开的窗口有效,关闭或从新打开其它窗口,仍会要求验证。能够根据须要修改成大于0的数字,好比3600等,意思是在3600秒内,打开任意窗口,都不须要验证。
咱们这里将cookieSecure改成false , cookieMaxAge 改成3600
(3)修改cas的WEB-INF/spring-configuration/warnCookieGenerator.xml
找到下面配置
<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator" p:cookieSecure="true" p:cookieMaxAge="-1" p:cookieName="CASPRIVACY" p:cookiePath="/cas" />
咱们这里将cookieSecure改成false , cookieMaxAge 改成3600
总之CAS的思想就是若是你要登陆就到认证中心登陆,若是你有票据就到认证中心去验证票据。
说明:测试工程会建立两个Web工程,分别为WebCasClientA和WebCasClientB
WebCasClientA模块和WebCasClientB都须要作的操做如3.1和3.2
<!-- cas --> <dependency> <groupId>org.jasig.cas.client</groupId> <artifactId>cas-client-core</artifactId> <version>3.3.3</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency>
war工程导入tomcat插件坐标以及编译使用的jdk版本,WebCasClientA的tomcat端口是9001,WebCasClientB的tomcat插件端口为9002,自行修改
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <!-- 指定端口 --> <port>9002</port> <!-- 请求路径 --> <path>/</path> </configuration> </plugin> </plugins> </build>
该部分是核心配置,注意WebCasClientA的tomcat端口是9001,WebCasClientB的tomcat插件端口为9002,自行修改
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!-- ======================== 单点登陆开始 ======================== --> <!-- 第一部分:单点登出。用于单点退出,该过滤器用于实现单点登出功能,可选配置 --> <listener> <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class> </listener> <!-- 该过滤器用于实现单点登出功能,可选配置。 --> <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> <filter-name>CASFilter</filter-name> <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <!--这里的server是CAS认证中心服务端的IP,没有登陆的用户会被重定向到这个IP --> <param-value>http://localhost:8080/cas/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <!--当前web应用的地址,此地址为了登陆后从cas认证中心跳回时使用 --> <param-value>http://localhost:9001</param-value> </init-param> </filter> <filter-mapping> <filter-name>CASFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!--第三步分:票据验证。该过滤器负责对来自于浏览器的用户票据Ticket的校验工做,必须启用它 --> <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> <!-- 票据认证填写cas认证中心服务端url地址--> <param-value>http://localhost:8080/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <!-- 票据认证后重定向到当前web服务的url--> <param-value>http://localhost:9002</param-value> </init-param> </filter> <filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<!--下方两个部分是用来获取登录的用户名的--> <!-- 第四部分:该过滤器负责实现HttpServletRequest请求的包裹, 好比容许开发者经过HttpServletRequest的getRemoteUser()方法得到SSO登陆用户的登陆名,可选配置。 --> <filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class> org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 第五部分:该过滤器使得开发者能够经过org.jasig.cas.client.util.AssertionHolder来获取用户的登陆名。 好比AssertionHolder.getAssertion().getPrincipal().getName()。 --> <filter> <filter-name>CAS Assertion Thread Local Filter</filter-name> <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class> </filter> <filter-mapping> <filter-name>CAS Assertion Thread Local Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- ======================== 单点登陆结束,共计五个Filter过滤器 ======================== --> </web-app>
启动部署好cas的tomcat服务器。启动WebCasClientA的tomcat端口是9001,WebCasClientB的tomcat插件端口为9002的两个服务,启动后登陆界面便会跳转到认证中心。
因为登陆是在认证中心进行的,因此退出也是在认证中心进行的,退出登陆直接跳转到http://localhost:8080/cas/logout便可退出登陆,页面添加退出按钮
<a href="http://localhost:8080/cas/logout">退出登陆</a>
在3.4执行登出以后页面会停留在认证中心的登出界面,咱们能够经过如下配置达到登出以后跳转到指定界面
修改cas系统的配置文件\webapps\cas\WEB-INF\cas-servlet.xml
最后一个参数followServiceRedirects换成true
<bean id="logoutAction" class="org.jasig.cas.web.flow.LogoutAction" p:servicesManager-ref="servicesManager" p:followServiceRedirects="${cas.logout.followServiceRedirects:true}"/>
以后页面的连接跳转增长service,注意写全访问路径
<a href="http://localhost:8080/cas/logout?service=https://www.baidu.com/">退出登陆</a>
测试时注意清除浏览器缓存,改配置的时候,须要重启部署cas的tomcat服务器。
3个jar包放到cas项目的WEB-INF\lib目录下(负责访问数据库),jar包分别是
c3p0-0.9.1.2.jar
cas-server-support-jdbc-4.0.0.jar
mysql-connector-java-5.1.32.jar
下方位置贴在beans标签内部
<!--c3p0数据源的配置--> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" p:driverClass="com.mysql.jdbc.Driver" p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/huawei?characterEncoding=utf8" p:user="root" p:password="root" /> <!--密码用了md5,它默认的只有md5加密,若是不要加密能够直接把这里干掉,须要的配置对应p:passwordEncoder-ref--> <bean id="passwordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder" c:encodingAlgorithm="MD5" p:characterEncoding="UTF-8" /> <!--负责验证用户登陆,上方数据源,加密类,手写sql查询数据库获取用户--> <bean id="dbAuthHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler" p:dataSource-ref="dataSource" p:sql="select password from tb_user where username = ?" p:passwordEncoder-ref="passwordEncoder"/> <!--若是须要加密则须要注入该加密类,不然直接删除p:passwordEncoder-ref这段--> <!--因为cas默认使用primaryAuthenticationHandler进行认证,因此咱们在文档搜索primaryAuthenticationHandler,找到 <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" /> 改成此处的dbAuthHandler即 <entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver" /> -->
拓展:若是使用了MD5加密则须要在添加用户的时候就把密码加密。可使用Apache的工具类进行MD5加密
DigestUtils.md5Hex(password)
建立模块CASclientC
<properties> <spring.version>4.2.4.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-cas</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.jasig.cas.client</groupId> <artifactId>cas-client-core</artifactId> <version>3.3.3</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <!-- 指定端口 --> <port>9003</port> <!-- 请求路径 --> <path>/</path> </configuration> </plugin> </plugins> </build>
spring-security.xml配置文件以下
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans:beans xmlns="http://www.springframework.org/schema/security" 3 xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 http://www.springframework.org/schema/beans/spring-beans.xsd 6 http://www.springframework.org/schema/security 7 http://www.springframework.org/schema/security/spring-security.xsd"> 8 9 <!-- entry-point-ref 入口点引用,表示之后的登陆交给CAS处理,SpringSecurity不要再过问了 --> 10 <http use-expressions="false" entry-point-ref="casProcessingFilterEntryPoint"> 11 <intercept-url pattern="/**" access="ROLE_USER"/> 12 <csrf disabled="true"/> 13 <!-- custom-filter为过滤器, position 表示将过滤器放在指定的位置上,before表示放在指定位置以前 ,after表示放在指定的位置以后 --> 14 <custom-filter ref="casAuthenticationFilter" position="CAS_FILTER" /> 15 <custom-filter ref="requestSingleLogoutFilter" before="LOGOUT_FILTER"/> 16 <custom-filter ref="singleLogoutFilter" before="CAS_FILTER"/> 17 </http> 18 19 <!-- CAS入口点 开始 下方的配置只须要动端口号,ip 其余的配置都是固定配置--> 20 <beans:bean id="casProcessingFilterEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"> 21 <!-- cas登陆服务器登陆URL,当用户登录的时候会跳转到cas认证中心进行登陆 --> 22 <beans:property name="loginUrl" value="http://localhost:8080/cas/login"/> 23 <beans:property name="serviceProperties" ref="serviceProperties"/> 24 </beans:bean> 25 <beans:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties"> 26 <!--service 配置自身工程的根地址+/login/cas --> 27 <beans:property name="service" value="http://localhost:9003/login/cas"/> 28 </beans:bean> 29 <!-- CAS入口点 结束 --> 30 31 32 <!-- 认证过滤器 开始 --> 33 <beans:bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter"> 34 <beans:property name="authenticationManager" ref="authenticationManager"/> 35 </beans:bean> 36 <!-- 认证管理器 --> 37 <authentication-manager alias="authenticationManager"> 38 <authentication-provider ref="casAuthenticationProvider"> 39 </authentication-provider> 40 </authentication-manager> 41 <!-- 认证提供者 --> 42 <beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider"> 43 <beans:property name="authenticationUserDetailsService"> 44 <beans:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper"> 45 <beans:constructor-arg ref="userDetailsService" /> 46 </beans:bean> 47 </beans:property> 48 <beans:property name="serviceProperties" ref="serviceProperties"/> 49 <!-- ticketValidator 为票据验证器 --> 50 <beans:property name="ticketValidator"> 51 <beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator"> 52 <!-- 设置cas票据验证地址 --> 53 <beans:constructor-arg index="0" value="http://localhost:8080/cas"/> 54 </beans:bean> 55 </beans:property> 56 <beans:property name="key" value="an_id_for_this_auth_provider_only"/> 57 </beans:bean> 58 <!-- springScurity认证类 --> 59 <beans:bean id="userDetailsService" class="cn.huawei.service.UserDetailServiceImpl"/> 60 61 <!-- 认证过滤器 结束 --> 62 63 64 <!-- 单点登出 开始 --> 65 <beans:bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"/> 66 <beans:bean id="requestSingleLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"> 67 <beans:constructor-arg value="http://localhost:8080/cas/logout?service=http://www.baidu.com"/> 68 <beans:constructor-arg> 69 <beans:bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/> 70 </beans:constructor-arg> 71 <!-- 将本地/logout/cas和 64行退出后的部分进行绑定 --> 72 <beans:property name="filterProcessesUrl" value="/logout/cas"/> 73 </beans:bean> 74 <!-- 单点登出 结束 --> 75 76 </beans:beans>
SpringSecurity主要作了以下几件事
一、第10行的entry-point-ref="casProcessingFilterEntryPoint"配置将认证的任务交给了CAS进行处理,引用了第20行的bean
二、第19到29行作的就是当有验证请求时,若是没有登陆就跳转到CAS认证中心,认证以后返回到登陆以前的页面
三、在第13到16行配置了三个自定义过滤器
casAuthenticationFilter:
在36行到40行有以下配置
<!-- 认证管理器 --> <authentication-manager alias="authenticationManager"> <authentication-provider ref="casAuthenticationProvider"> </authentication-provider> </authentication-manager>
springSecurity将本身的认证管理器和认证提供者都交由CAS的casAuthenticationProvider进行操做,而在casAuthenticationProvider中的authenticationUserDetailsService又引入了SpringSecurity的UserDetailService的实现类,目的是进行角色的验证。
再接着就是票据验证的部分。
UserDetailServiceImpl的代码以下
1 import java.util.ArrayList; 2 import java.util.Collection; 3 import java.util.List; 4 5 import org.springframework.security.core.GrantedAuthority; 6 import org.springframework.security.core.authority.SimpleGrantedAuthority; 7 import org.springframework.security.core.userdetails.User; 8 import org.springframework.security.core.userdetails.UserDetails; 9 import org.springframework.security.core.userdetails.UserDetailsService; 10 import org.springframework.security.core.userdetails.UsernameNotFoundException; 11 12 //注意认证类的包名要和spring-security.xml文件中的包名一致 13 //该类能够拷贝shop-web子模块中的 14 //该类的目的已经不是为了进行用户认证,在调用该类前springSecurity已经从CAS作完认证后才调用,该类的执行只为了拿到角色"ROLE_USER"返回用户角色信息 15 public class UserDetailServiceImpl implements UserDetailsService { 16 17 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 18 System.out.println("通过认证类:"+username); 19 20 List<GrantedAuthority> authorities=new ArrayList(); 21 authorities.add(new SimpleGrantedAuthority("ROLE_USER")); 22 23 return new User(username,"",authorities); 24 } 25 }
此类不须要进行数据库校验,只须要赋予权限就行。
requestSingleLogoutFilter:用于单点退出
singleLogoutFilter:用于单点退出的配置
springmvc.xml的配置以下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="cn.huawei" /><!-- 包扫描 --> <mvc:annotation-driven /> <!-- 启动mvc注解 --> </beans>
web.xml的配置以下
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!--SpringMVC--> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 指定加载的配置文件 ,经过参数contextConfigLocation加载 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!--SpringSecurity--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-security.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
至此,SpringSecurity整合CAS完毕,之后拦截用户登录的再也不是CAS的过滤器,而是SpringSecurity进行拦截。
因此主要配置包括
一、web.xml配置SpringSecurity的过滤器
二、静态资源放行
三、SpringSecurity中的入口点配置
四、认证过滤器配置
五、单点退出配置