security 權限管理

Java代碼 複製代碼
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.        xmlns:p="http://www.springframework.org/schema/p"  
  4.        xmlns:security="http://www.springframework.org/schema/security"  
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd   
  6.         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">   
  7.   
  8.     <!--   
  9.             FilterChainProxy會按順序來調用這些filter,使這些filter能享用Spring Ioc的功能,   
  10.             CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON 定義url比較前先轉爲小寫   
  11.             PATTERN_TYPE_APACHE_ANT 定義使用Apache ant的匹配模式   
  12.          -->   
  13.     <bean id="springSecurityFilterChain"  
  14.           class="org.springframework.security.util.FilterChainProxy">   
  15.         <property name="filterInvocationDefinitionSource">   
  16.             <value><![CDATA[   
  17.                     CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON   
  18.                     PATTERN_TYPE_APACHE_ANT   
  19.                     /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor   
  20.                 ]]></value>   
  21.         </property>   
  22.     </bean>   
  23.     <!--   
  24.         集成過濾器(HttpSessionContextIntegrationFilter是集成過濾器的一個實現)   
  25.            每次request前HttpSessionContextIntegrationFilter從Session中獲取Authentication對象,在request完後   
  26.            又把Authentication對象保存到Session中供下次request使用,此filter必須在其他Acegi filter前使用   
  27.     -->   
  28.     <bean id="httpSessionContextIntegrationFilter"  
  29.           class="org.springframework.security.context.HttpSessionContextIntegrationFilter"/>   
  30.     <!--   
  31.         退出(Logout)過濾器 退出登錄操作   
  32.     -->   
  33.     <bean id="logoutFilter"  
  34.           class="org.springframework.security.ui.logout.LogoutFilter">   
  35.         <!-- 退出系統後系統跳轉到此URL -->   
  36.         <constructor-arg value="/login.action"/>   
  37.         <!-- 退出系統後的操作(調用logout方法) -->   
  38.         <constructor-arg>   
  39.             <list>   
  40.                 <!-- 實現了LogoutHandler接口(logout方法) -->   
  41.                 <ref bean="rememberMeServices"/>   
  42.                 <bean class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"/>   
  43.             </list>   
  44.         </constructor-arg>   
  45.     </bean>   
  46.     <!--   
  47.         處理表單認證filter:   
  48.         1.authenticationManager     認證管理器   
  49.         2.authenticationFailureUrl  定義登錄失敗時轉向的頁面   
  50.         3.defaultTargetUrl        定義登錄成功時轉向的頁面   
  51.         4.filterProcessesUrl        定義登錄請求的地址   
  52.         5.rememberMeServices        在驗證成功後添加cookie信息   
  53.     -->   
  54.     <bean id="authenticationProcessingFilter"  
  55.           class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter"  
  56.           p:authenticationManager-ref="authenticationManager"  
  57.           p:authenticationFailureUrl="/login.action?login_error=1"  
  58.           p:defaultTargetUrl="/user.action"  
  59.           p:filterProcessesUrl="/j_spring_security_check"  
  60.           p:rememberMeServices-ref="rememberMeServices"/>   
  61.     <!--   
  62.         認證管理器(org.springframework.security.AuthenticationManager接口)   
  63.          org.springframework.security.providers.ProviderManager是認證管理器的一個實現,   
  64.          ProviderManager通過遍歷一個提供者的集合來實現身份驗證,   
  65.          直到某一個認證提供者能夠成功地驗證該用戶的身份   
  66.     -->   
  67.     <!--   
  68.         通過Providers提供認證者列表,如果一個認證提供者失敗可以嘗試另外一個認證提供者,以保證獲取不同來源的身份認證,如   
  69.         DaoAuthenticationProvider        從數據庫中讀取用戶信息驗證身份   
  70.         AnonymousAuthenticationProvider  匿名用戶身份認證   
  71.         RememberMeAuthenticationProvider 已存cookie中的用戶信息身份認證   
  72.   
  73.         其它的還有   
  74.         AuthByAdapterProvider           使用容器的適配器驗證身份   
  75.         CasAuthenticationProvider       根據Yale中心認證服務驗證身份, 用於實現單點登陸   
  76.         JaasAuthenticationProvider      從JASS登陸配置中獲取用戶信息驗證身份   
  77.         RemoteAuthenticationProvider    根據遠程服務驗證用戶身份   
  78.         RunAsImplAuthenticationProvider 對身份已被管理器替換的用戶進行驗證   
  79.         X509AuthenticationProvider      從X509認證中獲取用戶信息驗證身份   
  80.         TestingAuthenticationProvider   單元測試時使用   
  81.   
  82.         每個認證者會對自己指定的證明信息進行認證,如DaoAuthenticationProvider僅對UsernamePasswordAuthenticationToken這個證明信息進行認證。   
  83.     -->   
  84.     <bean id="authenticationManager"  
  85.           class="org.springframework.security.providers.ProviderManager"  
  86.           p:sessionController-ref="concurrentSessionController">   
  87.         <property name="providers">   
  88.             <list>   
  89.                 <ref bean="daoAuthenticationProvider"/>   
  90.                 <bean                        class="org.springframework.security.providers.anonymous.AnonymousAuthenticationProvider"  
  91.                         p:key="springsecurity"/>   
  92.                 <bean                       class="org.springframework.security.providers.rememberme.RememberMeAuthenticationProvider"  
  93.                         p:key="springsecurity"/>   
  94.             </list>   
  95.         </property>   
  96.     </bean>   
  97.     <!-- 阻止用戶在成功登錄之後再進行一次成功登錄 -->   
  98.     <bean id="concurrentSessionController"  
  99.           class="org.springframework.security.concurrent.ConcurrentSessionControllerImpl"  
  100.           p:maximumSessions="1"  
  101.           p:exceptionIfMaximumExceeded="true"  
  102.           p:sessionRegistry-ref="sessionRegistry"  
  103.           p:messageSource-ref="messageSource"/>   
  104.     <bean id="sessionRegistry"  
  105.           class="org.springframework.security.concurrent.SessionRegistryImpl"/>   
  106.     <bean id="messageSource"  
  107.           class="org.springframework.context.support.ReloadableResourceBundleMessageSource"  
  108.           p:basename="/WEB-INF/classes/messages_zh_CN"/>   
  109.     <bean id="securityContextHolderAwareRequestFilter"  
  110.           class="org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter"/>   
  111.     <!--   
  112.        利用cookie自動登陸filter   
  113.         當SecurityContextHolder中不存在Authentication.用戶授權信息,   
  114.         rememberMeProcessingFilter就會調用autoLogin()方法從cookie中獲取用戶信息,在驗證filter之前使用   
  115.     -->   
  116.     <bean id="rememberMeProcessingFilter"  
  117.           class="org.springframework.security.ui.rememberme.RememberMeProcessingFilter"  
  118.           p:authenticationManager-ref="authenticationManager"  
  119.           p:rememberMeServices-ref="rememberMeServices"/>   
  120.     <!--   
  121.         如果不存在任何授權信息時,自動添加匿名用戶身份至SecurityContextHolder中   
  122.     -->   
  123.     <bean id="anonymousProcessingFilter"  
  124.           class="org.springframework.security.providers.anonymous.AnonymousProcessingFilter"  
  125.           p:key="springsecurity"  
  126.           p:userAttribute="anonymousUser,ROLE_ANONYMOUS"/>   
  127.     <!--   
  128.        異常處理filter(異常轉換過濾器),主要是處理AccessDeniedException和AuthenticationException,   
  129.         將給每個異常找到合適的"去向"  
  130.     -->   
  131.     <bean id="exceptionTranslationFilter"  
  132.           class="org.springframework.security.ui.ExceptionTranslationFilter"  
  133.           p:accessDeniedHandler-ref="accessDeniedHandler"  
  134.           p:authenticationEntryPoint-ref="authenticationEntryPoint"/>   
  135.     <!-- 處理AccessDeniedException -->   
  136.     <bean id="accessDeniedHandler"  
  137.           class="org.springframework.security.ui.AccessDeniedHandlerImpl"  
  138.           p:errorPage="/accessDenied.jsp"/>   
  139.     <!--  -->   
  140.     <bean id="authenticationEntryPoint"  
  141.           class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint"  
  142.           p:loginFormUrl="/login.action"  
  143.           p:forceHttps="false"/>   
  144.     <!--   
  145.          使用過濾器安全攔截器保護資源   
  146.          filterSecurityInterceptor在執行轉向目標url前檢查objectDefinitionSource中設定的用戶權限信息,   
  147.           安全強制過濾器負責攔截請求,判斷請求是否安全,並且給予認證和訪問決策管理器一個機會來驗證用戶的身份和權限   
  148.           過程:   
  149.              首先,過濾器安全攔截器使用authenticationManager調用自己的provider來對用戶的認證信息進行驗證並獲取用戶已有的權限。   
  150.              然後,使用訪問決策管理器來判斷用戶是否擁用合適的授權來訪問受保護的資源。   
  151.               (objectDefinitionSource屬性定義了訪問URL需要的權限信息)   
  152.              最後,有投票者根據用戶持有認證和訪問url需要的屬性,調用自己的voter來投票,決定是否允許訪問。   
  153.     -->   
  154.     <bean id="filterSecurityInterceptor"  
  155.           class="org.springframework.security.intercept.web.FilterSecurityInterceptor"  
  156.           p:authenticationManager-ref="authenticationManager"  
  157.           p:accessDecisionManager-ref="accessDecisionManager"  
  158.           p:objectDefinitionSource-ref="objectDefinitionSource">   
  159.     </bean>   
  160.     <bean id="objectDefinitionSource"  
  161.           class="com.shopin.modules.security.intercept.web.DataBaseFilterInvocationDefinitionSource"  
  162.           p:convertUrlToLowercaseBeforeComprison="true"  
  163.           p:useAntPath="true"  
  164.           p:cacheManager-ref="securityCacheManager"/>   
  165.     <!--   
  166.          訪問決策管理器   
  167.            驗證用戶是否有權限訪問相應的資源(filterSecurityInterceptor中objectDefinitionSource屬性定義的訪問URL需要的屬性信息)   
  168.     -->   
  169.     <bean id="accessDecisionManager"  
  170.           class="org.springframework.security.vote.AffirmativeBased"  
  171.           p:allowIfAllAbstainDecisions="false">   
  172.         <property name="decisionVoters">   
  173.             <list>   
  174.                 <bean class="org.springframework.security.vote.RoleVoter"/>   
  175.                 <bean class="org.springframework.security.vote.AuthenticatedVoter"/>   
  176.             </list>   
  177.         </property>   
  178.     </bean>   
  179.   
  180.     <bean id="rememberMeServices"  
  181.           class="org.springframework.security.ui.rememberme.TokenBasedRememberMeServices"  
  182.           p:key="springsecurity"  
  183.           p:userDetailsService-ref="userDetailsService"/>   
  184.   
  185.     <bean id="daoAuthenticationProvider"  
  186.           class="org.springframework.security.providers.dao.DaoAuthenticationProvider"  
  187.           p:userCache-ref="userCache"  
  188.           p:passwordEncoder-ref="passwordEncoder"  
  189.           p:userDetailsService-ref="userDetailsService"/>   
  190.     <bean id="passwordEncoder"  
  191.           class="org.springframework.security.providers.encoding.Md5PasswordEncoder"/>   
  192.   
  193.     <!-- 緩存配置 -->   
  194.     <bean id="resourceCache"  
  195.           class="com.shopin.modules.security.resourcedetails.EhCacheResourceCache">   
  196.         <property name="cache">   
  197.             <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean"  
  198.                   p:cacheManager-ref="cacheManager"  
  199.                   p:cacheName="resourceCache"/>   
  200.         </property>   
  201.     </bean>   
  202.     <bean id="userCache"  
  203.           class="org.springframework.security.providers.dao.cache.EhCacheBasedUserCache">   
  204.         <property name="cache">   
  205.             <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean"  
  206.                   p:cacheManager-ref="cacheManager"  
  207.                   p:cacheName="userCache"/>   
  208.         </property>   
  209.     </bean>   
  210.     <bean id="cacheManager"  
  211.           class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"  
  212.           p:configLocation="classpath:ehcache-hibernate.xml">   
  213.     </bean>   
  214.   
  215.     <bean id="userDetailsService" class="cn.shopin.miniweb.service.security.UserDetailServiceImpl"/>   
  216.   
  217.     <bean id="securityCacheManager"  
  218.           class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"  
  219.           p:transactionManager-ref="transactionManager"  
  220.           p:proxyTargetClass="true">   
  221.         <property name="target">   
  222.             <bean class="com.shopin.modules.security.cache.SecurityCacheManagerImpl"  
  223.                   p:sessionFactory-ref="sessionFactory"  
  224.                   p:resourcCache-ref="resourceCache"/>   
  225.         </property>   
  226.         <property name="transactionAttributes">   
  227.             <props>   
  228.                 <prop key="init*">PROPAGATION_REQUIRED,readOnly</prop>   
  229.                 <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>   
  230.             </props>   
  231.         </property>   
  232.     </bean>   
  233.     <bean id="loggerListener"  
  234.           class="org.springframework.security.event.authentication.LoggerListener"/>   
  235.   
  236. </beans>  
<?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:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">

    <!--
            FilterChainProxy會按順序來調用這些filter,使這些filter能享用Spring Ioc的功能,
            CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON 定義url比較前先轉爲小寫
            PATTERN_TYPE_APACHE_ANT 定義使用Apache ant的匹配模式
         -->
    <bean id="springSecurityFilterChain"
          class="org.springframework.security.util.FilterChainProxy">
        <property name="filterInvocationDefinitionSource">
            <value><![CDATA[
                    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                    PATTERN_TYPE_APACHE_ANT
                    /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor
                ]]></value>
        </property>
    </bean>
    <!--
        集成過濾器(HttpSessionContextIntegrationFilter是集成過濾器的一個實現)
           每次request前HttpSessionContextIntegrationFilter從Session中獲取Authentication對象,在request完後
           又把Authentication對象保存到Session中供下次request使用,此filter必須在其他Acegi filter前使用
    -->
    <bean id="httpSessionContextIntegrationFilter"
          class="org.springframework.security.context.HttpSessionContextIntegrationFilter"/>
    <!--
        退出(Logout)過濾器 退出登錄操作
    -->
    <bean id="logoutFilter"
          class="org.springframework.security.ui.logout.LogoutFilter">
        <!-- 退出系統後系統跳轉到此URL -->
        <constructor-arg value="/login.action"/>
        <!-- 退出系統後的操作(調用logout方法) -->
        <constructor-arg>
            <list>
                <!-- 實現了LogoutHandler接口(logout方法) -->
                <ref bean="rememberMeServices"/>
                <bean class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"/>
            </list>
        </constructor-arg>
    </bean>
    <!--
        處理表單認證filter:
        1.authenticationManager     認證管理器
        2.authenticationFailureUrl  定義登錄失敗時轉向的頁面
        3.defaultTargetUrl 	      定義登錄成功時轉向的頁面
        4.filterProcessesUrl        定義登錄請求的地址
        5.rememberMeServices        在驗證成功後添加cookie信息
    -->
    <bean id="authenticationProcessingFilter"
          class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter"
          p:authenticationManager-ref="authenticationManager"
          p:authenticationFailureUrl="/login.action?login_error=1"
          p:defaultTargetUrl="/user.action"
          p:filterProcessesUrl="/j_spring_security_check"
          p:rememberMeServices-ref="rememberMeServices"/>
    <!--
        認證管理器(org.springframework.security.AuthenticationManager接口)
         org.springframework.security.providers.ProviderManager是認證管理器的一個實現,
         ProviderManager通過遍歷一個提供者的集合來實現身份驗證,
         直到某一個認證提供者能夠成功地驗證該用戶的身份
    -->
    <!--
        通過Providers提供認證者列表,如果一個認證提供者失敗可以嘗試另外一個認證提供者,以保證獲取不同來源的身份認證,如
        DaoAuthenticationProvider        從數據庫中讀取用戶信息驗證身份
        AnonymousAuthenticationProvider  匿名用戶身份認證
        RememberMeAuthenticationProvider 已存cookie中的用戶信息身份認證

        其它的還有
        AuthByAdapterProvider           使用容器的適配器驗證身份
        CasAuthenticationProvider       根據Yale中心認證服務驗證身份, 用於實現單點登陸
        JaasAuthenticationProvider      從JASS登陸配置中獲取用戶信息驗證身份
        RemoteAuthenticationProvider    根據遠程服務驗證用戶身份
        RunAsImplAuthenticationProvider 對身份已被管理器替換的用戶進行驗證
        X509AuthenticationProvider      從X509認證中獲取用戶信息驗證身份
        TestingAuthenticationProvider   單元測試時使用

        每個認證者會對自己指定的證明信息進行認證,如DaoAuthenticationProvider僅對UsernamePasswordAuthenticationToken這個證明信息進行認證。
    -->
    <bean id="authenticationManager"
          class="org.springframework.security.providers.ProviderManager"
          p:sessionController-ref="concurrentSessionController">
        <property name="providers">
            <list>
                <ref bean="daoAuthenticationProvider"/>
                <bean                        class="org.springframework.security.providers.anonymous.AnonymousAuthenticationProvider"
                        p:key="springsecurity"/>
                <bean                       class="org.springframework.security.providers.rememberme.RememberMeAuthenticationProvider"
                        p:key="springsecurity"/>
            </list>
        </property>
    </bean>
    <!-- 阻止用戶在成功登錄之後再進行一次成功登錄 -->
    <bean id="concurrentSessionController"
          class="org.springframework.security.concurrent.ConcurrentSessionControllerImpl"
          p:maximumSessions="1"
          p:exceptionIfMaximumExceeded="true"
          p:sessionRegistry-ref="sessionRegistry"
          p:messageSource-ref="messageSource"/>
    <bean id="sessionRegistry"
          class="org.springframework.security.concurrent.SessionRegistryImpl"/>
    <bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
          p:basename="/WEB-INF/classes/messages_zh_CN"/>
    <bean id="securityContextHolderAwareRequestFilter"
          class="org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter"/>
    <!--
       利用cookie自動登陸filter
        當SecurityContextHolder中不存在Authentication.用戶授權信息,
        rememberMeProcessingFilter就會調用autoLogin()方法從cookie中獲取用戶信息,在驗證filter之前使用
    -->
    <bean id="rememberMeProcessingFilter"
          class="org.springframework.security.ui.rememberme.RememberMeProcessingFilter"
          p:authenticationManager-ref="authenticationManager"
          p:rememberMeServices-ref="rememberMeServices"/>
    <!--
        如果不存在任何授權信息時,自動添加匿名用戶身份至SecurityContextHolder中
    -->
    <bean id="anonymousProcessingFilter"
          class="org.springframework.security.providers.anonymous.AnonymousProcessingFilter"
          p:key="springsecurity"
          p:userAttribute="anonymousUser,ROLE_ANONYMOUS"/>
    <!--
       異常處理filter(異常轉換過濾器),主要是處理AccessDeniedException和AuthenticationException,
        將給每個異常找到合適的"去向"
    -->
    <bean id="exceptionTranslationFilter"
          class="org.springframework.security.ui.ExceptionTranslationFilter"
          p:accessDeniedHandler-ref="accessDeniedHandler"
          p:authenticationEntryPoint-ref="authenticationEntryPoint"/>
    <!-- 處理AccessDeniedException -->
    <bean id="accessDeniedHandler"
          class="org.springframework.security.ui.AccessDeniedHandlerImpl"
          p:errorPage="/accessDenied.jsp"/>
    <!--  -->
    <bean id="authenticationEntryPoint"
          class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint"
          p:loginFormUrl="/login.action"
          p:forceHttps="false"/>
    <!--
         使用過濾器安全攔截器保護資源
         filterSecurityInterceptor在執行轉向目標url前檢查objectDefinitionSource中設定的用戶權限信息,
          安全強制過濾器負責攔截請求,判斷請求是否安全,並且給予認證和訪問決策管理器一個機會來驗證用戶的身份和權限
          過程:
             首先,過濾器安全攔截器使用authenticationManager調用自己的provider來對用戶的認證信息進行驗證並獲取用戶已有的權限。
             然後,使用訪問決策管理器來判斷用戶是否擁用合適的授權來訪問受保護的資源。
              (objectDefinitionSource屬性定義了訪問URL需要的權限信息)
             最後,有投票者根據用戶持有認證和訪問url需要的屬性,調用自己的voter來投票,決定是否允許訪問。
    -->
    <bean id="filterSecurityInterceptor"
          class="org.springframework.security.intercept.web.FilterSecurityInterceptor"
          p:authenticationManager-ref="authenticationManager"
          p:accessDecisionManager-ref="accessDecisionManager"
          p:objectDefinitionSource-ref="objectDefinitionSource">
    </bean>
    <bean id="objectDefinitionSource"
          class="com.shopin.modules.security.intercept.web.DataBaseFilterInvocationDefinitionSource"
          p:convertUrlToLowercaseBeforeComprison="true"
          p:useAntPath="true"
          p:cacheManager-ref="securityCacheManager"/>
    <!--
         訪問決策管理器
           驗證用戶是否有權限訪問相應的資源(filterSecurityInterceptor中objectDefinitionSource屬性定義的訪問URL需要的屬性信息)
    -->
    <bean id="accessDecisionManager"
          class="org.springframework.security.vote.AffirmativeBased"
          p:allowIfAllAbstainDecisions="false">
        <property name="decisionVoters">
            <list>
                <bean class="org.springframework.security.vote.RoleVoter"/>
                <bean class="org.springframework.security.vote.AuthenticatedVoter"/>
            </list>
        </property>
    </bean>

    <bean id="rememberMeServices"
          class="org.springframework.security.ui.rememberme.TokenBasedRememberMeServices"
          p:key="springsecurity"
          p:userDetailsService-ref="userDetailsService"/>

    <bean id="daoAuthenticationProvider"
          class="org.springframework.security.providers.dao.DaoAuthenticationProvider"
          p:userCache-ref="userCache"
          p:passwordEncoder-ref="passwordEncoder"
          p:userDetailsService-ref="userDetailsService"/>
    <bean id="passwordEncoder"
          class="org.springframework.security.providers.encoding.Md5PasswordEncoder"/>

    <!-- 緩存配置 -->
    <bean id="resourceCache"
          class="com.shopin.modules.security.resourcedetails.EhCacheResourceCache">
        <property name="cache">
            <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean"
                  p:cacheManager-ref="cacheManager"
                  p:cacheName="resourceCache"/>
        </property>
    </bean>
    <bean id="userCache"
          class="org.springframework.security.providers.dao.cache.EhCacheBasedUserCache">
        <property name="cache">
            <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean"
                  p:cacheManager-ref="cacheManager"
                  p:cacheName="userCache"/>
        </property>
    </bean>
    <bean id="cacheManager"
          class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
          p:configLocation="classpath:ehcache-hibernate.xml">
    </bean>

    <bean id="userDetailsService" class="cn.shopin.miniweb.service.security.UserDetailServiceImpl"/>

    <bean id="securityCacheManager"
          class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
          p:transactionManager-ref="transactionManager"
          p:proxyTargetClass="true">
        <property name="target">
            <bean class="com.shopin.modules.security.cache.SecurityCacheManagerImpl"
                  p:sessionFactory-ref="sessionFactory"
                  p:resourcCache-ref="resourceCache"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="init*">PROPAGATION_REQUIRED,readOnly</prop>
                <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
            </props>
        </property>
    </bean>
    <bean id="loggerListener"
          class="org.springframework.security.event.authentication.LoggerListener"/>

</beans>

 

 

文章來源:http://www.javaeye.com/topic/259816

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章