Class DefaultAttributes
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,,List<String>> org.keycloak.userprofile.Attributes
The default implementation for Attributes. Should be reused as much as possible by the different implementations
of UserProfileProvider.
One of the main aspects of this implementation is to allow normalizing attributes accordingly to the profile configuration and current context. As such, it provides some common normalization to common profile attributes (e.g.: username, email, first and last names, dynamic read-only attributes).
This implementation is not specific to any user profile implementation.
- Author:
- Pedro Igor
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.keycloak.userprofile.UserProfileContextstatic final Stringstatic final StringTo reference dynamic attributes that can be configured as read-only when setting up the provider.protected final org.keycloak.models.KeycloakSessionprotected final org.keycloak.models.UserModelFields inherited from interface org.keycloak.userprofile.Attributes
EMPTY_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionDefaultAttributes(org.keycloak.userprofile.UserProfileContext context, Map<String, ?> attributes, org.keycloak.models.UserModel user, org.keycloak.userprofile.UserProfileMetadata profileMetadata, org.keycloak.models.KeycloakSession session) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDefaultValidators(String name, List<org.keycloak.userprofile.AttributeMetadata> metadatas) booleanprotected org.keycloak.userprofile.AttributeContextcreateAttributeContext(org.keycloak.userprofile.AttributeMetadata metadata) protected org.keycloak.userprofile.AttributeMetadatagetAnnotations(String name) org.keycloak.userprofile.AttributeMetadatagetMetadata(String name) protected booleanbooleanisDefaultAttribute(String name) protected booleanisIncludeAttributeIfNotProvided(org.keycloak.userprofile.AttributeMetadata metadata) booleanisReadOnly(String name) protected booleanisReadOnlyFromMetadata(String attributeName) Checks whether an attribute is marked as read only by looking at its metadata.protected booleanisReadOnlyInternalAttribute(String attributeName) Returns whether an attribute is read only based on the provider configuration (using provider config), usually related to internal attributes managed by the server.booleanisRequired(String name) protected booleanisSupportedAttribute(String name) Checks whether an attribute is support by the profile configuration and the current context.nameSet()normalizeAttributeValues(String name, Object value) Intentionally kept to protected visibility to allow for custom normalization logic while clients adopt User Profileprotected voidtoMap()booleanMethods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.keycloak.userprofile.Attributes
getDefaultAttributes, getFirst
-
Field Details
-
READ_ONLY_ATTRIBUTE_KEY
To reference dynamic attributes that can be configured as read-only when setting up the provider. We should probably remove that once we remove the legacy provider, because this will come from the configuration.- See Also:
-
DEFAULT_MAX_LENGTH_ATTRIBUTES
- See Also:
-
context
protected final org.keycloak.userprofile.UserProfileContext context -
session
protected final org.keycloak.models.KeycloakSession session -
user
protected final org.keycloak.models.UserModel user
-
-
Constructor Details
-
DefaultAttributes
-
-
Method Details
-
isReadOnly
- Specified by:
isReadOnlyin interfaceorg.keycloak.userprofile.Attributes
-
isReadOnlyFromMetadata
Checks whether an attribute is marked as read only by looking at its metadata.- Parameters:
attributeName- the attribute name- Returns:
-
isRequired
- Specified by:
isRequiredin interfaceorg.keycloak.userprofile.Attributes
-
validate
- Specified by:
validatein interfaceorg.keycloak.userprofile.Attributes
-
addDefaultValidators
-
get
- Specified by:
getin interfaceorg.keycloak.userprofile.Attributes
-
contains
- Specified by:
containsin interfaceorg.keycloak.userprofile.Attributes
-
nameSet
- Specified by:
nameSetin interfaceorg.keycloak.userprofile.Attributes
-
getWritable
- Specified by:
getWritablein interfaceorg.keycloak.userprofile.Attributes
-
getMetadata
- Specified by:
getMetadatain interfaceorg.keycloak.userprofile.Attributes
-
getReadable
- Specified by:
getReadablein interfaceorg.keycloak.userprofile.Attributes
-
toMap
- Specified by:
toMapin interfaceorg.keycloak.userprofile.Attributes
-
isDefaultAttribute
- Specified by:
isDefaultAttributein interfaceorg.keycloak.userprofile.Attributes
-
createAttributeContext
protected org.keycloak.userprofile.AttributeContext createAttributeContext(org.keycloak.userprofile.AttributeMetadata metadata) -
normalizeAttributeValues
Intentionally kept to protected visibility to allow for custom normalization logic while clients adopt User Profile -
isAllowUnmanagedAttribute
protected boolean isAllowUnmanagedAttribute() -
setUserName
-
isIncludeAttributeIfNotProvided
protected boolean isIncludeAttributeIfNotProvided(org.keycloak.userprofile.AttributeMetadata metadata) -
isSupportedAttribute
Checks whether an attribute is support by the profile configuration and the current context.
This method can be used to avoid unexpected attributes from being added as an attribute because the attribute source is a regular
Mapand not normalized.- Parameters:
name- the name of the attribute- Returns:
-
isReadOnlyInternalAttribute
Returns whether an attribute is read only based on the provider configuration (using provider config), usually related to internal attributes managed by the server.
For user-defined attributes, it should be preferable to use the user profile configuration.
- Parameters:
attributeName- the attribute name- Returns:
trueif the attribute is readonly. Otherwise, returnsfalse
-
getUnmanagedAttributes
- Specified by:
getUnmanagedAttributesin interfaceorg.keycloak.userprofile.Attributes
-
getAnnotations
- Specified by:
getAnnotationsin interfaceorg.keycloak.userprofile.Attributes
-
createUnmanagedAttributeMetadata
-