我使用的是Spring-Security-Rest,spring-security-core和spring-security-ui插件的Grails v2.4.2。自定义UserDetailsService不被调用 - Grails和Spring安全性核心
我写了一个自定义UserDetailsService使用户名不区分大小写。所有我做的只是试图覆盖
UserDetails loadUserByUsername(String username, boolean loadRoles) throws UsernameNotFoundException
我com.example.core.CaseInsensitiveUserDetailsService类定义为:
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
}
}
}
我resources.groovy包含:
beans = {
userDetailsService(com.example.core.CaseInsensitiveUserDetailsService)
credentialsExtractor(Grails24CredentialExtractor)
// Some Custom Filters Are Also Defined (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
您是否将其创建为插件,然后将其安装到应用程序中? – John
不,它只是一个类 –
你可以显示你的配置(对安全和日志记录部分感兴趣)以及请求和响应的输出吗? –