acegi 配置

xml 代码
applicationContext-security-acegi.xml
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">  
  3. <beans default-lazy-init="true" default-autowire="byName">  
  4.     <bean id="channelProcessingFilter"  
  5.           class="org.acegisecurity.securechannel.ChannelProcessingFilter">  
  6.         <property name="channelDecisionManager">  
  7.             <ref local="channelDecisionManager"/>    
  8.         </property>  
  9.         <property name="filterInvocationDefinitionSource">  
  10.             <value>  
  11.                 CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON   
  12.                 PATTERN_TYPE_APACHE_ANT   
  13.                 /j_security_check=REQUIRES_CAPTCHA_ONCE_ABOVE_THRESOLD_REQUESTS  
  14.             </value>  
  15.         </property>  
  16.     </bean>  
  17.   
  18.     <bean id="channelDecisionManager"  
  19.           class="org.acegisecurity.securechannel.ChannelDecisionManagerImpl">  
  20.         <property name="channelProcessors">    
  21.             <list>  
  22.                 <ref local="testOnceAfterMaxRequestsCaptchaChannelProcessor"/>  
  23.                 <ref local="alwaysTestAfterTimeInMillisCaptchaChannelProcessor"/>  
  24.                 <ref local="alwaysTestAfterMaxRequestsCaptchaChannelProcessor"/>  
  25.                 <ref local="alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor"/>  
  26.             </list>  
  27.         </property>  
  28.     </bean>  
  29.   
  30.     <!-- REQUIRES_CAPTCHA_ONCE_ABOVE_THRESOLD_REQUESTS -->  
  31.     <bean id="testOnceAfterMaxRequestsCaptchaChannelProcessor"  
  32.           class="org.acegisecurity.captcha.TestOnceAfterMaxRequestsCaptchaChannelProcessor">  
  33.         <property name="thresold">  
  34.             <value>0</value>  
  35.         </property>  
  36.         <property name="entryPoint">  
  37.             <ref bean="captchaEntryPoint"/>  
  38.         </property>  
  39.     </bean>  
  40.   
  41.     <!-- REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS -->  
  42.     <bean id="alwaysTestAfterMaxRequestsCaptchaChannelProcessor"  
  43.           class="org.acegisecurity.captcha.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor">  
  44.         <property name="thresold">  
  45.             <value>5</value>  
  46.         </property>  
  47.         <property name="entryPoint">  
  48.             <ref bean="captchaEntryPoint"/>  
  49.         </property>  
  50.     </bean>  
  51.   
  52.     <!-- REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS -->  
  53.     <bean id="alwaysTestAfterTimeInMillisCaptchaChannelProcessor"  
  54.           class="org.acegisecurity.captcha.AlwaysTestAfterTimeInMillisCaptchaChannelProcessor">  
  55.         <property name="thresold">  
  56.             <value>5000</value>  
  57.         </property>  
  58.         <property name="entryPoint">  
  59.             <ref bean="captchaEntryPoint"/>  
  60.         </property>  
  61.     </bean>  
  62.   
  63.     <!-- REQUIRES_CAPTCHA_BELOW_AVERAGE_TIME_IN_MILLIS_REQUESTS -->  
  64.     <bean  
  65.             id="alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor"  
  66.             class="org.acegisecurity.captcha.AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor">  
  67.         <property name="thresold">  
  68.             <value>20000</value>  
  69.         </property>  
  70.         <property name="entryPoint">  
  71.             <ref bean="captchaEntryPoint"/>  
  72.         </property>  
  73.     </bean>  
  74.   
  75.     <bean id="captchaEntryPoint"  
  76.           class="org.acegisecurity.captcha.CaptchaEntryPoint">  
  77.         <property name="captchaFormUrl">  
  78.             <value>/login.jsp?login_error=code_error</value>  
  79.         </property>  
  80.         <property name="includeOriginalRequest">  
  81.             <value>false</value>  
  82.         </property>  
  83.         <property name="includeOriginalParameters">  
  84.             <value>false</value>  
  85.         </property>  
  86.     </bean>  
  87.   
  88.     <bean id="captchaValidationProcessingFilter"  
  89.           class="org.acegisecurity.captcha.CaptchaValidationProcessingFilter">  
  90.         <property name="captchaService">  
  91.             <ref bean="captchaService"/>  
  92.         </property>  
  93.         <property name="captchaValidationParameter" value="j_captcha_response"/>  
  94.     </bean>  
  95.   
  96.     <!-- imageCaptchaService is injected into captchaImageCreateController as well as to captchaService beans -->  
  97.     <bean id="captchaService" class="com.systop.common.security.jcaptcha.JCaptchaServiceProxyImpl">  
  98.         <property name="jcaptchaService" ref="imageCaptchaService"/>  
  99.     </bean>  
  100.   
  101.     <bean id="imageCaptchaService" class="com.octo.captcha.service.image.DefaultManageableImageCaptchaService">  
  102.         <constructor-arg type="com.octo.captcha.service.captchastore.CaptchaStore" index="0">  
  103.             <ref bean="fastHashMapCaptchaStore"/>  
  104.         </constructor-arg>  
  105.         <!-- (1) which captcha Engine you use -->  
  106.         <constructor-arg type="com.octo.captcha.engine.CaptchaEngine" index="1">  
  107.             <ref bean="captchaEngineEx"/>  
  108.         </constructor-arg>  
  109.         <constructor-arg index="2">  
  110.             <value>180</value>  
  111.         </constructor-arg>  
  112.         <constructor-arg index="3">  
  113.             <value>100000</value>  
  114.         </constructor-arg>  
  115.         <constructor-arg index="4">  
  116.             <value>75000</value>  
  117.         </constructor-arg>  
  118.     </bean>  
  119.   
  120.     <bean id="fastHashMapCaptchaStore" class="com.octo.captcha.service.captchastore.FastHashMapCaptchaStore"/>  
  121.   
  122.     <!-- (2) you can define more than one captcha engine here -->  
  123.     <bean id="captchaEngineEx"  
  124.           class="com.systop.common.security.jcaptcha.engine.CaptchaEngineEx"/>  
  125.   
  126. </beans>  
applicationContext-security-captcha.xml
xml 代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">  
  3. <beans default-lazy-init="true" default-autowire="byName">  
  4.     <!-- ======================== FILTER CHAIN ======================= -->  
  5.   
  6.     <!--  if you wish to use channel security, add "channelProcessingFilter," in front   
  7.         of "httpSessionContextIntegrationFilter" in the list below -->  
  8.     <!--   
  9.         FilterChainProxy会按顺序来调用这些filter,使这些filter能享用Spring ioc的功能,   
  10.         CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON定义了url比较前先转为小写   
  11.         PATTERN_TYPE_APACHE_ANT定义了使用Apache ant的匹配模式   
  12.         如果加入了验证码,则在logoutFilter后加入captchaValidationProcessingFilter   
  13.         如果加入channel验证,把channelProcessingFilter加到authenticationProcessingFilter之前   
  14.     -->  
  15.     <bean id="filterChainProxy"  
  16.         class="org.acegisecurity.util.FilterChainProxy">  
  17.         <property name="filterInvocationDefinitionSource">    
  18.             <value>  
  19.                 CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON   
  20.                 PATTERN_TYPE_APACHE_ANT   
  21.                 /**=httpSessionContextIntegrationFilter,logoutFilter,captchaValidationProcessingFilter,channelProcessingFilter,authenticationProcessingFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor   
  22.             </value>  
  23.         </property>  
  24.     </bean>  
  25.   
  26.     <!-- ======================== AUTHENTICATION ======================= -->  
  27.   
  28.     <!--   
  29.         通过Providers提供认证者列表,如果一个认证提供者失败可以尝试另外一个认证提供者,以保证获取不同来源的身份认证,如   
  30.         DaoAuthenticationProvider 从数据库中读取用户信息验证身份   
  31.         AnonymousAuthenticationProvider 匿名用户身份认证   
  32.         RememberMeAuthenticationProvider 已存cookie中的用户信息身份认证   
  33.            
  34.         其它的还有   
  35.         AuthByAdapterProvider 使用容器的适配器验证身份   
  36.         CasAuthenticationProvider 根据Yale中心认证服务验证身份, 用于实现单点登陆   
  37.         JaasAuthenticationProvider 从JAAS登陆配置中获取用户信息验证身份   
  38.         RemoteAuthenticationProvider 根据远程服务验证用户身份   
  39.         RunAsImplAuthenticationProvider 对身份已被管理器替换的用户进行验证   
  40.         X509AuthenticationProvider 从X509认证中获取用户信息验证身份   
  41.         TestingAuthenticationProvider 单元测试时使用   
  42.            
  43.         每个认证者会对自己指定的证明信息进行认证,如DaoAuthenticationProvider仅对UsernamePasswordAuthenticationToken这个证明信息进行认证。   
  44.     -->  
  45.     <bean id="authenticationManager"  
  46.         class="org.acegisecurity.providers.ProviderManager">  
  47.         <property name="providers">  
  48.             <list>  
  49.                 <ref local="daoAuthenticationProvider" />  
  50.                 <ref local="anonymousAuthenticationProvider" />  
  51.                 <ref local="rememberMeAuthenticationProvider" />  
  52.                 <!-- testingAuthenticationProvider仅供测试环境用,正式生产平台请去除   
  53.                     <ref local="testingAuthenticationProvider"/> -->  
  54.             </list>  
  55.         </property>  
  56.         <!-- property name="sessionController">  
  57.             <ref bean="concurrentSessionController" />  
  58.         </property-->  
  59.     </bean>  
  60.   
  61.     <!-- 可以阻止某个用户名在已经成功登录进web应用的同时再进行一次成功的登录 -->  
  62.     <bean id="concurrentSessionController"  
  63.         class="org.acegisecurity.concurrent.ConcurrentSessionControllerImpl">  
  64.         <property name="maximumSessions">  
  65.             <value>1</value>  
  66.         </property>  
  67.         <property name="sessionRegistry">  
  68.             <ref local="sessionRegistry" />  
  69.         </property>  
  70.         <property name="exceptionIfMaximumExceeded" value="true" />  
  71.     </bean>  
  72.   
  73.     <bean id="sessionRegistry"  
  74.         class="org.acegisecurity.concurrent.SessionRegistryImpl" />  
  75.   
  76.     <!--   
  77.         jdbcDaoImpl 用于在数据中获取用户信息。   
  78.         acegi提供了用户及授权的表结构,但是您也可以自己来实现。   
  79.     -->  
  80.     <bean id="jdbcDaoImpl" class="com.systop.common.security.acegi.UserDetailService">  
  81.         <property name="userManager" ref="userManager"></property>    
  82.         <!-- property name="userCache" ref="userCache"></property-->    
  83.     </bean>  
  84.        
  85.     <!-- 缓存用户和资源相对应的权限信息 -->  
  86.     <bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">  
  87.         <property name="cache"><ref local="userCacheBackend"/></property>  
  88.     </bean>  
  89.       
  90.     <bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">  
  91.        <property name="cacheManager">  
  92.             <ref local="cacheManager"/>  
  93.        </property>  
  94.         <property name="cacheName">  
  95.             <value>userCache</value>  
  96.         </property>  
  97.     </bean>  
  98.       
  99.     <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>  
  100.       
  101.     <!-- 使用Md5算法加密 -->  
  102.     <bean id="passwordEncoder"  
  103.         class="org.acegisecurity.providers.encoding.Md5PasswordEncoder" />  
  104.   
  105.     <!--   
  106.         userDetailsService 定义jdbcDaoImpl从数据库获取用户信息   
  107.         userCache ehcache缓存user信息。   
  108.         passwordEncoder 取得密码后作加密   
  109.     -->  
  110.     <bean id="daoAuthenticationProvider"  
  111.         class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">  
  112.         <property name="userDetailsService" ref="jdbcDaoImpl" />  
  113.         <property name="userCache" ref="userCache" />  
  114.         <property name="passwordEncoder" ref="passwordEncoder" />  
  115.         <property name="saltSource"><null/></property>  
  116.     </bean>  
  117.   
  118.   
  119.     <!--   
  120.         <bean id="testingAuthenticationProvider"  
  121.         class="org.acegisecurity.providers.TestingAuthenticationProvider"/>  
  122.     -->  
  123.   
  124.     <!-- 自动接收 AuthenticationEvent 信息 -->  
  125.     <bean id="loggerListener"  
  126.         class="org.acegisecurity.event.authentication.LoggerListener" />  
  127.   
  128.     <!--  
  129.         用于处理HTTP头的认证信息,如从Spring远程协议(如Hessian和Burlap)或普通的浏览器如IE,Navigator的HTTP头中获取用户信息  
  130.     -->  
  131.     <bean id="basicProcessingFilter"<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值