Acegi+Tomcat5.5(测试例子问题汇总)

Acegi+Tomcat(测试例子问题汇总)
从网上下了个达人的Acegi的例子,可能是我学习Acegi太晚的原因,那个例子是acegi-0.8的版本,而我刚入手用的就是Acegi1.0.4的版本,故在看了看其中的例子后,开始进行版本的切换问题。
首先需要替换掉acegi的jar包.
然后修改在applicationContext-basic.xml,applicationContext-security-acegi.xml,web.xml文件中对应的类名.
都比较简单,主要是在Acegi0.8版本中有一个securityEnforcementFilter. 作用主要是将http请求转发给filterSecurityInterceptor,由filterSecurityInterceptor来对HTTP请求的合法性进行判断。
filterSecurityInterceptor 实现对URL资源进行授权访问。 authenticationEntryPoint 配置登录界面信息。
<bean id="securityEnforcementFilter" class="org.acegisecurity.intercept.web.SecurityEnforcementFilter">
 <property name="filterSecurityInterceptor"><ref local="filterInvocationInterceptor"/></property>
 <property name="authenticationEntryPoint"><ref local="authenticationProcessingFilterEntryPoint"/></property>
</bean>
但是在1.0版本中,无此过滤器.故单独修改applicationContext-security-acegi.xml文件中的filterChainProxyfilter项.在其中单独增加filterInvocationInterceptor过滤器.屏蔽掉对securityEnforcementFilter的定义.
同时,该例子未进行exceptionTranslationFilter过滤器的定义.
造成在访问http://localhost:8080/Sample/contactlist.jsp的时候,直接出现以下错误:
org.acegisecurity.AccessDeniedException: Access is denied
    org.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:68)
    org.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:292)
    org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:104)
    org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
    org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
    org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
    org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
    org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:229)
    org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
    org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:286)
    org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
    org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
    org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
而不是像在struts中增加一个过滤器,如果判断无登陆信息,会自动跳转到登陆页面中.
故我增加了exceptionTranslationFilter
  <!-- 异常转换过滤器,主要是处理AccessDeniedException和AuthenticationException,将给每个异常找到合适的"去向"   -->
  <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
      <property name="authenticationEntryPoint"><ref bean="authenticationProcessingFilterEntryPoint"/></property>
  </bean>
增加后,当未登陆,直接访问http://localhost:8080/Sample/contactlist.jsp时,其会自动跳转到login.jsp页面.
    

同时我在定义filterChainProxyfilter的filterInvocationDefinitionSource属性时候,
/**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,anonymousProcessingFilter,
exceptionTranslationFilter,filterInvocationInterceptor
出现了以下问题:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named '' is defined: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,contactDao,contactManagerTarget,transactionManager,jdbcTemplate,businessAccessDecisionManager,customEditorConfigurer,transactionInterceptor,contactManagerSecurity,contactManager,filterChainProxy,httpSessionContextIntegrationFilter,authenticationManager,jdbcDaoImpl,cacheManager,userCacheBackend,userCache,daoAuthenticationProvider,loggerListener,anonymousProcessingFilter,anonymousAuthenticationProvider,authenticationProcessingFilter,authenticationProcessingFilterEntryPoint,filterInvocationInterceptor,httpRequestAccessDecisionManager,roleVoter,exceptionTranslationFilter]; root of BeanFactory hierarchy
    org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:349)
    org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:671)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:151)
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:557)
    org.acegisecurity.util.FilterChainProxy.obtainAllDefinedFilters(FilterChainProxy.java:221)
    org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:136)
    org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
弄得我非常之郁闷,结果在我修改了filterInvocationDefinitionSource属性定义为:
/**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
后,程序问题解决,只是多了一个换行而已,不知道为什么没有准确识别.或许是因为我的写法有问题吧,我暂时的认为是多了一个换行符.不知道你们有没有碰到过,我看网上别的介绍,经常出现换行的那种写法,我这里就是不行,如果有看到这个问题的达人,能帮我指明是最好的了,谢谢.

同时,例子中只用到了用户表和权限表,我按照RBAC的要求,对表进行了修改,主要是为了适应对domain object的控制,但是这部分还有问题,我现在还不太清楚acegi是怎样对对象的实例进行控制的.希望有达人看到后,如果有合适的例子能给我发一个,虽然在一般的项目中用不到对实例的控制,一般都是控制到方法.但是多学学总没有坏处,^0^.
根据我自己建立的表,对xml中的相关sql语句进行了修改.其中建表规则符合RBAC规范.就不再发出来了.同时符上我修改后的3个xml文件.
如果有和我情况相同的朋友,给个小小的提示哈,别忘了修改工程里的index.jsp.那里引用了很多acegi0.8包中的类,别忘了修改.(^0^)
我还在web.xml文件中增加了一个欢迎页面,否则也还是有点小郁闷的.
这是我的一点心得,没准有您用得上的,不过如果我的描述有问题,也请你指出,不过千万别拿砖拍我哈.
看着觉得不怎么样的,也请一笑而过,因为我是个小菜鸟.......(-_-!)
/*********************************(1) web.xml**************************************************************************/

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>XMNMS</display-name>
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
  </context-param>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      /WEB-INF/applicationContext-basic.xml
      /WEB-INF/applicationContext-security-acegi.xml
    </param-value>
  </context-param>

<!--Acegi Filter Chain Proxy -->
<!-- acegi通过实现了Filter接口的FilterToBeanProxy提供一种特殊的使用Servlet Filter的方式,
     它委托Spring中的Bean:FilterChainProxy来完成过滤功能。FilterChainProxy包含了处理
     认证过程的filter列表,每个filter都有各自的功能。-->
  <filter>
    <filter-name>AcegiProxy</filter-name>
    <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
      <param-name>targetClass</param-name>
      <param-value>org.acegisecurity.util.FilterChainProxy</param-value>
    </init-param>
  </filter>
<!-- 限定了FilterToBeanProxy的URL匹配模式,只有*.do和*.jsp和/j_acegi_security_check 的请求才会受到权限控制,对javascript,css等不限制。 -->
  <filter-mapping>
    <filter-name>AcegiProxy</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!--
  - Loads the root application context of this web app at startup.
  - The application context is then available via
  - WebApplicationContextUtils.getWebApplicationContext(servletContext).
  -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

  <!--
         The HttpSessionEventPublisher will publish
         HttpSessionCreatedEvent and HttpSessionDestroyedEvent
         to the WebApplicationContext
         HttpSessionEventPublisher用于发布HttpSessionApplicationEvents和HttpSessionDestroyedEvent事件给spring的applicationcontext
  -->
  <listener>
    <listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class>
  </listener>
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>

</web-app>


/*********************************(2) applicationContext-basic.xml*****************************************************/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- applicationContext-basic.xml主要包括数据访问对象,业务方法,业务方法安全管理拦截器的配置信息。
     主要讲解业务方法安全管理拦截器(MethodSecurityInterceptor)的相关配置,其它的配置就不再赘述了,请参考相关文档。 -->
<beans>
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass">
      <value>com.ibm.db2.jcc.DB2Driver</value>
    </property>
    <property name="jdbcUrl">
      <value>jdbc:db2://localhost:50000/TestDB</value>
    </property>
    <property name="user">
      <value>db2test</value>
    </property>
    <property name="password">
      <value>db2test</value>
    </property>
    <property name="initialPoolSize">
      <value>10</value>
    </property>
    <property name="minPoolSize">
      <value>10</value>
    </property>
    <property name="maxPoolSize">
      <value>50</value>
    </property>
    <property name="checkoutTimeout">
      <value>5000</value>
    </property>
    <property name="maxIdleTime">
      <value>1800</value>
    </property>
    <property name="idleConnectionTestPeriod">
      <value>3000</value>
    </property>
    <property name="acquireIncrement">
      <value>5</value>
    </property>
  </bean>
 
  <!--dao start -->
  <bean id="contactDao" class="sample.dao.impl.ContactDao">
    <property name="dataSource">
      <ref bean="dataSource"/>
    </property>
  </bean>

  <!--service start -->
  <bean id="contactManagerTarget" class="sample.service.impl.ContactManager" >
    <property name="contactDao">
      <ref bean="contactDao"/>
    </property>
  </bean>

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource">
      <ref local="dataSource"/>
    </property>
  </bean>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
      <ref bean="dataSource"/>
    </property>
  </bean>

  <bean id="businessAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
     <property name="allowIfAllAbstainDecisions"><value>false</value></property>
     <property name="decisionVoters">
        <list>
           <ref bean="roleVoter"/>
        </list>
     </property>
  </bean>

  <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    <property name="customEditors">
      <map>
        <entry key="org.acegisecurity.intercept.method.MethodDefinitionSource">
          <bean class="sample.util.DataSourceMethodDefinitionSourceEditor">
            <property name="jdbcTemplate"> <ref bean="jdbcTemplate"/> </property>
          </bean>
        </entry>
      </map>
    </property>
  </bean>

  <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
      <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributeSource">
      <value>
        sample.service.impl.ContactManager.*=PROPAGATION_REQUIRED
      </value>
    </property>
  </bean>


  <!--authenticationManager 认证管理器
        accessDecisionManager投票通过策略管理器,和filterInvocationInterceptor采用相同的策略管理器,在实际项目中,如果有需要可以采用不同的策略管理器。
        bjectDefinitionSource 业务方法的权限配置信息。用于指定不同的业务方法资源对应的权限。
  -->
  <bean id="contactManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
     <property name="authenticationManager"><ref bean="authenticationManager"/></property>
     <property name="accessDecisionManager"><ref bean="businessAccessDecisionManager"/></property>
     <property name="objectDefinitionSource">
        <value>
               <!-- select authority,PROTECTED_RES from authorities where AUTH_TYPE='FUNCTION' and authority like 'AUTH_FUNC_ContactManager%'  -->   
               select p.name as authority,r.res_string as PROTECTED_RES
            from sw_permissions as p ,sw_permission_resource as pr,sw_resources as r
            where p.id = pr.permission_id and pr.resource_id = r.id
              and p.name like 'AUTH_FUNC_ContactManager%' and r.res_type ='FUNCTION'
        </value>
     </property>
  </bean>

  <bean id="contactManager" class="org.springframework.aop.framework.ProxyFactoryBean">
     <property name="proxyInterfaces"><value>sample.service.IContactManager</value></property>
     <property name="interceptorNames">
        <list>
           <idref local="transactionInterceptor"/>
           <idref local="contactManagerSecurity"/>
           <idref local="contactManagerTarget"/>
        </list>
     </property>
  </bean>
</beans>






/*********************************(3) applicationContext-security-acegi.xml********************************************/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
   <!-- ======================== FILTER CHAIN ======================= -->
    <!-- FilterChainProxy会按顺序来调用这些filter,使这些filter能享用Spring ioc的功能,
         CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON定义了url比较前先转为小写,
         PATTERN_TYPE_APACHE_ANT定义了使用Apache ant的匹配模式
         
         SecurityContext的认证主体安全信息在一个HTTP请求线程的多个调用之间是共享的(通过ThreadLocal),
         但它不能在多个请求之间保持共享。为了解决这个问题,Acegi将认证主体安全信息缓存于HttpSession中,
         当用户请求一个受限的资源时,Acegi通过 HttpSessionContextIntegrationFilter将认证主体信息从HttpSession中加载到 SecurityContext实例中,
         认证主体关联的SecurityContext实例保存在Acegi容器级的 SecurityContextHolder里。
         当请求结束之后,HttpSessionContextIntegrationFilter执行相反的操作,将SecurityContext中的认证主体安全信息重新转存到HttpSession中,
         然后从SecurityContextHolder中清除对应的SecurityContext实例。通过HttpSession转存机制,用户的安全信息就可以在多个HTTP请求间共享,
         同时保证 SecurityContextHolder中仅保存当前有用的用户安全信息.    
         
         -->
    <bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
      <property name="filterInvocationDefinitionSource">
         <value>
            CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
            PATTERN_TYPE_APACHE_ANT
              /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
         </value>
      </property>
    </bean>
    <!-- 每次request前 HttpSessionContextIntegrationFilter从Session中获取Authentication对象,
         在request完后, 又把Authentication对象保存到Session中供下次request使用,
         此filter必须在其他Acegi filter前使用,使之能跨越多个请求。 -->
  <bean id="httpSessionContextIntegrationFilter" class="org.acegisecurity.context.HttpSessionContextIntegrationFilter">
<!-- <property name="context"><value>org.acegisecurity.context.SecurityContext</value></property> -->         
  </bean>

   <!-- ======================== AUTHENTICATION 基础认证 ======================= -->
   <!-- 起到认证管理的作用,它将验证的功能委托给多个Provider,并通过遍历Providers, 以保证获取不同来源的身份认证,
        若某个Provider能成功确认当前用户的身份,authenticate()方法会返回一个完整的包含用户授权信息的Authentication对象,否则会抛出一个AuthenticationException。 -->
   <!-- DaoAuthenticationProvider 从数据库中读取用户信息验证身份
        AnonymousAuthenticationProvider 匿名用户身份认证
        RememberMeAuthenticationProvider 已存cookie中的用户信息身份认证
        AuthByAdapterProvider 使用容器的适配器验证身份
        CasAuthenticationProvider 根据Yale中心认证服务验证身份, 用于实现单点登陆
        JaasAuthenticationProvider 从JASS登陆配置中获取用户信息验证身份
        RemoteAuthenticationProvider 根据远程服务验证用户身份
        RunAsImplAuthenticationProvider 对身份已被管理器替换的用户进行验证
        X509AuthenticationProvider 从X509认证中获取用户信息验证身份
        TestingAuthenticationProvider 单元测试时使用 -->
   <!-- daoAuthenticationProvider主要功能是从数据库取出用户名和密码,判断登录信息是否正确,如果是,则取出用户权限等用户信息,并且存放到cache中,以便以后再次使用。 -->
   <bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
      <property name="providers">
         <list>
            <ref local="daoAuthenticationProvider"/>
           <ref local="anonymousAuthenticationProvider"/>
         </list>
      </property>
   </bean>
   <!-- jdbcDaoImpl是认证数据访问对象,它能够从默认的数据库结构中获取用户信息,由于Acegi默认的数据库结构和本程序的不
        同,因此需要修改jdbcDaoImpl的默认sql。注意,采用这种方式能够使Acegi很好的兼容旧的应用程序,因为它对底层的数据结
        构并没有强制要求。jdbcDaoImpl配置说明:
        dataSource 数据源bean
        usersByUsernameQuery 用户信息查询sql
        authoritiesByUsernameQuery 用户权限查询sql-->
   <bean id="jdbcDaoImpl" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
     <property name="dataSource"><ref bean="dataSource"/></property>
     <property name="usersByUsernameQuery">
<!--    <value>SELECT USERNAME, PASSWORD,ENABLED FROM USERINFO WHERE USERNAME=?</value>   -->
        <value>SELECT LOGINID, PASSWORD,STATUS AS ENABLED FROM SW_USERS WHERE LOGINID=?</value>   
     </property>
     <property name="authoritiesByUsernameQuery">
<!--
       <value>
         SELECT username,authority FROM userinfo as u, authorities as a,user_auth as ua
         WHERE u.user_id=ua.user_id
         and a.auth_id=ua.auth_id
         and u.username = ?
       </value>
-->
       <value>
            select u.loginid as username, p.name as authority
            from sw_users as u,sw_user_role as ur,sw_role_permission as rp,sw_permissions as p
            where u.id = ur.user_id and ur.role_id = rp.role_id and rp.permission_id = p.id and u.loginid =?
       </value>       
     </property>
   </bean>

  <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>

  <bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
     <property name="cacheManager"> <ref local="cacheManager"/> </property>
     <property name="cacheName"> <value>userCache</value> </property>
  </bean>
  <!--     userCache用于定义用户信息cache功能的提供者。userCache配置说明:
        cache 定义ehcache工厂bean
        本程序采用ehcache作为cache实现。由于认证管理器在每次对http请求进行认证之前都会查找用户信息,通过使用cache就可以
        避免每次都重复访问数据库。  -->
  <bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
     <property name="cache"><ref local="userCacheBackend"/></property>
  </bean>

   <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
      <property name="userDetailsService"><ref local="jdbcDaoImpl"/></property>
      <property name="userCache"><ref local="userCache"/></property>
   </bean>

   <!-- Automatically receives AuthenticationEvent messages from DaoAuthenticationProvider -->
   <bean id="loggerListener" class="org.acegisecurity.event.authentication.LoggerListener"/>

   <!-- anonymousProcessingFilter的作用是判断ContextHolder中是否有Authentication对象,如果没有就创建一个Authentication对
        象,其中包含的用户名是anonymousUser,用户权限是AUTH_ANONYMOUS。这使得没有登录的匿名用户能够自动的获得匿
        名的用户名和权限。  -->
  <bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
     <property name="key"><value>foobar</value></property>
     <property name="userAttribute"><value>anonymousUser,AUTH_ANONYMOUS</value></property>
  </bean>

  <bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
     <property name="key"><value>foobar</value></property>
  </bean>

   <!-- ===================== HTTP REQUEST SECURITY ==================== -->
   <!-- authenticationFailureUrl 认证失败后,重定向的url
        defaultTargetUrl 认证成功后,重定向的url
        filterProcessesUrl该过滤器拦截的url,通常是/j_acegi_security_check,和登录页面(login.jsp)的登录表单的action相同
        authenticationManager(认证管理器)用于管理AuthenticationProvider(认证提供者)。它的作用是使你能够通过多个不同的认
        证管理源来对用户进行认证。认证管理器将依次调用认证提供者的认证方法,直到认证通过。本程序使用两种认证提供者。
         -->
   <bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
      <property name="authenticationManager"><ref bean="authenticationManager"/></property>
      <property name="authenticationFailureUrl"><value>/login.jsp?login_error=1</value></property>
      <property name="defaultTargetUrl"><value>/index.jsp</value></property>
      <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
   </bean>
    <!--     ACEGI 0.8.3
         securityEnforcementFilter的作用主要是将http请求转发给filterSecurityInterceptor,由filterSecurityInterceptor来对HTTP请求的合法性进行判断。
         filterSecurityInterceptor 实现对URL资源进行授权访问。
         authenticationEntryPoint 配置登录界面信息。
      <bean id="securityEnforcementFilter" class="org.acegisecurity.intercept.web.SecurityEnforcementFilter">
         <property name="filterSecurityInterceptor"><ref local="filterInvocationInterceptor"/></property>
         <property name="authenticationEntryPoint"><ref local="authenticationProcessingFilterEntryPoint"/></property>
      </bean>
     -->
   <bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
      <property name="loginFormUrl"><value>/login.jsp</value></property>
      <property name="forceHttps"><value>false</value></property>
   </bean>

   <!-- authenticationManager 认证管理器
           accessDecisionManager 投票通过策略管理器
           objectDefinitionSourceURL的权限配置信息。用于指定不同的URL资源对应的权限
           配置指定AUTH_ANONYMOUS权限的用户(即匿名用户)只可以访问图片资源和登录页面,AUTH_USER权限的用户可以访问全部WEB资源。
    -->
   <bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
      <property name="authenticationManager"><ref bean="authenticationManager"/></property>
      <property name="accessDecisionManager"><ref local="httpRequestAccessDecisionManager"/></property>
      <property name="objectDefinitionSource">
         <value>
                CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                PATTERN_TYPE_APACHE_ANT
                /**/*.jpg=AUTH_ANONYMOUS,AUTH_USER
                /**/*.gif=AUTH_ANONYMOUS,AUTH_USER
                /**/*.png=AUTH_ANONYMOUS,AUTH_USER
                /login.jsp*=AUTH_ANONYMOUS,AUTH_USER
                  /**=AUTH_USER
         </value>
      </property>
   </bean>
   
    <!--allowIfAllAbstainDecisions 设定是否允许:“没人反对就通过”的投票策略
        decisionVoters 投票者
        AffirmativeBased(至少一个投票者同意方可通过),ConsensusBased(多数投票者同意方可通过),UnanimousBased(所有投
        票者同意方可通过)。本程序采用AffirmativeBased策略,并且禁止“没人反对就通过”的投票策略        
      -->
  <bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
     <property name="allowIfAllAbstainDecisions"><value>false</value></property>
     <property name="decisionVoters">
        <list>
           <ref bean="roleVoter"/>
        </list>
     </property>
  </bean>
  <!-- rolePrefix该投票者支持的权限前缀,默认是“ROLE_”,本程序所有的权限字符串均以“AUTH_”开头,故设为“AUTH_”
       通过设定rolePrefix可以指定roleVoter所支持的权限范围。 -->
  <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter">
    <property name="rolePrefix"><value>AUTH_</value></property>
  </bean>
 
  <!-- 异常转换过滤器,主要是处理AccessDeniedException和AuthenticationException,将给每个异常找到合适的"去向"   -->
  <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
      <property name="authenticationEntryPoint"><ref bean="authenticationProcessingFilterEntryPoint"/></property>
  </bean>

</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值