security 集成cas

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

http://www.cnblogs.com/victorma/p/springcas.html

http://www.cnblogs.com/question-sky/p/7068511.html

http://blog.csdn.net/cl_andywin/article/details/53998986

http://www.cnblogs.com/scau-chm/p/6836748.html?utm_source=tuicool&utm_medium=referral

 http://blog.csdn.net/hejingyuan6/article/details/45111703

http://blog.csdn.net/qq_33264648/article/details/68493262

自定义cas返回

http://blog.csdn.net/jadyer/article/details/46970747

 

http://zhenkm0507.iteye.com/blog/546785

http://blog.csdn.net/ahpo/article/details/46412859

http://blog.csdn.net/w410589502/article/details/51508336

http://www.jb51.net/article/114678.htm

http://liulijun-cn-2011.iteye.com/blog/2247166

注:至于获取ServletContext对象,可以从request,session中获取,他们都有getServletContext()方法

ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc)

ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)

UserLogService service = ApplicationContext.getBean(UserLogService.class);

posted @ 2017-09-27 23:27  采姑娘的蘑菇  阅读(254)  评论(0编辑  收藏  举报