Grails-用户名的Spring Security UI电子邮件



我正在使用Grails 3.2.4,并试图使用User类的电子邮件属性作为注册用户名。

到目前为止,我已经设法让Spring Security Core使用以下配置设置将电子邮件用作用户名:

grails.plugin.springsecurity.userLookup.usernamePropertyName='email'

然而,注册功能似乎没有考虑到这一点,也不允许我只使用电子邮件和密码注册新用户。

我已经尝试过几次覆盖RegisterController,但我仍然会遇到关于null用户名的不同错误。

我好像错过了一些很简单的东西。非常感谢任何帮助/指导。

spring-security-ui-3.0.0.M2版本中,username属性可能无法重写。

String paramNameToPropertyName(String paramName, String controllerName) {
// Properties in the ACL classes and RegistrationCode aren't currently
// configurable, and the PersistentLogin class is generated but its
// properties also aren't configurable. Since this method is only by
// the controllers to be able to hard-code param names and lookup the
// actual domain class property name we can short-circuit the logic here.
// Additionally there's no need to support nested properties (e.g.
// 'aclClass.className' for AclObjectIdentity search) since those are
// not used in GSP for classes with configurable properties.
if (!paramName) {
return paramName
}
Class<?> clazz = domainClassesByControllerName[controllerName]
String name
if (clazz) {
String key = paramName
if (paramName.endsWith('.id')) {
key = paramName[0..-4]
}
name = classMappings[clazz][key]
}
name ?: paramName
}

PS我现在通过在我的用户域类中做这样的事情来解决这个问题

static transients = ["migrating"]]
String username = null
public void setEmail(String email) {
this.email = email
this.username = email
}

最新更新