Usuário não é encontrado no banco de dados Spring Security Core Grails
17/05/2015 20:45
package test2import grails.plugin.springsecurity.userdetails.GrailsUser
import org.springframework.security.core.GrantedAuthority
class UserDetails extends GrailsUser {
final String nome
final String sobrenome
UserDetails(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired,
boolean accountNonLocked, Collection authorities, Object id, String nome, String sobrenome) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities, id)
this.nome = nome
this.sobrenome = sobrenome
}
}
package test2import grails.plugin.springsecurity.SpringSecurityUtilsAinda tenho dentro do meu arquivo grails-app/conf/spring/resources.groovy a anotação do bean que é denotado a seguir:
import grails.plugin.springsecurity.userdetails.GrailsUserDetailsService
import org.springframework.dao.DataAccessException
import org.springframework.security.core.authority.GrantedAuthorityImpl
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.test2.security.User
class UserDetailsService implements GrailsUserDetailsService {
static final List NO_ROLES = [new GrantedAuthorityImpl(SpringSecurityUtils.NO_ROLE)]
@Override
UserDetails loadUserByUsername(String username, boolean loadRoles)
throws UsernameNotFoundException, DataAccessException {
return loadUserByUsername(username)
}
@Override
UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
User.withTransaction { status ->
User user = User.findByUsername(username)
if (!user) throw new UsernameNotFoundException(
'User not found', username)
def authorities = user.authorities.collect {
new GrantedAuthorityImpl(it.authority)
}
return new UserDetailsService(user.username, user.password, user.enabled,
!user.accountExpired, !user.passwordExpired,
!user.accountLocked, authorities ?: NO_ROLES, user.id,
nome, sobrenome)
}
}
}
beans = { userDetailsService(test2.UserDetailsService)
}
return new UserDetailsService(...O correto seria retornar um
return new test2.UserDetails(...No entanto mesmo assim o mesmo erro de usuário não encontrado persiste.
Para se registrar, clique aqui.