Class DefaultAttributes
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,,List<String>> Attributes
- Direct Known Subclasses:
ServiceAccountAttributes
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 UserProfileContextstatic final Stringstatic final StringTo reference dynamic attributes that can be configured as read-only when setting up the provider.protected final KeycloakSessionprotected final UserModelFields inherited from interface org.keycloak.userprofile.Attributes
EMPTY_VALUE -
Constructor Summary
ConstructorsConstructorDescriptionDefaultAttributes(UserProfileContext context, Map<String, ?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddDefaultValidators(String name, List<AttributeMetadata> metadatas) booleanChecks whether an attribute with the givennameis defined.protected AttributeContextcreateAttributeContext(AttributeMetadata metadata) protected AttributeMetadataReturns all values for an attribute with the givenname.getAnnotations(String name) Returns the annotations for an attribute with the givenname.getMetadata(String name) Returns the metadata associated with the attribute with the givenname.Returns only the attributes that have read permissions in a particularUserProfileContext.Returns aMapholding any unmanaged attribute.Returns all the attributes with read-write permissions in a particularUserProfileContext.protected booleanprotected booleanbooleanisReadOnly(String name) Checks whether an attribute is read-only.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) Returns whether the attribute with the givennameis required.protected booleanisSupportedAttribute(String name) Checks whether an attribute is support by the profile configuration and the current context.nameSet()Returns the names of all defined attributes.normalizeAttributeValues(String name, Object value) Intentionally kept to protected visibility to allow for custom normalization logic while clients adopt User Profileprotected voidtoMap()Returns the attributes as aMapthat are accessible to a particularUserProfileContext.booleanvalidate(String name, Consumer<ValidationError>... listeners) Validates the attribute with the givenname.Methods 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
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
-
session
-
user
-
-
Constructor Details
-
DefaultAttributes
public DefaultAttributes(UserProfileContext context, Map<String, ?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session)
-
-
Method Details
-
isReadOnly
Description copied from interface:AttributesChecks whether an attribute is read-only.- Specified by:
isReadOnlyin interfaceAttributes- Parameters:
name- the attribute name- Returns:
trueif the attribute is read-only. Otherwise,false
-
isReadOnlyFromMetadata
Checks whether an attribute is marked as read only by looking at its metadata.- Parameters:
attributeName- the attribute name- Returns:
-
isRequired
Description copied from interface:AttributesReturns whether the attribute with the givennameis required.- Specified by:
isRequiredin interfaceAttributes- Parameters:
name- the attribute name- Returns:
trueif the attribute is required. Otherwise,false.
-
validate
Description copied from interface:AttributesValidates the attribute with the givenname.- Specified by:
validatein interfaceAttributes- Parameters:
name- the name of the attributelisteners- the listeners for listening for errors.ValidationError.inputHintcontains name of the attribute in error.- Returns:
trueif validation is successful. Otherwise,false. In case there is no attribute with the givenname,falseis also returned but without triggering listeners
-
addDefaultValidators
-
get
Description copied from interface:AttributesReturns all values for an attribute with the givenname.- Specified by:
getin interfaceAttributes- Parameters:
name- the name of the attribute- Returns:
- the attribute values
-
contains
Description copied from interface:AttributesChecks whether an attribute with the givennameis defined.- Specified by:
containsin interfaceAttributes- Parameters:
name- the name of the attribute- Returns:
trueif the attribute is defined. Otherwise,false
-
nameSet
Description copied from interface:AttributesReturns the names of all defined attributes.- Specified by:
nameSetin interfaceAttributes- Returns:
- the set of attribute names
-
getWritable
Description copied from interface:AttributesReturns all the attributes with read-write permissions in a particularUserProfileContext.- Specified by:
getWritablein interfaceAttributes- Returns:
- the attributes
-
getMetadata
Description copied from interface:AttributesReturns the metadata associated with the attribute with the given
name.The
AttributeMetadatais a copy of the original metadata. The original metadata keeps immutable.- Specified by:
getMetadatain interfaceAttributes- Parameters:
name- the attribute name- Returns:
- the metadata
-
getReadable
Description copied from interface:AttributesReturns only the attributes that have read permissions in a particularUserProfileContext.- Specified by:
getReadablein interfaceAttributes- Returns:
- the attributes with read permission.
-
toMap
Description copied from interface:AttributesReturns the attributes as aMapthat are accessible to a particularUserProfileContext.- Specified by:
toMapin interfaceAttributes- Returns:
- a map with all the attributes
-
createAttributeContext
-
normalizeAttributeValues
Intentionally kept to protected visibility to allow for custom normalization logic while clients adopt User Profile -
isAllowUnmanagedAttribute
protected boolean isAllowUnmanagedAttribute() -
setUserName
-
isIncludeAttributeIfNotProvided
-
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
Description copied from interface:AttributesReturns aMapholding any unmanaged attribute.- Specified by:
getUnmanagedAttributesin interfaceAttributes- Returns:
- a map with any unmanaged attribute
-
getAnnotations
Description copied from interface:AttributesReturns the annotations for an attribute with the given
name.The annotations returned by this method might differ from those returned directly from the
AttributeMetadata.getAnnotations()if the implementation supports annotations being resolved dynamically based on contextual data. SeeAttributeMetadata.setAnnotationDecorator(Function).- Specified by:
getAnnotationsin interfaceAttributes- Parameters:
name- the name of the attribute- Returns:
- the annotations
-
createUnmanagedAttributeMetadata
-