我在我的数据库,其中包含像“ROLE_ADMIN”和“ROLE_USER”,并在的applicationContext-security.xml文件角色用户角色表,我所定义的filterSecurityInterceptor为:春季安全角色
<s:filter-chain pattern="/rpc/adminService"
filters="
authenticationProcessingFilter,
filterSecurityInterceptor"/>
<s:filter-chain pattern="/rpc/**"
filters="
concurrentSessionFilter,
httpSessionContextIntegrationFilter,
authenticationProcessingFilter,
rememberMeProcessingFilter,
anonymousProcessingFilter,
exceptionTranslationFilter,
filterSecurityInterceptor" />
<s:filter-chain pattern="/j_spring_security*"
filters="
concurrentSessionFilter,
httpSessionContextIntegrationFilter,
logoutFilter,
authenticationProcessingFilter,
rememberMeProcessingFilter,
anonymousProcessingFilter" />
<s:filter-chain pattern="/**" filters="none" />
</s:filter-chain-map>
<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager" ref="authenticationManager" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionSource">
<s:filter-invocation-definition-source>
<s:intercept-url pattern="/rpc/userService" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<s:intercept-url pattern="/rpc/adminService**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<s:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
</s:filter-invocation-definition-source>
</property>
</bean>
<bean id="authenticationManager" class="org.springframework.security.providers.ProviderManager">
<property name="sessionController" ref="concurrentSessionController" />
<property name="providers">
<list>
<ref bean="rememberMeAuthenticationProvider" />
<ref bean="daoAuthenticationProvider" />
</list>
</property>
</bean>
<bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="accountRepository" />
<property name="passwordEncoder" ref="passwordEncoder" />
</bean>
然而,当我试图访问某些资源作为管理员用户,它得到了拒绝,抱怨是:
An Authentication object was not found in the SecurityContext
如何将数据库中定义的角色转换为securityContext可识别的角色?
听起来好像你没有正确设置认证。请说明你如何配置过滤链。 – 2012-03-23 20:08:55
@LukeTaylor:我已更新代码以包含过滤器链。 thx – user468587 2012-03-23 21:18:17