spring - 如何在Grails中从Spring Security获取普通密码或解密密码?

标签 spring security grails spring-security

我在Grails应用程序中使用 Spring Security插件。保存密码时,密码在数据库中为加密格式。我想给它发送普通密码。如何获得?

另一个Android应用程序使用了我的API。从我的API,我需要发送特定的用户密码。

最佳答案

如果您正在从db:读取密码,则将密码保存到数据库时,它们是hashed而不是encryptedthe process involved in hashing is not reversible,因此简单的答案是:不,您不能。

您可以在将密码保存到数据库时使用加密(以便在遇到特殊情况(例如您的情况)时可以解密密码),但这不是一个好主意that is why hashing functions are preferred to encryption algorithm for saving passwords

但是,如果您确实需要这样做并且知道如何处理风险,则可以拦截对user.save()的调用,特别是拦截对密码进行编码的beforeInsert()beforeUpdate()方法。

因此,用户的beforeInsert()beforeUpdate()方法将如下所示:

beforeInsert(){

    ...
    yourApiService.sendPassword(password)
    ...
    password = securityService.encodePassword(password)
    ...

}


beforeUpdate(){

    ...
    if(isDirty('password')){

        yourApiService.sendPassword(password)
        ...
        password = securityService.encodePassword(password)

    }
    ...

}

关于spring - 如何在Grails中从Spring Security获取普通密码或解密密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31383043/

相关文章:

java - HIbernate InvalidDataAccessApiUsageException - 只读模式

Spring Boot 无法读取 Docker 中的 application.properties

php - 将 cakephp 的 Auth 组件与加盐密码哈希一起使用

windows - 如何识别Windows 10中的内核进程(以保护环0运行的进程)?

grails - Grails字段插件-自定义集合显示成员作为链接

grails - 如何在Grails 4中的创建和编辑表单中添加多个枚举字段?

java - Springs CustomDateEditor 引诱犯错误?

java - Spring MVC 3.0 : how do I define an interceptor with annotations?

php - 在加密的 SSL 连接上使用 HTTP POST 发送信用卡信息是否足够安全?

java - 我可以轻松地将 EJB3 Remote 与 RAD 框架结合使用吗?