2010-06-19 9 views

Répondre

2

Il n'y a pas de soutien pour cela, mais il est assez facile de créer un UserDetailsService personnalisé, voir http://www.grails.org/AcegiSecurity+Plugin+-+Custom+UserDetailsService

Quelque chose comme cela devrait fonctionner:

package com.yourcompany.yourapp 

import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserImpl 

import org.springframework.security.GrantedAuthority 
import org.springframework.security.GrantedAuthorityImpl 
import org.springframework.security.userdetails.UserDetails 
import org.springframework.security.userdetails.UserDetailsService 
import org.springframework.security.userdetails.UsernameNotFoundException 

class MyUserDetailsService implements UserDetailsService { 

    UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 
     def userDetails 

     User.withTransaction { status -> 
     def users = User.executeQuery(
      'from User where lower(username) = :username', 
      [username: username.toLowerCase()]) 
     if (users.size() == 1) { 
      def user = users[0] 
      GrantedAuthority[] authorities = user.authorities.collect { 
       new GrantedAuthorityImpl(it.authority) } 

      userDetails = new GrailsUserImpl(
        user.username, user.password, user.enabled, 
        true, true, true, authorities, user) 
     } 
     } 

     if (!userDetails) { 
     throw new UsernameNotFoundException('User not found', username) 
     } 

     userDetails 
    } 
}