几天来,我一直在尝试实施 Spring Security,并且一直在努力解决csrf tokens
.
我已经调试CsrfRequestDataValueProcessor
并发现以下行返回null。
CsrfToken token = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
使用 Thymeleaf 我有以下形式:
<form th:action="@{/j_spring_security_check}" method="post">
<label for="j_username">Username</label>:
<input type="text" id="j_username" name="j_username" /> <br />
<label for="j_password">Password</label>:
<input type="password" id="j_password" name="j_password" /> <br />
<input type="submit" value="Log in" />
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
</form>
它不渲染并引发以下异常:
请求处理失败;嵌套异常是 org.thymeleaf.exceptions.TemplateProcessingException:异常评估 SpringEL 表达式:“_csrf.parameterName”(loginsample:19)] 根本原因 org.springframework.expression.spel.SpelEvaluationException:EL1007E:(pos 0):属性或字段在 null 上找不到“参数名称”
为什么会这样?