After migrating to Spring Security 3.2.0 and setting up xml, the _csrf token does not work.
The basics:
- Spring 4.0.1
- Spring Security 3.2.0.
- Freemarker Template Language
Step 1 - Spring Security xml configuration:
<sec:http>
<sec:csrf token-repository-ref="csrfTokenRepository" />
</sec:http>
<bean id="csrfTokenRepository" class="org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository">
<property name="headerName" value="X-SECURITY" />
</bean>
Step 2 - freemarker template:
<form accept-charset="UTF-8" action="/portal" method="POST" name="formAddItemToCart">
<input type="hidden"
name="${_csrf.parameterName}"
value="${_csrf.token}"/>
</form>
Step 3 - the displayed output:
<form accept-charset="UTF-8" action="/portal" method="POST" name="formAddItemToCart">
<input type="hidden" name="" value=""/>
</form>
Step 4 - freemarker template error:
FreeMarker template error:
The following has evaluated to null or missing:
==> _csrf [in template "cart.ftl" at line 28, column 21]
Link:
http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#csrf
I am currently debugging the entire application.
I don’t know where exactly the problem is, but csrf does not seem to work with freemarker. Is it even possible to include the csrf token in the freemarker template? Do you have any suggestions or solutions?