简体   繁体   English

使用用户名作为电子邮件,Spring Security UI插件

[英]Use username as email, Spring Security UI plugin

I'm using the Spring Security plugin, in combination with the Spring Security UI plugin. 我将Spring Security插件与Spring Security UI插件结合使用。

They both work like a charm, but my problem is that I don't want my user to have a username, instead he/she should use the e-mail as username. 它们都像超级按钮一样工作,但是我的问题是我不希望用户拥有用户名,而是他/她应使用电子邮件作为用户名。

So in the register-phase I tried removing the username from the registration-page and setting 所以在注册阶段,我尝试从注册页面中删除用户名并进行设置

newUser.username = params.email

So that the plugins still can access the variable username, but this gave me validation errors and I just can't figure out a way to solve it. 这样,插件仍然可以访问变量用户名,但这给了我验证错误,而我却想不出解决方法。

Any ideas? 有任何想法吗? Has anyone done anything similar? 有人做过类似的事情吗?

You can modify the default User field that spring security uses 您可以修改Spring Security使用的默认用户字段

In your Config.groovy add the following 在您的Config.groovy中添加以下内容

grails.plugins.springsecurity.userLookup.usernamePropertyName = 'XXX' grails.plugins.springsecurity.userLookup.usernamePropertyName ='XXX'

where XXX is the field of the User entity to be used 其中XXX是要使用的用户实体的字段

You can check the configuration attributes here 您可以在此处检查配置属性

I have recently done this by copying views and controllers from spring security plugin to my grails-app and updated view to display emailAddress as oppose to username. 我最近通过将视图和控制器从Spring Security插件复制到我的grails-app并更新了视图以将emailAddress显示为反对用户名来完成此操作。 I also replaced username property with emailAddress in User domain class. 我还用User域类中的emailAddress替换了username属性。 Make sure you update the constrains as follows: 确保按照以下方式更新约束:

static constraints = {
    emailAddress email: true, blank: false, unique: true
    password blank: false, password: true
}

What dimcookies suggest is correct and works for old version of Grails, the new syntax configuration, at least for Grails 2.3.1, is: dimcookies的建议是正确的,并且适用于旧版本的Grails,新的语法配置(至少适用于Grails 2.3.1)是:

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

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

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