【问题标题】:Grails - Spring Security UI Email for UsernameGrails - 用户名的 Spring Security UI 电子邮件
【发布时间】:2017-05-20 17:51:28
【问题描述】:

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

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

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

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

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

看来我一定错过了一些非常简单的东西。非常感谢任何帮助/指导。

【问题讨论】:

  • 检查用户域类中用户名属性的约束 - 如果 db 之前已经创建并且可以为空 false 并且您在之后更改为 true - 那么需要手动 db upate 将表更改列更改为可为空.您在没有任何实际代码或错误消息的情况下进行监督 - 任何人都可以为您提供任何有用的跟踪或任何东西
  • 感谢@vahid,我的问题不需要任何痕迹,因为我在询问如何使 spring-security-ui 中的注册功能使用电子邮件作为用户名。

标签: grails spring-security grails-plugin


【解决方案1】:

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

【讨论】:

  • 谢谢!正是我正在寻找的信息。
猜你喜欢
  • 2012-12-12
  • 2013-03-15
  • 2014-11-20
  • 2012-08-19
  • 2012-12-16
  • 2013-02-13
  • 2013-10-05
  • 2012-09-08
  • 1970-01-01
相关资源
最近更新 更多