0

当 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]
.
.
.
}

我需要能够知道身份验证失败时输入的密码。

4

1 回答 1

1

这是可能的,但您必须在提交登录表单之前将密码存储在会话中。将自定义按钮添加到您的登录表单并隐藏提交按钮:

<form action="/j_spring_security_check">
   ...
   <button onclick="javascript:store()" type="button">Login</button>
   <input class="invisible" id="loginButton" type="submit">
</form>

您需要store()在 javascript 中编写函数。这是一个如何实现的示例:FIDDLE (从这里借来的)。显然,在这个函数中,你必须附上表单提交(使用 jQuery):$('#loginButton').click()

身份验证失败后,您必须检索存储的密码。

于 2013-11-09T10:02:24.183 回答