【问题标题】:How can I get plaintext password from spring-security?如何从 spring-security 获取明文密码?
【发布时间】:2011-07-02 13:53:55
【问题描述】:

我使用 Grails + spring-security + LDAP 来验证用户。身份验证现在有效,但我需要纯文本密码来验证第二个服务。

我尝试了 SpringSecurityService 属性,但没有一个包含密码。

我必须实现自己的 UserDetailsMapper 还是 LdapUserDetailsMapper 还提供从 Web 表单检索的纯文本密码的映射?

【问题讨论】:

    标签: grails spring-security spring-ldap


    【解决方案1】:

    您可以从org.springframework.security.core.context.SecurityContextHolder 获取凭据。但是,我真的不认为使用它是一个好主意。您将无法使用“记住我”或“运行身份”或“切换用户”功能,因为凭据不包含当前用户的密码(它们可能为空)。另外,如果使用基本 HTML 身份验证或表单身份验证以外的任何其他方法,我认为您不会获得明文密码。

    无论如何,如果使用表单身份验证,SecurityContextHolder.getContext().getAuthentication().getCredentials() 会为您获取明文密码。

    【讨论】:

    • 弹簧安全有一个erase-credentials 设置。将其设置为 false 可能有助于找回密码。但是,我不知道此设置的去向。我正在寻找设置设置的位置并找到了这篇文章。
    • 找到了。尝试添加到 Config.groovy:grails.plugin.springsecurity.providerManager.eraseCredentialsAfterAuthentication = false
    猜你喜欢
    • 2015-10-01
    • 2017-04-04
    • 2013-08-12
    • 2023-04-05
    • 2023-03-30
    • 1970-01-01
    • 2014-02-14
    • 2014-07-29
    • 1970-01-01
    相关资源
    最近更新 更多