org.keycloak.models.utils

## Class RoleUtils

- java.lang.Object
- - org.keycloak.models.utils.RoleUtils

-     public class RoleUtils
      extends Object

  Author:
    Stian Thorgersen

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RoleUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Set<RoleModel>` | `expandCompositeRoles(Set<RoleModel> roles)`
    `static Stream<RoleModel>` | `expandCompositeRolesStream(Stream<RoleModel> roles)`
    `static Set<RoleModel>` | `getDeepUserRoleMappings(UserModel user)`
    `static boolean` | `hasRole(Set<RoleModel> roles, RoleModel targetRole)`
    `static boolean` | `hasRole(Stream<RoleModel> roles, RoleModel targetRole)`
    `static boolean` | `hasRoleFromGroup(GroupModel group, RoleModel targetRole, boolean checkParentGroup)` Checks whether the `targetRole` is contained in the given group or its parents (if requested)
    `static boolean` | `hasRoleFromGroup(Iterable<GroupModel> groups, RoleModel targetRole, boolean checkParentGroup)` Deprecated. Use `hasRoleFromGroup(Stream, RoleModel, boolean)` hasRoleFromGroup(Stream, RoleModel, boolean)} instead.
    `static boolean` | `hasRoleFromGroup(Stream<GroupModel> groups, RoleModel targetRole, boolean checkParentGroup)` Checks whether the `targetRole` is contained in any of the `groups` or their parents (if requested)
    `static boolean` | `isClientRole(RoleModel r, ClientModel c)`
    `static boolean` | `isMember(Set<GroupModel> groups, GroupModel targetGroup)` Deprecated. Use `isMember(Stream, GroupModel)` isMember(Stream, GroupModel)} instead.
    `static boolean` | `isMember(Stream<GroupModel> groups, GroupModel targetGroup)`
    `static boolean` | `isRealmRole(RoleModel r)`
    `static boolean` | `isRealmRole(RoleModel r, RealmModel realm)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RoleUtils

          public RoleUtils()

  - ### Method Detail

    - #### isMember

          public static boolean isMember(Set<GroupModel> groups,
                                         GroupModel targetGroup)

      Deprecated. Use `isMember(Stream, GroupModel)` isMember(Stream, GroupModel)} instead.
      Parameters:
        `groups` -
        `targetGroup` -
      Returns:
        true if targetGroup is in groups (directly or indirectly via parent child relationship)

    - #### isMember

          public static boolean isMember(Stream<GroupModel> groups,
                                         GroupModel targetGroup)

      Parameters:
        `groups` -
        `targetGroup` -
      Returns:
        true if targetGroup is in groups (directly or indirectly via parent child relationship)

    - #### hasRole

          public static boolean hasRole(Set<RoleModel> roles,
                                        RoleModel targetRole)

      Parameters:
        `roles` -
        `targetRole` -
      Returns:
        true if targetRole is in roles (directly or indirectly via composite role)

    - #### hasRole

          public static boolean hasRole(Stream<RoleModel> roles,
                                        RoleModel targetRole)

      Parameters:
        `roles` -
        `targetRole` -
      Returns:
        true if targetRole is in roles (directly or indirectly via composite role)

    - #### hasRoleFromGroup

          public static boolean hasRoleFromGroup(GroupModel group,
                                                 RoleModel targetRole,
                                                 boolean checkParentGroup)

      Checks whether the `targetRole` is contained in the given group or its parents (if requested)
      Parameters:
        `group` - Group to check role for
        `targetRole` -
        `checkParentGroup` - When `true`, also parent group is recursively checked for role
      Returns:
        true if targetRole is in roles (directly or indirectly via composite role)

    - #### hasRoleFromGroup

          public static boolean hasRoleFromGroup(Iterable<GroupModel> groups,
                                                 RoleModel targetRole,
                                                 boolean checkParentGroup)

      Deprecated. Use `hasRoleFromGroup(Stream, RoleModel, boolean)` hasRoleFromGroup(Stream, RoleModel, boolean)} instead.
      Checks whether the `targetRole` is contained in any of the `groups` or their parents (if requested)
      Parameters:
        `groups` -
        `targetRole` -
        `checkParentGroup` - When `true`, also parent group is recursively checked for role
      Returns:
        true if targetRole is in roles (directly or indirectly via composite role)

    - #### hasRoleFromGroup

          public static boolean hasRoleFromGroup(Stream<GroupModel> groups,
                                                 RoleModel targetRole,
                                                 boolean checkParentGroup)

      Checks whether the `targetRole` is contained in any of the `groups` or their parents (if requested)
      Parameters:
        `groups` -
        `targetRole` -
        `checkParentGroup` - When `true`, also parent group is recursively checked for role
      Returns:
        true if targetRole is in roles (directly or indirectly via composite role)

    - #### expandCompositeRoles

          public static Set<RoleModel> expandCompositeRoles(Set<RoleModel> roles)

      Parameters:
        `roles` -
      Returns:
        new set with composite roles expanded

    - #### expandCompositeRolesStream

          public static Stream<RoleModel> expandCompositeRolesStream(Stream<RoleModel> roles)

      Parameters:
        `roles` -
      Returns:
        stream with composite roles expanded

    - #### getDeepUserRoleMappings

          public static Set<RoleModel> getDeepUserRoleMappings(UserModel user)

      Parameters:
        `user` -
      Returns:
        all user role mappings including all groups of user. Composite roles will be expanded

    - #### isRealmRole

          public static boolean isRealmRole(RoleModel r)

    - #### isRealmRole

          public static boolean isRealmRole(RoleModel r,
                                            RealmModel realm)

    - #### isClientRole

          public static boolean isClientRole(RoleModel r,
                                             ClientModel c)

Copyright © 2020 JBoss by Red Hat. All rights reserved.