java - Grails Spring Security 密码尝试失败

标签 java grails spring-security pre-authentication

当 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/

相关文章:

git - Hudson构建因Git存储库和Grails失败

spring-security - Thymeleaf + Spring Security 表达语言

java - 将执行测试所需的时间附加到最终用户友好的 .xls/.csv 文件中

chalice 2.4.4 : services does not inject: integration test

grails - 如何在Grails上从.war检索源代码

java - 我什么时候应该在 Spring Boot 应用程序中覆盖 Spring Security 的 configure(AuthenticationManagerBuilder auth)?

grails - 在Grails Spring Security Core插件中设置 session 超时

Java 7 在 Win7 上创建路径为 230 个字符的文件失败

java - 为什么 Java 集合不提供方便的 map 方法?

java - Selendroid - 如何单击 ListView 中的项目?