zoukankan      html  css  js  c++  java
  • SpringSecurity3整合CAS实现单点登录

    国内私募机构九鼎控股打造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

    大功告成~!

  • 相关阅读:
    Python 两个list合并成一个字典
    python 取列表(数组)偶数和奇数位置的值
    爬虫-Xpath语法笔记-转载
    详解Python requests 超时和重试的方法-转载
    6种负载均衡算法-转载
    python学习点滴记录-Day22
    python学习点滴记录-Day21-项目
    python学习点滴记录-Day20(分页、cookie/session、ajax)
    vimrc
    使用 find 命令实现高级排除需求
  • 原文地址:https://www.cnblogs.com/AloneSword/p/4097488.html
Copyright © 2011-2022 走看看