org.keycloak.models

## Interface GroupProvider

- All Superinterfaces:
    GroupLookupProvider, Provider
  All Known Subinterfaces:
    CacheRealmProvider, RealmProvider
  All Known Implementing Classes:
    GroupStorageManager, JpaRealmProvider, MapGroupProvider, RealmCacheSession

      public interface GroupProvider
      extends Provider, GroupLookupProvider

  Provider of group records
  Author:
    mhajas

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTopLevelGroup(RealmModel realm, GroupModel subGroup)` Removes parent group for the given group in the given realm.
    `default GroupModel` | `createGroup(RealmModel realm, String name)` Creates a new group with the given name in the given realm.
    `default GroupModel` | `createGroup(RealmModel realm, String name, GroupModel toParent)` Creates a new group with the given name and parent to the given realm.
    `default GroupModel` | `createGroup(RealmModel realm, String id, String name)` Creates a new group with the given id and name in the given realm.
    `GroupModel` | `createGroup(RealmModel realm, String id, String name, GroupModel toParent)` Creates a new group with the given name, id, name and parent to the given realm.
    `default GroupModel` | `getGroupById(String id, RealmModel realm)` Deprecated. Use method `getGroupById(realm, id)`
    `default List<GroupModel>` | `getGroups(RealmModel realm)` Deprecated. Use `getGroupsStream` instead.
    `default List<GroupModel>` | `getGroupsByRole(RealmModel realm, RoleModel role, int firstResult, int maxResults)` Deprecated. Use `getGroupsByRoleStream` instead.
    `Stream<GroupModel>` | `getGroupsByRoleStream(RealmModel realm, RoleModel role, Integer firstResult, Integer maxResults)` Returns groups with the given role in the given realm.
    `Long` | `getGroupsCount(RealmModel realm, Boolean onlyTopGroups)` Returns a number of groups/top level groups (i.e.
    `default Long` | `getGroupsCount(RealmModel realm, Stream<String> ids, String search)` Returns a number of groups that contains the search string in the name
    `Long` | `getGroupsCountByNameContaining(RealmModel realm, String search)` Returns number of groups with the given string in name for the given realm.
    `Stream<GroupModel>` | `getGroupsStream(RealmModel realm)` Returns groups for the given realm.
    `default Stream<GroupModel>` | `getGroupsStream(RealmModel realm, Stream<String> ids)` Returns a list of groups with given ids.
    `default Stream<GroupModel>` | `getGroupsStream(RealmModel realm, Stream<String> ids, Integer first, Integer max)` Returns a paginated list of groups with given ids.
    `Stream<GroupModel>` | `getGroupsStream(RealmModel realm, Stream<String> ids, String search, Integer first, Integer max)` Returns a paginated stream of groups with given ids and given search value in group names.
    `default List<GroupModel>` | `getTopLevelGroups(RealmModel realm)` Deprecated. Use `getTopLevelGroupsStream` instead.
    `default List<GroupModel>` | `getTopLevelGroups(RealmModel realm, Integer firstResult, Integer maxResults)` Deprecated. Use `getTopLevelGroupsStream` instead.
    `Stream<GroupModel>` | `getTopLevelGroupsStream(RealmModel realm)` Returns all top level groups (i.e.
    `Stream<GroupModel>` | `getTopLevelGroupsStream(RealmModel realm, Integer firstResult, Integer maxResults)` Returns top level groups (i.e.
    `void` | `moveGroup(RealmModel realm, GroupModel group, GroupModel toParent)` This method is used for moving groups in group structure, for example: making an existing child group child group of some other group, setting a top level group (i.e.
    `void` | `preRemove(RealmModel realm, RoleModel role)` This function is called when a role is removed; this serves for removing references from groups to roles.
    `boolean` | `removeGroup(RealmModel realm, GroupModel group)` Removes the given group for the given realm.

    - ### Methods inherited from interface org.keycloak.provider.Provider

      `close`

    - ### Methods inherited from interface org.keycloak.storage.group.GroupLookupProvider

      `getGroupById, searchForGroupByName, searchForGroupByNameStream`

- - ### Method Detail

    - #### getGroupById

          default GroupModel getGroupById(String id,
                                          RealmModel realm)

      Deprecated. Use method `getGroupById(realm, id)`
      Returns a group from the given realm with the corresponding id
      Parameters:
        `id` - Id.
        `realm` - Realm.
      Returns:
        GroupModel with the corresponding id.

    - #### getGroups

          @Deprecated
          default List<GroupModel> getGroups(RealmModel realm)

      Deprecated. Use `getGroupsStream` instead.
      Returns groups for the given realm.
      Parameters:
        `realm` - Realm.
      Returns:
        List of groups in the Realm.

    - #### getGroupsStream

          Stream<GroupModel> getGroupsStream(RealmModel realm)

      Returns groups for the given realm.
      Parameters:
        `realm` - Realm.
      Returns:
        Stream of groups in the Realm.

    - #### getGroupsStream

          default Stream<GroupModel> getGroupsStream(RealmModel realm,
                                                     Stream<String> ids)

      Returns a list of groups with given ids. Effectively the same as `getGroupsStream(realm, ids, null, null, null)`.
      Parameters:
        `realm` - Realm.
        `ids` - List of ids.
      Returns:
        List of GroupModels with the specified ids

    - #### getGroupsStream

          Stream<GroupModel> getGroupsStream(RealmModel realm,
                                             Stream<String> ids,
                                             String search,
                                             Integer first,
                                             Integer max)

      Returns a paginated stream of groups with given ids and given search value in group names.
      Parameters:
        `realm` - Realm.
        `ids` - List of ids.
        `search` - Case insensitive string which will be searched for. Ignored if null.
        `first` - Index of the first result to return. Ignored if negative or `null`.
        `max` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        List of desired groups.

    - #### getGroupsStream

          default Stream<GroupModel> getGroupsStream(RealmModel realm,
                                                     Stream<String> ids,
                                                     Integer first,
                                                     Integer max)

      Returns a paginated list of groups with given ids. Effectively the same as `getGroupsStream(realm, ids, null, first, max)`.
      Parameters:
        `realm` - Realm.
        `ids` - List of ids.
        `first` - Index of the first result to return. Ignored if negative or `null`.
        `max` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        List of GroupModels with the specified ids

    - #### getGroupsCount

          default Long getGroupsCount(RealmModel realm,
                                      Stream<String> ids,
                                      String search)

      Returns a number of groups that contains the search string in the name
      Parameters:
        `realm` - Realm.
        `ids` - List of ids.
        `search` - Case insensitive string which will be searched for. Ignored if null.
      Returns:
        Number of groups.

    - #### getGroupsCount

          Long getGroupsCount(RealmModel realm,
                              Boolean onlyTopGroups)

      Returns a number of groups/top level groups (i.e. groups without parent group) for the given realm.
      Parameters:
        `realm` - Realm.
        `onlyTopGroups` - When true the function returns a count of top level groups only.
      Returns:
        Number of groups/top level groups.

    - #### getGroupsCountByNameContaining

          Long getGroupsCountByNameContaining(RealmModel realm,
                                              String search)

      Returns number of groups with the given string in name for the given realm.
      Parameters:
        `realm` - Realm.
        `search` - Case insensitive string which will be searched for.
      Returns:
        Number of groups with the given string in its name.

    - #### getGroupsByRole

          @Deprecated
          default List<GroupModel> getGroupsByRole(RealmModel realm,
                                                               RoleModel role,
                                                               int firstResult,
                                                               int maxResults)

      Deprecated. Use `getGroupsByRoleStream` instead.
      Returns groups with the given role in the given realm.
      Parameters:
        `realm` - Realm.
        `role` - Role.
        `firstResult` - First result to return. Ignored if negative.
        `maxResults` - Maximum number of results to return. Ignored if negative.
      Returns:
        List of groups with the given role.

    - #### getGroupsByRoleStream

          Stream<GroupModel> getGroupsByRoleStream(RealmModel realm,
                                                   RoleModel role,
                                                   Integer firstResult,
                                                   Integer maxResults)

      Returns groups with the given role in the given realm.
      Parameters:
        `realm` - Realm.
        `role` - Role.
        `firstResult` - First result to return. Ignored if negative or `null`.
        `maxResults` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        Stream of groups with the given role.

    - #### getTopLevelGroups

          @Deprecated
          default List<GroupModel> getTopLevelGroups(RealmModel realm)

      Deprecated. Use `getTopLevelGroupsStream` instead.
      Returns all top level groups (i.e. groups without parent group) for the given realm.
      Parameters:
        `realm` - Realm.
      Returns:
        List of all top level groups in the realm.

    - #### getTopLevelGroupsStream

          Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm)

      Returns all top level groups (i.e. groups without parent group) for the given realm.
      Parameters:
        `realm` - Realm.
      Returns:
        Stream of all top level groups in the realm.

    - #### getTopLevelGroups

          @Deprecated
          default List<GroupModel> getTopLevelGroups(RealmModel realm,
                                                                 Integer firstResult,
                                                                 Integer maxResults)

      Deprecated. Use `getTopLevelGroupsStream` instead.
      Returns top level groups (i.e. groups without parent group) for the given realm.
      Parameters:
        `realm` - Realm.
        `firstResult` - First result to return. Ignored if negative or `null`.
        `maxResults` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        List of top level groups in the realm.

    - #### getTopLevelGroupsStream

          Stream<GroupModel> getTopLevelGroupsStream(RealmModel realm,
                                                     Integer firstResult,
                                                     Integer maxResults)

      Returns top level groups (i.e. groups without parent group) for the given realm.
      Parameters:
        `realm` - Realm.
        `firstResult` - First result to return. Ignored if negative or `null`.
        `maxResults` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        Stream of top level groups in the realm.

    - #### createGroup

          default GroupModel createGroup(RealmModel realm,
                                         String name)

      Creates a new group with the given name in the given realm. Effectively the same as `createGroup(realm, null, name, null)`.
      Parameters:
        `realm` - Realm.
        `name` - Name.
      Returns:
        Model of the created group.
      Throws:
        `ModelDuplicateException` - If there is already a top-level group with the given name

    - #### createGroup

          default GroupModel createGroup(RealmModel realm,
                                         String id,
                                         String name)

      Creates a new group with the given id and name in the given realm. Effectively the same as `createGroup(realm, id, name, null)`
      Parameters:
        `realm` - Realm.
        `id` - Id.
        `name` - Name.
      Returns:
        Model of the created group
      Throws:
        `ModelDuplicateException` - If a group with given id already exists or there is a top-level group with the given name

    - #### createGroup

          default GroupModel createGroup(RealmModel realm,
                                         String name,
                                         GroupModel toParent)

      Creates a new group with the given name and parent to the given realm. Effectively the same as `createGroup(realm, null, name, toParent)`.
      Parameters:
        `realm` - Realm.
        `name` - Name.
        `toParent` - Parent group.
      Returns:
        Model of the created group.
      Throws:
        `ModelDuplicateException` - If the toParent group already has a subgroup with the given name

    - #### createGroup

          GroupModel createGroup(RealmModel realm,
                                 String id,
                                 String name,
                                 GroupModel toParent)

      Creates a new group with the given name, id, name and parent to the given realm.
      Parameters:
        `realm` - Realm.
        `id` - Id, will be generated if `null`.
        `name` - Name.
        `toParent` - Parent group, or `null` if the group is top level group
      Returns:
        Model of the created group
      Throws:
        `ModelDuplicateException` - If a group with the given id already exists or the toParent group has a subgroup with the given name

    - #### removeGroup

          boolean removeGroup(RealmModel realm,
                              GroupModel group)

      Removes the given group for the given realm.
      Parameters:
        `realm` - Realm.
        `group` - Group.
      Returns:
        true if the group was removed, false if group doesn't exist or doesn't belong to the given realm

    - #### moveGroup

          void moveGroup(RealmModel realm,
                         GroupModel group,
                         GroupModel toParent)

      This method is used for moving groups in group structure, for example:
      - making an existing child group child group of some other group,
      - setting a top level group (i.e. group without parent group) child of some group,
      - making a child group top level group (i.e. removing its parent group).
      Parameters:
        `realm` - Realm owning this group.
        `group` - Group to update.
        `toParent` - New parent group, or `null` if we are moving the group to top level group.
      Throws:
        `ModelDuplicateException` - If there is already a group with group.name under the toParent group (or top-level if toParent is null)

    - #### addTopLevelGroup

          void addTopLevelGroup(RealmModel realm,
                                GroupModel subGroup)

      Removes parent group for the given group in the given realm.
      Parameters:
        `realm` - Realm.
        `subGroup` - Group.
      Throws:
        `ModelDuplicateException` - If there is already a top level group name with the same name

    - #### preRemove

          void preRemove(RealmModel realm,
                         RoleModel role)

      This function is called when a role is removed; this serves for removing references from groups to roles.
      Parameters:
        `realm` - Realm.
        `role` - Role which will be removed.

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