您错过了允许匿名访问您的登录页面,否则您的登录页面将被禁止访问。请尝试以下方式 的 似乎你的login-processing-url =“/ j_spring_security_check” 强> ,尝试将其更改为“/ login”,否则添加如下所示的url模式以允许匿名访问该URL
<http auto-config="true"> <intercept-url pattern="/login" access="isAnonymous()" /> <intercept-url pattern="/j_spring_security_check" access="isAnonymous()" />
更新: 像这样修复你的web.xml
Context-param应该初始化除了MVC之外的所有bean,因为你有dispatcher-servlet,否则你将在两个不同的上下文中加载重复的bean。
<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/application-context-webservice.xml, /WEB-INF/applicationContext.xml, /WEB-INF/spring-security.xml </param-value> </context-param>
Dispatcher应该处理与MVC相关的配置。
<servlet-name>TemptingPlacesMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/TemptingPlacesMvc-servlet.xml </param-value> </init-param> <load-on-startup>1</load-on-startup>
安全过滤器不需要安全配置,因为它们将在上下文之前初始化
<filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter>
解决这个问题
Error creating bean with name 'org.springframework.security.filterChainProxy': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.security.web.access.expression.WebSecurityExpressionRoot.set??DefaultRolePrefix(Ljava/lang/String;)
如果您使用maven pom.xml add,请尝试在项目中包含spring-security-core
<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>3.2.3.RELEASE</version> </dependency>
解决这个问题 在请求参数'_csrf'或标题'X-CSRF-TOKEN'上找到无效的CSRF令牌'null'
您已启用csrf,因此每个POST请求都需要csrf令牌。 所以要么禁用
<csrf disabled="true"/>
或者在您发出的每个POST请求中提供令牌,如下所示
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> <form action="${loginUrl}" method="POST"> <sec:csrfInput />
要么
<form action="${logoutUrl}" method="post"> <input type="submit" value="Log out" /> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> </form>