我使用 Grails + spring-security + LDAP 来验证用户。身份验证现在有效,但我需要纯文本密码来验证第二个服务。
我尝试了 SpringSecurityService 属性,但没有一个包含密码。
我必须实现自己的 UserDetailsMapper 还是 LdapUserDetailsMapper 也提供从 Web 表单检索到的纯文本密码的映射?
最佳答案
您可以从 org.springframework.security.core.context.SecurityContextHolder
获取凭据。但是,我真的不认为使用它是个好主意。您将无法使用“记住我”、“运行方式”或“切换用户”功能,因为凭据不会包含当前用户的密码(它们可能为空)。此外,我认为如果使用基本 HTML 身份验证或表单例份验证以外的任何其他方式,您将无法获得明文密码。
无论如何,如果使用表单例份验证,SecurityContextHolder.getContext().getAuthentication().getCredentials()
将为您提供明文密码。
关于grails - 如何从 spring-security 获取明文密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5088319/