After configuring Spring Security 3.2, _csrf.token
is not bound to a request or a session object.
This is the spring security config:
&l
I used to have the same problem.
Your config use security="none" so cannot generate _csrf:
<http pattern="/login.jsp" security="none"/>
you can set access="IS_AUTHENTICATED_ANONYMOUSLY" for page /login.jsp replace above config:
<http>
<intercept-url pattern="/login.jsp*" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/**" access="ROLE_USER"/>
<form-login login-page="/login.jsp"
authentication-failure-url="/login.jsp?error=1"
default-target-url="/index.jsp"/>
<logout/>
<csrf />
</http>
Shouldn't you add to the login form?;
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
As stated in the here in the Spring security documentation
Please see my working sample application on Github and compare with your set up.
In your controller add the following:
@RequestParam(value = "_csrf", required = false) String csrf
And on jsp page add
<form:form modelAttribute="someName" action="someURI?${_csrf.parameterName}=${_csrf.token}
Neither one of the solutions worked form me. The only one that worked for me in Spring form is:
action="./upload?${_csrf.parameterName}=${_csrf.token}"
REPLACED WITH:
action="./upload?_csrf=${_csrf.token}"
(Spring 5 with enabled csrf in java configuration)