| [[authorityGroupClass]] |
| === Group Class |
| |
| The plugin provides you the option of creating an access inheritance level between "`person`" and "`authority`": the "`group`". The next three classes you will read about (including this one) are only used in a "`person`"/"`group`"/"`authority`" implementation. Rather than granting authorities directly to a "`person`", you can create a "`group`", map authorities to it, and then map a "`person`" to that "`group`". For applications that have a one or more groups of users who need the same level of access, having one or more "`group`" instances makes managing changes to access levels easier because the authorities that make up that access level are encapsulated in the "`group`", and a single change will affect all of the users. |
| |
| If you run the <<s2-quickstart>> script with the group name specified and use `com.mycompany.myapp` as your package and `RoleGroup` and `Role` as your class names, you'll generate this class: |
| |
| [source, groovy] |
| .`RoleGroup.groovy` |
| ---- |
| include::../code/s2-quickstart-rolegroup/grails-app/domain/com/mycompany/myapp/RoleGroup.groovy[] |
| ---- |
| |
| When running the <<s2-quickstart>> script with the group name specified, the "`person`" class will be generated differently to accommodate the use of groups. Assuming you use `com.mycompany.myapp` as your package and `User` and `RoleGroup` as your class names, the `getAuthorities()` method will be generated like so: |
| |
| [source,groovy] |
| .Listing {counter:listing}. The generated `getAuthorities()` method when using role groups |
| ---- |
| include::../code/s2-quickstart-rolegroup/grails-app/domain/com/mycompany/myapp/User.groovy[tag=getAuthorities, indent=0] |
| ---- |
| |
| The plugin assumes the attribute `authorities` will provide the "`authority`" collection for each class, but you can change the property names in `grails-app/conf/application.groovy`. You also must ensure that the property `useRoleGroups` is set to `true` in order for `GormUserDetailsService` to properly retrieve the `authorities`. |
| |
| .RoleGroup configuration options |
| [cols="30,30,40"] |
| |==================== |
| | *Property* | *Default Value* | *Meaning* |
| |
| |useRoleGroups |
| |`false` |
| |Whether to use "`authority group`" implementation when loading user authorities |
| |
| |authority.groupAuthorityNameField |
| |_none_ (the <<s2-quickstart>> script uses the name "`authorities`") |
| |RoleGroup class role collection property |
| |==================== |