要将身份验证添加到 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/