Package org.keycloak.userprofile
Class DeclarativeUserProfileProvider
- java.lang.Object
-
- org.keycloak.userprofile.AbstractUserProfileProvider<UserProfileProvider>
-
- org.keycloak.userprofile.DeclarativeUserProfileProvider
-
- All Implemented Interfaces:
AmphibianProviderFactory<UserProfileProvider>,ComponentFactory<UserProfileProvider,UserProfileProvider>,ConfiguredProvider,Provider,ProviderFactory<UserProfileProvider>,UserProfileProvider,UserProfileProviderFactory<UserProfileProvider>
public class DeclarativeUserProfileProvider extends AbstractUserProfileProvider<UserProfileProvider> implements AmphibianProviderFactory<UserProfileProvider>
UserProfileProviderloading configuration from the changeable JSON file stored in component config. Parsed configuration is cached.- Author:
- Pedro Igor, Vlastimil Elias
-
-
Field Summary
Fields Modifier and Type Field Description static StringIDstatic intPROVIDER_PRIORITYstatic StringREALM_USER_PROFILE_ENABLEDstatic StringUP_PIECES_COUNT_COMPONENT_CONFIG_KEY-
Fields inherited from class org.keycloak.userprofile.AbstractUserProfileProvider
contextualMetadataRegistry, session
-
-
Constructor Summary
Constructors Constructor Description DeclarativeUserProfileProvider()DeclarativeUserProfileProvider(KeycloakSession session, Map<UserProfileContext,UserProfileMetadata> metadataRegistry, String defaultRawConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected UserProfileMetadataconfigureUserProfile(UserProfileMetadata metadata, KeycloakSession session)Sub-types can override this method to customize how contextual profile metadata is configured at runtime.protected UserProfileProvidercreate(KeycloakSession session, Map<UserProfileContext,UserProfileMetadata> metadataRegistry)Subclasses can override this method to create their instances ofUserProfileProvider.protected AttributescreateAttributes(UserProfileContext context, Map<String,?> attributes, UserModel user, UserProfileMetadata metadata)protected ComponentModelcreateComponentModel()Create the component model to store configurationprotected AttributeValidatorMetadatacreateConfiguredValidator(String validator, Map<String,Object> validatorConfig)Create validator for validation configured in the user profile config.protected UserProfileMetadatadecorateUserProfileForCache(UserProfileMetadata decoratedMetadata, ComponentModel model)Decorate basic metadata provided fromAbstractUserProfileProviderbased on 'per realm' configuration.ComponentModelgetComponentModel()List<ProviderConfigProperty>getConfigProperties()StringgetConfiguration()Get current UserProfile configuration.StringgetHelpText()StringgetId()protected UPConfiggetParsedConfig(ComponentModel model)Get parsed config file configured in model.voidinit(Config.Scope config)Only called once when the factory is first created.intorder()voidsetConfiguration(String configuration)Set new UserProfile configuration.voidvalidateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel model)Called before a component is created or updated.-
Methods inherited from class org.keycloak.userprofile.AbstractUserProfileProvider
close, configureUserProfile, create, create, create, create, getRegexPatternString, postInit
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.keycloak.component.AmphibianProviderFactory
close, create, create, onUpdate, preRemove
-
Methods inherited from interface org.keycloak.component.ComponentFactory
getCommonProviderConfigProperties, getTypeMetadata, onCreate
-
Methods inherited from interface org.keycloak.provider.ConfiguredProvider
getConfig
-
Methods inherited from interface org.keycloak.provider.ProviderFactory
getConfigMetadata, postInit
-
-
-
-
Field Detail
-
ID
public static final String ID
- See Also:
- Constant Field Values
-
PROVIDER_PRIORITY
public static final int PROVIDER_PRIORITY
- See Also:
- Constant Field Values
-
UP_PIECES_COUNT_COMPONENT_CONFIG_KEY
public static final String UP_PIECES_COUNT_COMPONENT_CONFIG_KEY
- See Also:
- Constant Field Values
-
REALM_USER_PROFILE_ENABLED
public static final String REALM_USER_PROFILE_ENABLED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DeclarativeUserProfileProvider
public DeclarativeUserProfileProvider()
-
DeclarativeUserProfileProvider
public DeclarativeUserProfileProvider(KeycloakSession session, Map<UserProfileContext,UserProfileMetadata> metadataRegistry, String defaultRawConfig)
-
-
Method Detail
-
getId
public String getId()
- Specified by:
getIdin interfaceProviderFactory<UserProfileProvider>
-
create
protected UserProfileProvider create(KeycloakSession session, Map<UserProfileContext,UserProfileMetadata> metadataRegistry)
Description copied from class:AbstractUserProfileProviderSubclasses can override this method to create their instances ofUserProfileProvider.- Specified by:
createin classAbstractUserProfileProvider<UserProfileProvider>- Parameters:
session- the sessionmetadataRegistry- the profile metadata- Returns:
- the profile provider instance
-
createAttributes
protected Attributes createAttributes(UserProfileContext context, Map<String,?> attributes, UserModel user, UserProfileMetadata metadata)
- Overrides:
createAttributesin classAbstractUserProfileProvider<UserProfileProvider>
-
configureUserProfile
protected UserProfileMetadata configureUserProfile(UserProfileMetadata metadata, KeycloakSession session)
Description copied from class:AbstractUserProfileProviderSub-types can override this method to customize how contextual profile metadata is configured at runtime.- Overrides:
configureUserProfilein classAbstractUserProfileProvider<UserProfileProvider>- Parameters:
metadata- the profile metadatasession- the current session- Returns:
- the metadata
-
getHelpText
public String getHelpText()
- Specified by:
getHelpTextin interfaceConfiguredProvider
-
validateConfiguration
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel model) throws ComponentValidationException
Description copied from interface:ComponentFactoryCalled before a component is created or updated. Allows you to validate the configuration- Specified by:
validateConfigurationin interfaceComponentFactory<UserProfileProvider,UserProfileProvider>- Throws:
ComponentValidationException
-
getConfiguration
public String getConfiguration()
Description copied from interface:UserProfileProviderGet current UserProfile configuration. JSON formatted file is expected, but depends on the implementation.- Specified by:
getConfigurationin interfaceUserProfileProvider- Overrides:
getConfigurationin classAbstractUserProfileProvider<UserProfileProvider>- Returns:
- current UserProfile configuration
- See Also:
UserProfileProvider.setConfiguration(String)
-
setConfiguration
public void setConfiguration(String configuration)
Description copied from interface:UserProfileProviderSet new UserProfile configuration. It is persisted inside of the provider.- Specified by:
setConfigurationin interfaceUserProfileProvider- Overrides:
setConfigurationin classAbstractUserProfileProvider<UserProfileProvider>- Parameters:
configuration- to be set- See Also:
UserProfileProvider.getConfiguration()
-
getConfigProperties
public List<ProviderConfigProperty> getConfigProperties()
- Specified by:
getConfigPropertiesin interfaceAmphibianProviderFactory<UserProfileProvider>- Specified by:
getConfigPropertiesin interfaceConfiguredProvider
-
init
public void init(Config.Scope config)
Description copied from interface:ProviderFactoryOnly called once when the factory is first created. This config is pulled from keycloak_server.json- Specified by:
initin interfaceProviderFactory<UserProfileProvider>- Overrides:
initin classAbstractUserProfileProvider<UserProfileProvider>
-
order
public int order()
- Specified by:
orderin interfaceProviderFactory<UserProfileProvider>
-
getComponentModel
public ComponentModel getComponentModel()
-
decorateUserProfileForCache
protected UserProfileMetadata decorateUserProfileForCache(UserProfileMetadata decoratedMetadata, ComponentModel model)
Decorate basic metadata provided fromAbstractUserProfileProviderbased on 'per realm' configuration. This method is called for eachUserProfileContextin each realm, and metadata are cached then and this method is called again only if configuration changes.- Parameters:
decoratedMetadata- base to be decorated based on configuration loaded from component modelmodel- component model to get "per realm" configuration from- Returns:
- decorated metadata
-
getParsedConfig
protected UPConfig getParsedConfig(ComponentModel model)
Get parsed config file configured in model. Default one used if not configured.- Parameters:
model- to take config from- Returns:
- parsed configuration
-
createComponentModel
protected ComponentModel createComponentModel()
Create the component model to store configuration- Returns:
- component model
-
createConfiguredValidator
protected AttributeValidatorMetadata createConfiguredValidator(String validator, Map<String,Object> validatorConfig)
Create validator for validation configured in the user profile config.- Parameters:
validator- id to create validator forvalidatorConfig- of the validator- Returns:
- validator metadata to run given validation
-
-