【发布时间】:2015-09-25 01:35:56
【问题描述】:
你好(感谢阅读;)
我遇到了这种非常烦人的情况:
首先我想为我们的 Spring 应用程序应用安全性, 我很高兴得到 403,所以第二天我想真正授权人们使用该应用程序。
这似乎比预期更难做到:(
在进行了一些预授权工作后,我们决定我们的应用程序不需要明确的 Spring Security(因为我们有其他身份验证),因此我们选择了匿名身份验证,
我按照spring-security-master 的指南进行预身份验证,并按照the reference page for anonymous authentication 上的规范对其进行了调整,但没有成功。
(我仍然收到错误代码 403)
我的 applicationContext-security.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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 request-matcher="ant">
<sec:filter-chain pattern="/**" filters="anonymousAuthFilter"/>
</sec:filter-chain-map>
</bean>
<bean id="anonymousAuthFilter"
class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter">
<constructor-arg value="foobar"/>
</bean>
<bean id="anonymousAuthenticationProvider"
class="org.springframework.security.authentication.AnonymousAuthenticationProvider">
<constructor-arg value="foobar"/>
</bean>
<bean id="filterSecurityInterceptor"
class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
<property name="authenticationManager" ref="authenticationManager"/>
<property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/>
<property name="securityMetadataSource">
<sec:filter-security-metadata-source>
<sec:intercept-url pattern='/index.jsp' access='ROLE_ANONYMOUS'/>
<sec:intercept-url pattern='/**' access='ROLE_ANONYMOUS'/>
</sec:filter-security-metadata-source>
</property>
</bean>
<bean id="httpRequestAccessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<constructor-arg>
<list>
<ref bean="roleVoter"/>
</list>
</constructor-arg>
<property name="allowIfAllAbstainDecisions" value="true"/>
</bean>
<bean id="roleVoter" class="org.springframework.security.web.access.expression.WebExpressionVoter"/>
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="anonymousAuthenticationProvider" />
</sec:authentication-manager>
</beans>
我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<filter>
<filter-name>filterChainProxy</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>filterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<security-role>
<role-name>ROLE_USER</role-name>
</security-role>
<security-role>
<role-name>ROLE_SUPERVISOR</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>All areas</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ROLE_USER</role-name>
</auth-constraint>
</security-constraint>
</web-app>
【问题讨论】:
标签: java spring authentication spring-security