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

时间:2017-01-06 01:51:58

标签: grails spring-security grails-plugin

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

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

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

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

我已经尝试覆盖RegisterController,但我仍然遇到有关空用户名的不同错误。

似乎我必须遗漏一些非常简单的东西。非常感谢任何帮助/方向。

1 个答案:

答案 0 :(得分:2)

似乎在版本 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
}