title: Grails Spring Security core - Custom user information?
body: <p>I'm using spring security core for authentication in my web app, but I can't figure out how to get a custom information from my User class
  here's my user class:</p>
  
  <pre><code>package core
  
  import beans.Colaborador
  import groovy.transform.EqualsAndHashCode
  import groovy.transform.ToString
  
  @EqualsAndHashCode(includes = 'username')
  @ToString(includes = 'username', includeNames = true, includePackage = false)
  class Usuario implements Serializable {
  
      private static final long serialVersionUID = 1
  
      transient springSecurityService
      String username
      String password
      boolean enabled = true
      boolean accountExpired
      boolean accountLocked
      boolean passwordExpired
      Colaborador colaborador
  
      Usuario(String username, String password) {
          this()
          this.username = username
          this.password = password
      }
  
      Set&lt;Permissao&gt; getAuthorities() {
          UsuarioPermissao.findAllByUsuario(this)*.permissao
      }
  
      def beforeInsert() {
          encodePassword()
      }
  
      def beforeUpdate() {
          if (isDirty('password')) {
              encodePassword()
          }
      }
  
      protected void encodePassword() {
          password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
      }
  
      static transients = ['springSecurityService']
  
      static constraints = {
          username blank: false, unique: true
          password blank: false
          colaborador nullable: true
      }
  
      static mapping = {
          password column: '`password`'
      }
  }
  </code></pre>
  
  <p>The information I want to use is inside Colaborador object, but if I try to access it by using <strong>sec:loggedInUserInfo</strong> and had no success, I've read that I need to create a Custom UserDetailsService, but I couldn't find out how and where to create it, can someone give me a hand?</p>
  
  <p>Thanks!</p>
  
  <p>@Edit</p>
  
  <p>I tried following the documentation and I create two classes</p>
  
  <pre><code>import beans.Colaborador
  import grails.plugin.springsecurity.userdetails.GrailsUser
  import org.springframework.security.core.GrantedAuthority
  
  class MyUserDetails extends GrailsUser {
  
      final Colaborador colaborador
  
      MyUserDetails(String username, String password, boolean enabled,
                    boolean accountNonExpired, boolean credentialsNonExpired,
                    boolean accountNonLocked,
                    Collection&lt;GrantedAuthority&gt; authorities,
                    long id, Colaborador colaborador) {
          super(username, password, enabled, accountNonExpired,
                  credentialsNonExpired, accountNonLocked, authorities, id)
          this.colaborador = colaborador
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>package core    
  import grails.plugin.springsecurity.SpringSecurityUtils
  import grails.plugin.springsecurity.userdetails.GrailsUserDetailsService
  import grails.plugin.springsecurity.userdetails.NoStackUsernameNotFoundException
  import grails.transaction.Transactional
  import org.springframework.security.core.authority.SimpleGrantedAuthority
  import org.springframework.security.core.userdetails.UserDetails
  import org.springframework.security.core.userdetails.UsernameNotFoundException
  
  class MyUserDetailsService implements GrailsUserDetailsService {
      static final List NO_ROLES = [new SimpleGrantedAuthority(SpringSecurityUtils.NO_ROLE)]
  
      UserDetails loadUserByUsername(String username, boolean loadRoles)
              throws UsernameNotFoundException {
          return loadUserByUsername(username)
      }
  
      @Transactional(readOnly = true, noRollbackFor = [IllegalArgumentException, UsernameNotFoundException])
      UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
  
          Usuario user = Usuario.findByUsername(username)
          if (!user) throw new NoStackUsernameNotFoundException()
          def roles = user.authorities
          def authorities = roles.collect {
              new SimpleGrantedAuthority(it.authority)
          }
  
          return new MyUserDetails(user.username, user.password, user.enabled,
                  !user.accountExpired, !user.passwordExpired,
                  !user.accountLocked, authorities ?: NO_ROLES, user.id,
                  user.colaborador)
      }
  }
  </code></pre>
  
  <p>and when I login in my app I get this error:</p>
  
  <pre><code>2016-11-14 11:56:46,061 [http-bio-80-exec-4] ERROR authentication.GrailsUsernamePasswordAuthenticationFilter  - An internal error occurred while trying to authenticate the user.
  Message: Could not find matching constructor for: java.lang.Object(java.lang.String, java.lang.String, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, java.util.ArrayList, java.lang.Long)
  </code></pre>