简体   繁体   English

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

[英]Grails - Spring Security UI Email for Username

I'm using Grails 3.2.4 and am attempting to use the email property of my User class as the username for registration. 我正在使用Grails 3.2.4,并试图将User类的email属性用作注册的用户名。

So far, I've managed to get Spring Security Core to use the email as the username using the configuration setting below: 到目前为止,我已经设法使Spring Security Core使用以下配置设置将电子邮件用作用户名:

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

However, the registration functionality doesn't seem to take this into account and won't let me register a new user using only an email and password. 但是,注册功能似乎没有考虑到这一点,也不允许我仅使用电子邮件和密码注册新用户。

I've made a few attempts at overriding the RegisterController but I continue to experience different errors regarding null usernames. 我已经做了一些尝试来重写RegisterController的尝试,但是我仍然遇到有关空用户名的不同错误。

It seems like I must be missing something very simple. 看来我一定缺少一些非常简单的东西。 Any help / direction is greatly appreciated. 任何帮助/方向,我们将不胜感激。

It appears that in version spring-security-ui-3.0.0.M2 the username property might not be override-able. 看来在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 I'm getting around this now by doing something like this in my user domain class: PS我现在通过在用户域类中执行以下操作来解决此问题:

static transients = ["migrating"]]
String username = null

public void setEmail(String email) {
    this.email = email
    this.username = email
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM