title: grails spring security role and group
body: <p>I have configured my spring security to work with groups.</p>
  
  <p>I used this scipt to create the domain classes:</p>
  
  <pre><code>grails s2-quickstart com.yourapp User Role --groupClassName=RoleGroup
  </code></pre>
  
  <p>I assumed that a user can have many groups where a group can have many roles</p>
  
  <p>This is what a generated method looks like in the User class:</p>
  
  <pre><code>Set&lt;RoleGroup&gt; getAuthorities() {
      UserRoleGroup.findAllByUser(this).collect { it.roleGroup }
  }
  </code></pre>
  
  <p>But now I seen that the script also created a class called UserRole which is the association between User and Role. So a User can ALSO have many Roles directly?</p>
  
  <p>I tried it and it is saved in the database. I modified the method like this:</p>
  
  <pre><code>def getAuthorities() {
      def authorities = UserRoleGroup.findAllByUser(this).collect { it.roleGroup }
  
      authorities.addAll(UserRole.findAllByUser(this).collect { it.role })
      return authorities
  }
  </code></pre>
  
  <p>Now, when I create a entry in the database in the User &lt;--> Role association. I cannot login anymore. I get the default message by spring security basically saying that no credentials have been found.</p>
  
  <p>When I delete the entry manually, I can login again. I think this is because the method is then only returning RoleGroup objects.</p>
  
  <p>My questions are:</p>
  
  <p>a) can I also assign roles directly when I have configured Groups</p>
  
  <p>b) if no, why is the script creating this class</p>
  
  <p>c) if yes, how do I do that?</p>