我一直在試圖實現Spring Security幾天,並一直在努力與csrf tokens
。Spring Security生成空的CSRF令牌 - 無法找到屬性或字段'parameterName'null
我已調試到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):屬性或字段'parameterName'無法找到null
爲什麼這可能是?
你使用彈簧安全4? – smoggers
你如何生成csrf標記? – kTT