Vote count:
0
I made a custom UserDetailsService that makes the username in a login case insensitive, and it's working, however, all controllers (which were working previously) are now returning null for authenticatedUser.
Right before requesting authenticatedUser, isLoggedIn() returns true and getPrincipal() returns the logged in user.
Any ideas on why everything seems to be working but the authenticatedUser is null? Here's the custom UserDetailsService:
package com.mydomain
import grails.plugin.springsecurity.SpringSecurityUtils
import org.springframework.security.core.authority.GrantedAuthorityImpl
import grails.plugin.springsecurity.userdetails.GrailsUser
import grails.plugin.springsecurity.userdetails.GrailsUserDetailsService
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UsernameNotFoundException
class CaseInsensitiveUserDetailsService implements GrailsUserDetailsService {
static final List NO_ROLES = [new GrantedAuthorityImpl(SpringSecurityUtils.NO_ROLE)]
UserDetails loadUserByUsername(String username, boolean hasRoles) throws UsernameNotFoundException {
return loadUserByUsername(username)
}
UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Person.withTransaction { status ->
Person user = Person.findByEmailIlike(username)
if(!user) throw new UsernameNotFoundException('User not found', username)
def authorities = user.authorities.collect {
new GrantedAuthorityImpl(it.authority)
}
new GrailsUser(user.username, user.password, user.enabled, !user.accountExpired, !user.passwordExpired, !user.accountLocked, authorities, user.id)
}
}
}
asked 2 mins ago
Grails Spring Security - custom UserDetailsService makes authenticatedUser null
Aucun commentaire:
Enregistrer un commentaire