Class SessionAttributesUtils


  • public class SessionAttributesUtils
    extends Object
    • Constructor Detail

      • SessionAttributesUtils

        public SessionAttributesUtils()
    • Method Detail

      • grabNewFactoryIdentifier

        public static int grabNewFactoryIdentifier()
        Returns a new unique counter across whole Keycloak instance
        Returns:
        unique number
      • createProviderIfAbsent

        public static <T extends Provider> T createProviderIfAbsent​(KeycloakSession session,
                                                                    int factoryIdentifier,
                                                                    Class<T> providerClass,
                                                                    Function<KeycloakSession,​T> createNew)
        Used for creating a provider instance only once within one KeycloakSession.

        Checks whether there already exists a provider withing session attributes for given providerClass and factoryIdentifier. If exists returns existing provider, otherwise creates a new instance using createNew function.

        Type Parameters:
        T - type of the provider
        Parameters:
        session - current Keycloak session
        factoryIdentifier - unique factory identifier. grabNewFactoryIdentifier() can be used for obtaining new identifiers.
        providerClass - class of the requested provider
        createNew - function that creates a new instance of the provider
        Returns:
        an instance of the provider either from session attributes or freshly created.
      • createMapStorageIfAbsent

        public static <V extends AbstractEntity & UpdatableEntity,​M,​T extends MapStorage<V,​M>> T createMapStorageIfAbsent​(KeycloakSession session,
                                                                                                                                            Class<? extends MapStorageProvider> providerType,
                                                                                                                                            Class<M> modelType,
                                                                                                                                            int factoryId,
                                                                                                                                            Supplier<T> createNew)
        Used for creating a store instance only once within one KeycloakSession.

        Checks whether there already is a store within session attributes for given providerClass, modelType and factoryIdentifier. If exists returns existing provider, otherwise creates a new instance using createNew supplier.

        Type Parameters:
        V - entity type
        M - model type
        T - store type
        Parameters:
        session - current Keycloak session
        providerType - map storage provider class
        modelType - model class. Can be null if the store is the same for all models.
        factoryId - unique factory identifier. grabNewFactoryIdentifier() can be used for obtaining new identifiers.
        createNew - supplier that creates a new instance of the store
        Returns:
        an instance of the store either from session attributes or freshly created.