grails 3.3 spring security 加密密码的前插入在哪里?

标签 grails spring-security

要将身份验证添加到 grails 3 应用程序,请将其添加到 build.gradle:

compile 'org.grails.plugins:spring-security-core:3.2.3'

然后运行
 grails s2-quickstart com.myapp Operator Role

这会创建 3 个域对象,但我找不到其他任何东西。

Operator 域对象如下所示:
package com.myapp

importgroovy.transform.EqualsAndHashCode
importgroovy.transform.ToString
importgrails.compiler.GrailsCompileStatic

@GrailsCompileStatic
@EqualsAndHashCode(includes='username')
@ToString(includes='username',includeNames=true,includePackage=false)
classOperatorimplementsSerializable{

privatestaticfinallongserialVersionUID=1

Stringusername
Stringpassword
booleanenabled=true
booleanaccountExpired
booleanaccountLocked
booleanpasswordExpired

Set<Role>getAuthorities(){
(OperatorRole.findAllByOperator(this)asList<OperatorRole>)*.roleasSet<Role>
}

staticconstraints={
passwordnullable:false,blank:false,password:true
usernamenullable:false,blank:false,unique:true
}

staticmapping={
passwordcolumn:'
`password`'
}
}

问题是,缺少前插入来加密密码。在 grails 2.5 中,它曾经将其放入 Operator 域对象中:
    def beforeInsert() {
            encodePassword()
    }

所以我希望密码以纯文本形式插入,但似乎并非如此。它似乎是加密的,至少对于使用 bootstrap 创建的 Operators 问题是在哪里以及如何?

最佳答案

允许域类进行 Autowiring 并将 bean 注入(inject)到域类的每个实例中的旧方法会消耗相当多的内存。更高版本的 Grails (3.3.x) 选择 PreInsertEvent监听器对密码进行编码。这在获得相同结果的同时节省了相当多的内存。请参阅 s2quicktstart 的文档和类(class) UserPasswordEncoderListener这是在您的应用程序中创建的。

https://grails-plugins.github.io/grails-spring-security-core/latest/index.html#tutorials

关于grails 3.3 spring security 加密密码的前插入在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54410328/

相关文章:

spring - 在使用 Spring 进行集成测试期间模拟外部服务器

spring - 使用 Spring-security @PreAuthorize 注释和 OAuth2 保护 REST API

database - 使用 executeUpdate() 进行 Grails 悲观锁定

grails - grails 中的 jasper 报告

java - 如何使用 MongoDB 实现 ReactiveUserDetailsS​​ervice

spring-mvc - 如何使用 spring mvc 在拦截器中获取主体?

ajax - 断开Grails中的 Atmosphere socket

grails - 用户域 “enabled”字段设置为false时,使用Grails Acegi插件。用户仍然可以登录

grails - grails test-app个人集成测试

java - LDAP 支持 BCrypt 吗?尝试在 Java Spring Security 中实现 BCrypt