SpringSecurity3整合CAS实现单点登录

简介: 国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私募机构九鼎控股打造,九鼎投资是在全国股份转让系统挂牌的公众公司,股票代码为430719,为“中国PE第一股”,市值超1000亿元。

国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html
内部邀请码:C8E245J (不写邀请码,没有现金送)
国内私募机构九鼎控股打造,九鼎投资是在全国股份转让系统挂牌的公众公司,股票代码为430719,为中国PE第一股,市值超1000亿元。 

------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

SpringSecurity本身已经做好了与CAS的集成工作,只需要我们做简单配置就可以了

 

步骤1 spring-cas.xml配置文件内容如下(完整版)

 

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <beans:beans xmlns="http://www.springframework.org/schema/security" 
  3.     xmlns:context="http://www.springframework.org/schema/context" 
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
  5.     xmlns:beans="http://www.springframework.org/schema/beans" 
  6.     xsi:schemaLocation="  http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  7.            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
  8.            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"  
  9.     default-lazy-init="true"
  10.     <context:component-scan base-package="com.itec.core" /> 
  11. <!--SSO --> 
  12.     <http auto-config="false" entry-point-ref="casEntryPoint" servlet-api-provision="true">    
  13.         <intercept-url pattern="/login.do" filters="none" /> 
  14.         <intercept-url pattern="/image.do" filters="none" /> 
  15.         <intercept-url pattern="/admin/*.do*" access="ROLE_LOGIN" />   
  16.         <!-- logout-success-url="/login.html" -->    
  17. <!--        <logout logout-url="/login.do" success-handler-ref="casLogoutSuccessHandler"/>   --> 
  18.         <custom-filter ref="requestSingleLogoutFilter" before="LOGOUT_FILTER" />   
  19.         <custom-filter position="FORM_LOGIN_FILTER" ref="casFilter"/>    
  20.         <custom-filter ref="singleLogoutFilter" before="CAS_FILTER" /> 
  21.     </http>   
  22.  
  23.     <beans:bean id="casEntryPoint"  class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">    
  24.         <beans:property name="loginUrl" value="http://172.19.50.21:9083/HASLSSO/login"/>    
  25.         <beans:property name="serviceProperties" ref="serviceProperties"/>    
  26.     </beans:bean
  27.     <beans:bean id="serviceProperties"  class="org.springframework.security.cas.ServiceProperties">    
  28.         <beans:property name="service"  value="http://172.19.4.225:8080/HACMS/j_spring_cas_security_check"/>    
  29.         <beans:property name="sendRenew" value="false"/>    
  30.     </beans:bean
  31.  
  32.     <beans:bean id="casFilter"  class="org.springframework.security.cas.web.CasAuthenticationFilter">    
  33.         <beans:property name="authenticationManager" ref="authenticationManager"/>    
  34.     </beans:bean>    
  35.         
  36.     <authentication-manager alias="authenticationManager">    
  37.         <authentication-provider ref="casAuthenticationProvider"/>   
  38.     </authentication-manager>    
  39.         
  40.     <beans:bean id="casAuthenticationUserDetailsService" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">    
  41.         <beans:property name="userDetailsService" >    
  42.             <beans:ref bean="userDetailsManager" />    
  43.         </beans:property>    
  44.     </beans:bean>    
  45.        
  46.     <beans:bean id="casAuthenticationProvider"    
  47.             class="org.springframework.security.cas.authentication.CasAuthenticationProvider">    
  48.         <beans:property name="authenticationUserDetailsService" ref="casAuthenticationUserDetailsService"/>    
  49.         <beans:property name="serviceProperties" ref="serviceProperties" />    
  50.         <beans:property name="ticketValidator">    
  51.             <beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">    
  52.                 <beans:constructor-arg index="0" value="http://172.19.50.21:9083/HASLSSO" />    
  53.             </beans:bean>    
  54.         </beans:property>    
  55.         <beans:property name="key" value="an_id_for_this_auth_provider_only"/>    
  56.     </beans:bean>    
  57.  
  58.     <!-- 注销客户端 --> 
  59.     <beans:bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter" /> 
  60.  
  61.     <!-- 注销服务器端 --> 
  62.     <beans:bean id="requestSingleLogoutFilter" 
  63.     class="org.springframework.security.web.authentication.logout.LogoutFilter"
  64.     <beans:constructor-arg 
  65.     value="http://172.19.50.21:9083/HASLSSO/logout" /> 
  66.     <beans:constructor-arg
  67.     <beans:bean 
  68.     class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/> 
  69.     </beans:constructor-arg
  70.     <beans:property name="filterProcessesUrl" value="/j_spring_cas_security_logout" /> 
  71.     </beans:bean
  72.  
  73. </beans:beans>    

 

 

步骤2 之前的UserDetailsManager不需要改任何代码

 

  1. @Service 
  2. public class UserDetailsManager implements UserDetailsService { 

步骤3 web.xml需要修改一点东西,不加载Security的配置文件就行了

 

  1. <context-param
  2.         <param-name>contextConfigLocation</param-name
  3.         <!-- 使用工程本身验证 --> 
  4.         <param-value>/WEB-INF/spring-config.xml,/WEB-INF/spring-freemarker.xml,/WEB-INF/spring-jpa.xml,/WEB-INF/spring-security.xml</param-value
  5.         <!-- 使用 SSO 验证 --> 
  6. <!--        <param-value>/WEB-INF/spring-config.xml,/WEB-INF/spring-freemarker.xml,/WEB-INF/spring-jpa.xml,/WEB-INF/spring-cas.xml</param-value> --> 
  7.     </context-param

大功告成~!

目录
相关文章
|
安全 Java 应用服务中间件
基于CAS实现SSO单点登录
基于CAS实现SSO单点登录
基于CAS实现SSO单点登录
|
8月前
|
JSON 安全 算法
看完就懂-SpringSecurity+JWT 实现单点登录
单点登录(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一。SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统
253 0
|
安全 Java 应用服务中间件
基于CAS,实现SSO单点登录,很细
基于CAS,实现SSO单点登录,很细
438 0
基于CAS,实现SSO单点登录,很细
|
缓存 网络安全
JavaWeb - SSO单点登录原理之基于CAS(二)
JavaWeb - SSO单点登录原理之基于CAS(二)
211 0
JavaWeb - SSO单点登录原理之基于CAS(二)
|
存储 NoSQL 安全
JavaWeb - SSO单点登录原理之基于CAS(一)
JavaWeb - SSO单点登录原理之基于CAS(一)
215 0
|
存储 SQL 安全
CAS实现单点登录
单点登录(Single Sign On),简称为 SSO,是比较流行的企业业务整合的解决方案之一。SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统。
264 0
CAS实现单点登录
shiro、cas、pac4j 实现单点登陆(1)
shiro、cas、pac4j 实现单点登陆(1)
186 0
shiro、cas、pac4j 实现单点登陆(1)
shiro、cas、pac4j 实现单点登陆(2)
shiro、cas、pac4j 实现单点登陆(2)
121 0
shiro、cas、pac4j 实现单点登陆(2)
|
安全 算法 Java
使用CAS实现单点登录
使用CAS实现单点登录
269 0
使用CAS实现单点登录
|
JSON 安全 算法
单点登录SSO解决方案之SpringSecurity+JWT实现
通过前面几天文章我们详细的介绍了SpringSecurity的使用,本文我们来看下,结合JWT来实现单点登录操作。
单点登录SSO解决方案之SpringSecurity+JWT实现