提交表单时出现InvalidCsrfTokenException

时间:2015-06-29 20:22:04

标签: spring jsp spring-security csrf

我正在使用基于Spring的Web应用程序(版本4.1.6.RELEASE,spring security 4.0.0.RELEASE),我在提交表单(POST方法)后收到错误<form:form>。根据{{​​3}}“Spring Security自动为您使用的任何<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" 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-4.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd"> <http use-expressions="true" disable-url-rewriting="true"> <headers> <frame-options/> <xss-protection/> <hsts/> </headers> <csrf/> <intercept-url pattern="/welcome" access="isAuthenticated()" /> <!-- some others urls to intercept --> <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed" /> <logout logout-success-url="/logout" /> <session-management> <concurrency-control max-sessions="1" expired-url="/login" /> </session-management> </http> 标签插入CSRF表单字段”,那么为什么我会收到此异常?
提前致谢。
这是我的spring安全配置:

<form:form action="myaction" method="post" enctype="multipart/form-data" id="formId" modelAttribute="myBean">
</form:form>


这是我的表单的定义(不包括它包含的字段):

with t as (
    select cust_id, event_datetime,
           (24 * (event_datetime -
                  coalesce(min(event_datetime) over (partition by cust_id ), 0)
           ) as difference
    from tbl
   )
select t.*
from (select t.*, 
             row_number() over (partition by cust_id, floor(difference / 12)
                                order by difference) as seqnum
      from t
     ) t
where seqnum = 1;

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:2)

由于您使用的是多部分表单,因此出现此问题。请在此处查看接受的答案:

Spring CSRF token does not work, when the request to be sent is a multipart request