自定义UserDetailsService未被调用 - Grails& Spring Security Core [英] Custom UserDetailsService Not Being Called - Grails & Spring Security Core
问题描述
我使用的是Spring-Security-Rest,spring-security-core和spring-security-ui插件的Grails v2.4.2。
编写一个自定义的UserDetailsService以使用户名不区分大小写。我所做的只是试图覆盖
UserDetails loadUserByUsername(String username,boolean loadRoles)throws UsernameNotFoundException
code>
我的 com.example.core.CaseInsensitiveUserDetailsService 类定义为:
class CaseInsensitiveUserDetailsService extends GormUserDetailsService {
$ b $ / **
*使用户名不区分大小写
* /
UserDetails loadUserByUsername(String username,boolean loadRoles)抛出UsernameNotFoundException {
Person.withTransaction {status - >
log.debug不区分大小写的用户详细信息服务
//查找用户名
def user = Person.findByUsernameIlike(用户名)
//如果找不到用户,抛出异常
if(!user){
log.warn未找到用户:$ username
抛出新的UsernameNotFoundException('未找到用户',用户名)
}
集合<授权授权> authority = loadAuthorities(user,username,loadRoles)
createUserDetails user,authorities
}
}
}
我的 resources.groovy 包含:
beans = {
userDetailsService(com.example.core.CaseInsensitiveUserDetailsService)
credentialsExtractor(Grails24CredentialExtractor)
//定义了一些自定义过滤器(securityContextRepository ,securityContextPersistenceFilter,multipartResolver)
}
它成功编译,但它永远不会实际上运行了我的自定义 CaseInsensitiveUserDetailsService 。在控制台中,我从实际的GormUserDetailsService中看到调试语句,而不是我自定义的调试语句。可以做些什么来使用我的自定义UserDetailsService?
** 注意:我一直在关注这两个教程:
- http://www.stevideter.com/2012/11/17/case-insensitive-usernames-using-spring-security-core-plugin-for-grails /
- http://grails-plugins.github.io/grails-spring-security-core/guide/userDetailsService.html
它认为:
- 身份验证提供程序
- 自定义UserDetailsService
请注意,它是在grails之上3.2.5 p>
I'm using Grails v2.4.2 with spring-security-rest, spring-security-core, and spring-security-ui plugins.
I've written a custom UserDetailsService to make the username case-insensitive. All I am doing is simply trying to override
UserDetails loadUserByUsername(String username, boolean loadRoles) throws UsernameNotFoundException
My com.example.core.CaseInsensitiveUserDetailsService class is defined as:
class CaseInsensitiveUserDetailsService extends GormUserDetailsService {
/**
* Make The Username Case Insensitive
*/
UserDetails loadUserByUsername(String username, boolean loadRoles) throws UsernameNotFoundException {
Person.withTransaction { status ->
log.debug "Case Insensitive User Details Service"
// Find The Username
def user = Person.findByUsernameIlike(username)
// If User Not Found, Throw Exception
if (!user) {
log.warn "User not found: $username"
throw new UsernameNotFoundException('User not found', username)
}
Collection<GrantedAuthority> authorities = loadAuthorities(user, username, loadRoles)
createUserDetails user, authorities
}
}
}
My resources.groovy contains:
beans = {
userDetailsService(com.example.core.CaseInsensitiveUserDetailsService)
credentialsExtractor(Grails24CredentialExtractor)
// Some Custom Filters Are Also Defined (securityContextRepository, securityContextPersistenceFilter, multipartResolver)
}
It compiles succesfully, but it never actually runs my custom CaseInsensitiveUserDetailsService. In the console, I see debug statements from the actual GormUserDetailsService instead of my custom one. What can be done to use my custom UserDetailsService?
** Note: I've been following these two tutorials:
- http://www.stevideter.com/2012/11/17/case-insensitive-usernames-using-spring-security-core-plugin-for-grails/
- http://grails-plugins.github.io/grails-spring-security-core/guide/userDetailsService.html
I wrote this example for educational(self) purposes, perhaps it might help: https://github.com/grails-coder/grails-spring-security
It regards to:
- Authentication Providers
- Custom UserDetailsService
Kindly notice it's on top of grails 3.2.5
这篇关于自定义UserDetailsService未被调用 - Grails& Spring Security Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!