[英]Grails Spring Security Custom UserDetailsService (goal of Email in place of Username)
I am using Grails Spring Security Plugin 1.2.7.3
and would like to have the User authenticate via Email Address and Password. 我正在使用
Grails Spring Security Plugin 1.2.7.3
并希望用户通过电子邮件地址和密码进行身份验证。 I would like Email Address to be the primary Login ID. 我希望电子邮件地址成为主要的登录ID。
I came across the following Nabble post regarding case insensitive usernames , where the original poster is attempting to do the same. 我遇到了关于不区分大小写的用户名的以下Nabble帖子 ,其中原始海报试图做同样的事情。 However, I was a bit confused on a few points:
但是,我对以下几点感到困惑:
I understand that I need to write my own implementation of UserDetailsService
and register it in grails-app/conf/spring/resources.groovy
. 我知道我需要编写自己的
UserDetailsService
实现并在grails-app/conf/spring/resources.groovy
。
However, I wasn't sure which folder the custom implementation of UserDetailsService
should go (best practices). 但是,我不确定
UserDetailsService
的自定义实现应该去哪个文件夹(最佳实践)。 My guesses are either /grails-app/services
, /grails-app/utils
, or /src/groovy
. 我的猜测是
/grails-app/services
, /grails-app/utils
,或/src/groovy
。 Has anyone done this before and where is the best place for the custom UserDetailsService
? 有没有人这样做过,哪里是自定义
UserDetailsService
的最佳位置?
I read this chapter in the Docs: http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/11%20Custom%20UserDetailsService.html but I didn't really see guidance on what Grails folder to put it in. 我在Docs中阅读了这一章: http : //grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/11%20Custom%20UserDetailsService.html但是我没有看到关于Grails文件夹放在哪里。
I created my User domain class via s2 command: 我通过s2命令创建了我的用户域类:
s2-quickstart com.philiptenn.security User Role Requestmap
If I were to rename the field User.username
to User.email
so that my code is clearer, will I be in for a world of hurt? 如果我要将
User.email
字段重命名为User.username
,以便我的代码更清晰,那么我是否会受到伤害?
I did a Find Usages on this field, and one stuck out in DefaultSecurityConfig.groovy : userLookup.usernamePropertyName = 'username'
我在这个字段上找了一个Find
userLookup.usernamePropertyName = 'username'
,并在DefaultSecurityConfig.groovy中找到了一个: userLookup.usernamePropertyName = 'username'
Could I just update this to read: DefaultSecurityConfig.groovy : userLookup.usernamePropertyName = 'email'
我可以将其更新为: DefaultSecurityConfig.groovy :
userLookup.usernamePropertyName = 'email'
Thank you. 谢谢。
As you pointed out, you can override the default security configs in your own Config.groovy
, the options all start with grails.plugins.springsecurity
, so it would be grails.plugins.springsecurity.userLookup.usernamePropertyName = 'email'
( docs ). 正如您所指出的,您可以在自己的
Config.groovy
覆盖默认安全配置,所有选项都以grails.plugins.springsecurity
,因此它将是grails.plugins.springsecurity.userLookup.usernamePropertyName = 'email'
( docs ) 。 That's the first thing I'd try. 这是我尝试的第一件事。 If you check out the source of the GormUserDetailsService , the default userDetailsService, you'll see it uses that property for the lookup.
如果你查看GormUserDetailsService的源代码,默认的userDetailsService,你会看到它使用该属性进行查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.