我正在尝试在多租户Grails应用程序中进行身份验证。我已经完成了s2-quickstart,这是我的User类(名为MyUser):
class MyUser {
transient springSecurityService
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
Tenant tenant
static hasMany = [classes:FitnessClassSchedule]
static belongsTo = [Tenant,FitnessClassSchedule]
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: 'tenant'
password blank: false
classes nullable:true
}
static mapping = {
password column: '`password`'
}
Set<SecRole> getAuthorities() {
MyUserSecRole.findAllByMyUser(this).collect { it.secRole }
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
}
对于用户名的限制,它在租户中应该是唯一的意味着某事(&#34; username1&#34;,&#34; password1&#34;,&#34; tenant1&#34;)和(&# 34; username1&#34;,&#34; password1&#34;,&#34; tenant2&#34;)是可能的。因此,仅通过用户名和密码,我们无法识别身份验证用户(这就是为什么即使在bootstrap.groovy中初始化一些用户后我也无法登录)。因此,我们需要传递第三个参数作为识别用户的租户,而我似乎无法找到实现此目的的方法。
由于我在grails 2.3.7上使用spring-security-core:2.0-RC4,因此没有显式生成登录控制器,因此覆盖似乎很难。
那我该怎么办?是否可以在不覆盖控制器的情况下这样做?