简体   繁体   English

Grails Spring Security Custom UserDetailsS​​ervice(电子邮件的目标代替用户名)

[英]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: 但是,我对以下几点感到困惑:

  1. 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%20UserDetailsS​​ervice.html但是我没有看到关于Grails文件夹放在哪里。

  2. 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.groovyuserLookup.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. 如果你查看GormUserDetailsS​​ervice的源代码,默认的userDetailsS​​ervice,你会看到它使用该属性进行查找。

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

相关问题 Grails Spring Security-自定义UserDetailsS​​ervice使authenticatedUser为空 - Grails Spring Security - custom UserDetailsService makes authenticatedUser null 自定义UserDetailsS​​ervice未被调用-Grails和Spring Security Core - Custom UserDetailsService Not Being Called - Grails & Spring Security Core Grails-用于用户名的Spring Security UI电子邮件 - Grails - Spring Security UI Email for Username 未加载Grails Spring bean(自定义UserDetailsS​​ervice) - Grails spring bean in not loaded (custom UserDetailsService) 使用电子邮件和用户名作为Grails中Spring安全插件的登录 - using email and username both as login in spring security plugin in Grails grails spring安全核心插件-使用用户名和电子邮件登录 - grails spring security core plugin - login with username and email 全球范围内使用Grails Spring Security用户名 - Grails Spring Security Username globally 如何从Grails中的Spring Security for Facebook身份验证中获取Facebook UserName,Email,phoneno等 - How to fetch Facebook UserName, Email, phoneno etc from Facebook Authentication for Spring Security in Grails Grails Spring 安全插件 - 用户名 escaping 问题 - Grails Spring Security Plugin - Username escaping problem Grails 3,登录后的Spring Security Rest用户名 - Grails 3, Spring Security Rest username after login
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM