Package org.keycloak.models.map.common
Class SessionAttributesUtils
- java.lang.Object
-
- org.keycloak.models.map.common.SessionAttributesUtils
-
public class SessionAttributesUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description SessionAttributesUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V extends AbstractEntity & UpdatableEntity,M,T extends MapStorage<V,M>>
TcreateMapStorageIfAbsent(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.static <T extends Provider>
TcreateProviderIfAbsent(KeycloakSession session, int factoryIdentifier, Class<T> providerClass, Function<KeycloakSession,T> createNew)
Used for creating a provider instance only once within one KeycloakSession.static int
grabNewFactoryIdentifier()
Returns a new unique counter across whole Keycloak instance
-
-
-
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 givenproviderClass
andfactoryIdentifier
. If exists returns existing provider, otherwise creates a new instance usingcreateNew
function.- Type Parameters:
T
- type of the provider- Parameters:
session
- current Keycloak sessionfactoryIdentifier
- unique factory identifier.grabNewFactoryIdentifier()
can be used for obtaining new identifiers.providerClass
- class of the requested providercreateNew
- 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 givenproviderClass
,modelType
andfactoryIdentifier
. If exists returns existing provider, otherwise creates a new instance usingcreateNew
supplier.- Type Parameters:
V
- entity typeM
- model typeT
- store type- Parameters:
session
- current Keycloak sessionproviderType
- map storage provider classmodelType
- 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.
-
-