org.keycloak.storage

## Class RoleStorageManager

- java.lang.Object
- - org.keycloak.storage.RoleStorageManager

- All Implemented Interfaces:
    RoleProvider, Provider, RoleLookupProvider

      public class RoleStorageManager
      extends Object
      implements RoleProvider

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected KeycloakSession` | `session`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RoleStorageManager(KeycloakSession session, long roleStorageProviderTimeout)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `RoleModel` | `addClientRole(ClientModel client, String name)` Adds a client role with given `name` to the given client.
    `RoleModel` | `addClientRole(ClientModel client, String id, String name)` Adds a client role with given internal ID and `name` to the given client.
    `RoleModel` | `addRealmRole(RealmModel realm, String name)` Adds a realm role with given `name` to the given realm.
    `RoleModel` | `addRealmRole(RealmModel realm, String id, String name)` Adds a realm role with given internal ID and `name` to the given realm.
    `void` | `close()`
    `RoleModel` | `getClientRole(ClientModel client, String name)` Exact search for a client role by given name.
    `Stream<RoleModel>` | `getClientRolesStream(ClientModel client)` Returns all the client roles of the given client.
    `Stream<RoleModel>` | `getClientRolesStream(ClientModel client, Integer first, Integer max)` Returns the client roles of the given client.
    `static <T> Stream<T>` | `getEnabledStorageProviders(KeycloakSession session, RealmModel realm, Class<T> type)`
    `RoleModel` | `getRealmRole(RealmModel realm, String name)` Exact search for a role by given name.
    `Stream<RoleModel>` | `getRealmRolesStream(RealmModel realm, Integer first, Integer max)` Returns the realm roles of the given realm as a stream.
    `RoleModel` | `getRoleById(RealmModel realm, String id)` Exact search for a role by its internal ID..
    `static RoleStorageProvider` | `getStorageProvider(KeycloakSession session, RealmModel realm, String componentId)`
    `static RoleStorageProvider` | `getStorageProviderInstance(KeycloakSession session, RoleStorageProviderModel model, RoleStorageProviderFactory factory)`
    `static RoleStorageProviderModel` | `getStorageProviderModel(RealmModel realm, String componentId)`
    `static <T> Stream<T>` | `getStorageProviders(KeycloakSession session, RealmModel realm, Class<T> type)`
    `static <T> Stream<RoleStorageProviderModel>` | `getStorageProviders(RealmModel realm, KeycloakSession session, Class<T> type)`
    `static boolean` | `isStorageProviderEnabled(RealmModel realm, String providerId)`
    `boolean` | `removeRole(RoleModel role)` Removes given realm role from the given realm.
    `void` | `removeRoles(ClientModel client)` Removes all roles from the given client.
    `void` | `removeRoles(RealmModel realm)` Removes all roles from the given realm.
    `Stream<RoleModel>` | `searchForClientRolesStream(ClientModel client, String search, Integer first, Integer max)` Obtaining roles from an external role storage is time-bounded.
    `Stream<RoleModel>` | `searchForRolesStream(RealmModel realm, String search, Integer first, Integer max)` Obtaining roles from an external role storage is time-bounded.

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

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

    - ### Methods inherited from interface org.keycloak.models.RoleProvider

      `getRealmRoles, getRealmRolesStream`

- - ### Field Detail

    - #### session

          protected KeycloakSession session

  - ### Constructor Detail

    - #### RoleStorageManager

          public RoleStorageManager(KeycloakSession session,
                                    long roleStorageProviderTimeout)

  - ### Method Detail

    - #### isStorageProviderEnabled

          public static boolean isStorageProviderEnabled(RealmModel realm,
                                                         String providerId)

    - #### getStorageProviderModel

          public static RoleStorageProviderModel getStorageProviderModel(RealmModel realm,
                                                                         String componentId)

    - #### getStorageProvider

          public static RoleStorageProvider getStorageProvider(KeycloakSession session,
                                                               RealmModel realm,
                                                               String componentId)

    - #### getStorageProviders

          public static <T> Stream<RoleStorageProviderModel> getStorageProviders(RealmModel realm,
                                                                                 KeycloakSession session,
                                                                                 Class<T> type)

    - #### getStorageProviderInstance

          public static RoleStorageProvider getStorageProviderInstance(KeycloakSession session,
                                                                       RoleStorageProviderModel model,
                                                                       RoleStorageProviderFactory factory)

    - #### getStorageProviders

          public static <T> Stream<T> getStorageProviders(KeycloakSession session,
                                                          RealmModel realm,
                                                          Class<T> type)

    - #### getEnabledStorageProviders

          public static <T> Stream<T> getEnabledStorageProviders(KeycloakSession session,
                                                                 RealmModel realm,
                                                                 Class<T> type)

    - #### addRealmRole

          public RoleModel addRealmRole(RealmModel realm,
                                        String name)

      Description copied from interface: `RoleProvider`
      Adds a realm role with given `name` to the given realm. The internal ID of the role will be created automatically.
      Specified by:
        `addRealmRole` in interface `RoleProvider`
      Parameters:
        `realm` - Realm owning this role.
        `name` - String name of the role.
      Returns:
        Model of the created role.

    - #### addRealmRole

          public RoleModel addRealmRole(RealmModel realm,
                                        String id,
                                        String name)

      Description copied from interface: `RoleProvider`
      Adds a realm role with given internal ID and `name` to the given realm.
      Specified by:
        `addRealmRole` in interface `RoleProvider`
      Parameters:
        `realm` - Realm owning this role.
        `id` - Internal ID of the role or `null` if one is to be created by the underlying store
        `name` - String name of the role.
      Returns:
        Model of the created client.

    - #### getRealmRole

          public RoleModel getRealmRole(RealmModel realm,
                                        String name)

      Description copied from interface: `RoleLookupProvider`
      Exact search for a role by given name.
      Specified by:
        `getRealmRole` in interface `RoleLookupProvider`
      Parameters:
        `realm` - Realm.
        `name` - String name of the role.
      Returns:
        Model of the role, or `null` if no role is found.

    - #### getRoleById

          public RoleModel getRoleById(RealmModel realm,
                                       String id)

      Description copied from interface: `RoleLookupProvider`
      Exact search for a role by its internal ID..
      Specified by:
        `getRoleById` in interface `RoleLookupProvider`
      Parameters:
        `realm` - Realm.
        `id` - Internal ID of the role.
      Returns:
        Model of the role.

    - #### getRealmRolesStream

          public Stream<RoleModel> getRealmRolesStream(RealmModel realm,
                                                       Integer first,
                                                       Integer max)

      Description copied from interface: `RoleProvider`
      Returns the realm roles of the given realm as a stream.
      Specified by:
        `getRealmRolesStream` in interface `RoleProvider`
      Parameters:
        `realm` - Realm.
        `first` - First result to return. Ignored if negative or `null`.
        `max` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        Stream of the roles. Never returns `null`.

    - #### searchForRolesStream

          public Stream<RoleModel> searchForRolesStream(RealmModel realm,
                                                        String search,
                                                        Integer first,
                                                        Integer max)

      Obtaining roles from an external role storage is time-bounded. In case the external role storage isn't available at least roles from a local storage are returned. For this purpose the `DefaultKeycloakSessionFactory.getRoleStorageProviderTimeout()` property is used. Default value is 3000 milliseconds and it's configurable. See `DefaultKeycloakSessionFactory` for details.
      Specified by:
        `searchForRolesStream` in interface `RoleLookupProvider`
      Parameters:
        `realm` - Realm.
        `search` - Searched substring of the role's name or description.
        `first` - First result to return. Ignored if negative or `null`.
        `max` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        Stream of the realm roles their name or description contains given search string. Never returns `null`.

    - #### removeRole

          public boolean removeRole(RoleModel role)

      Description copied from interface: `RoleProvider`
      Removes given realm role from the given realm.
      Specified by:
        `removeRole` in interface `RoleProvider`
      Parameters:
        `role` - Role to be removed.
      Returns:
        `true` if the role existed and has been removed, `false` otherwise.

    - #### removeRoles

          public void removeRoles(RealmModel realm)

      Description copied from interface: `RoleProvider`
      Removes all roles from the given realm.
      Specified by:
        `removeRoles` in interface `RoleProvider`
      Parameters:
        `realm` - Realm.

    - #### removeRoles

          public void removeRoles(ClientModel client)

      Description copied from interface: `RoleProvider`
      Removes all roles from the given client.
      Specified by:
        `removeRoles` in interface `RoleProvider`
      Parameters:
        `client` - Client.

    - #### addClientRole

          public RoleModel addClientRole(ClientModel client,
                                         String name)

      Description copied from interface: `RoleProvider`
      Adds a client role with given `name` to the given client. The internal ID of the role will be created automatically.
      Specified by:
        `addClientRole` in interface `RoleProvider`
      Parameters:
        `client` - Client owning this role.
        `name` - String name of the role.
      Returns:
        Model of the created role.

    - #### addClientRole

          public RoleModel addClientRole(ClientModel client,
                                         String id,
                                         String name)

      Description copied from interface: `RoleProvider`
      Adds a client role with given internal ID and `name` to the given client.
      Specified by:
        `addClientRole` in interface `RoleProvider`
      Parameters:
        `client` - Client owning this role.
        `id` - Internal ID of the client role or `null` if one is to be created by the underlying store.
        `name` - String name of the role.
      Returns:
        Model of the created role.

    - #### getClientRole

          public RoleModel getClientRole(ClientModel client,
                                         String name)

      Description copied from interface: `RoleLookupProvider`
      Exact search for a client role by given name.
      Specified by:
        `getClientRole` in interface `RoleLookupProvider`
      Parameters:
        `client` - Client.
        `name` - String name of the role.
      Returns:
        Model of the role, or `null` if no role is found.

    - #### getClientRolesStream

          public Stream<RoleModel> getClientRolesStream(ClientModel client)

      Description copied from interface: `RoleProvider`
      Returns all the client roles of the given client. Effectively the same as the call `getClientRoles(client, null, null)`.
      Specified by:
        `getClientRolesStream` in interface `RoleProvider`
      Parameters:
        `client` - Client.
      Returns:
        Stream of the roles. Never returns `null`.

    - #### getClientRolesStream

          public Stream<RoleModel> getClientRolesStream(ClientModel client,
                                                        Integer first,
                                                        Integer max)

      Description copied from interface: `RoleProvider`
      Returns the client roles of the given client.
      Specified by:
        `getClientRolesStream` in interface `RoleProvider`
      Parameters:
        `client` - Client.
        `first` - First result to return. Ignored if negative or `null`.
        `max` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        Stream of the roles. Never returns `null`.

    - #### searchForClientRolesStream

          public Stream<RoleModel> searchForClientRolesStream(ClientModel client,
                                                              String search,
                                                              Integer first,
                                                              Integer max)

      Obtaining roles from an external role storage is time-bounded. In case the external role storage isn't available at least roles from a local storage are returned. For this purpose the `DefaultKeycloakSessionFactory.getRoleStorageProviderTimeout()` property is used. Default value is 3000 milliseconds and it's configurable. See `DefaultKeycloakSessionFactory` for details.
      Specified by:
        `searchForClientRolesStream` in interface `RoleLookupProvider`
      Parameters:
        `client` - Client.
        `search` - String to search by role's name or description.
        `first` - First result to return. Ignored if negative or `null`.
        `max` - Maximum number of results to return. Ignored if negative or `null`.
      Returns:
        Stream of the client roles their name or description contains given search string. Never returns `null`.

    - #### close

          public void close()

      Specified by:
        `close` in interface `Provider`

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