2014-03-26 64 views
0

我正在嘗試使用tomcat認證爲我的spring web服務配置預認證。我嘗試了pre-auth spring示例並像下面那樣配置了我的applicationContext-security.xml以使用默認彈簧配置。Spring Web服務預認證過濾器映射角色

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:sec="http://www.springframework.org/schema/security" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> 

<bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"> 
    <sec:filter-chain-map path-type="ant"> 
     <sec:filter-chain pattern="/**" filters="sif,j2eePreAuthFilter,logoutFilter,etf,fsi"/> 
    </sec:filter-chain-map> 
</bean> 

<bean id="sif" class="org.springframework.security.web.context.SecurityContextPersistenceFilter"/> 

<sec:authentication-manager alias="authenticationManager"> 
    <sec:authentication-provider ref='preAuthenticatedAuthenticationProvider'/> 
</sec:authentication-manager> 

<bean id="preAuthenticatedAuthenticationProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider"> 
    <property name="preAuthenticatedUserDetailsService" ref="preAuthenticatedUserDetailsService"/> 
</bean> 

<bean id="preAuthenticatedUserDetailsService" 
     class="org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService"/> 

<bean id="j2eePreAuthFilter" class="org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter"> 
    <property name="authenticationManager" ref="authenticationManager"/> 
    <property name="authenticationDetailsSource"> 
     <bean class="org.springframework.security.web.authentication.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource"> 
      <property name="mappableRolesRetriever"> 
       <bean class="org.springframework.security.web.authentication.preauth.j2ee.WebXmlMappableAttributesRetriever" /> 
      </property> 
      <property name="userRoles2GrantedAuthoritiesMapper"> 
       <bean class="org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper"> 
        <property name="convertAttributeToUpperCase" value="true"/> 
       </bean> 
      </property> 
     </bean> 
    </property> 
</bean> 

<bean id="preAuthenticatedProcessingFilterEntryPoint" 
     class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"/> 

<bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"> 
    <constructor-arg value="/"/> 
    <constructor-arg> 
     <list> 
      <bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/> 
     </list> 
    </constructor-arg> 
</bean> 

<bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean"/> 

<bean id="etf" class="org.springframework.security.web.access.ExceptionTranslationFilter"> 
    <property name="authenticationEntryPoint" ref="preAuthenticatedProcessingFilterEntryPoint"/> 
</bean> 

<bean id="httpRequestAccessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased"> 
    <property name="allowIfAllAbstainDecisions" value="false"/> 
    <property name="decisionVoters"> 
     <list> 
      <ref bean="roleVoter"/> 
     </list> 
    </property> 
</bean> 

<bean id="fsi" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"> 
    <property name="authenticationManager" ref="authenticationManager"/> 
    <property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/> 
    <property name="securityMetadataSource"> 
     <sec:filter-invocation-definition-source> 
      <sec:intercept-url pattern="/**" access="TESTROLE"/> 
     </sec:filter-invocation-definition-source> 
    </property> 
</bean> 

<bean id="roleVoter" class="org.springframework.security.access.vote.RoleVoter"/> 

<bean id="securityContextHolderAwareRequestFilter" class="org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter"/> 

這裏TESTROLE是在Tomcat中-users.xml中 定義的角色,但現在我得到下面的錯誤。

java.lang.IllegalArgumentException: Unsupported configuration attributes: [TESTROLE] 
    org.springframework.security.access.intercept.AbstractSecurityInterceptor.afterPropertiesSet(AbstractSecurityInterceptor.java:156) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) 
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154) 
    org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:379) 

任何我想法,爲什麼發生這種情況?

回答

0

這僅僅是角色定義上的一個錯誤。對於spring-security來標識角色,他們需要以ROLE_開頭,所以我只是將我的角色更改爲ROLE_TEST。最後它工作。 :)