繁体   English   中英

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

[英]Grails - Spring Security UI Email for Username

我正在使用Grails 3.2.4,并试图将User类的email属性用作注册的用户名。

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

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

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

我已经做了一些尝试来重写RegisterController的尝试,但是我仍然遇到有关空用户名的不同错误。

看来我一定缺少一些非常简单的东西。 任何帮助/方向,我们将不胜感激。

看来在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
}

暂无
暂无

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

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