当 LoginController 的操作 authfail 中身份验证失败时,是否有办法在 spring security core grails 插件中检索用户输入的密码?
def authfail = {
def msg = ''
// I can get the username as below
def username = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
// There is UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY but the value is null when access here as below
def attemptedPassword = session[UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY]
.
.
.
}
我需要能够在身份验证失败时知道输入的密码。
最佳答案
这是可能的,但您必须在提交登录表单之前将密码存储在 session 中。将自定义按钮添加到您的登录表单并隐藏提交按钮:
<form action="/j_spring_security_check">
...
<button onclick="javascript:store()" type="button">Login</button>
<input class="invisible" id="loginButton" type="submit">
</form>
您需要用 JavaScript 编写 store()
函数。以下是如何实现这一目标的示例:FIDDLE (借自 here )。显然,在此函数中,您必须包含表单提交(使用 jQuery): $('#loginButton').click()
身份验证失败后,您必须检索存储的密码。
关于java - Grails Spring Security 密码尝试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19873257/