Class DefaultAttributes
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
,List<String>> 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
Modifier and TypeFieldDescriptionprotected final UserProfileContext
static final String
To reference dynamic attributes that can be configured as read-only when setting up the provider.protected final KeycloakSession
protected final UserModel
Fields inherited from interface org.keycloak.userprofile.Attributes
EMPTY_VALUE
-
Constructor Summary
ConstructorDescriptionDefaultAttributes
(UserProfileContext context, Map<String, ?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session) -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected AttributeContext
createAttributeContext
(AttributeMetadata metadata) getMetadata
(String name) protected boolean
boolean
isReadOnly
(String attributeName) protected boolean
isReadOnlyFromMetadata
(String attributeName) Checks whether an attribute is marked as read only by looking at its metadata.protected boolean
isReadOnlyInternalAttribute
(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.boolean
isRequired
(String name) protected boolean
protected boolean
isSupportedAttribute
(String name) Checks whether an attribute is support by the profile configuration and the current context.nameSet()
toMap()
boolean
validate
(String name, Consumer<ValidationError>... listeners) 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, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.keycloak.userprofile.Attributes
getFirstValue, getReadable, isRootAttribute
-
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:
-
context
-
session
-
user
-
-
Constructor Details
-
DefaultAttributes
public DefaultAttributes(UserProfileContext context, Map<String, ?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session)
-
-
Method Details
-
isReadOnly
- Specified by:
isReadOnly
in interfaceAttributes
-
isReadOnlyFromMetadata
Checks whether an attribute is marked as read only by looking at its metadata.- Parameters:
attributeName
- the attribute name- Returns:
-
isRequired
- Specified by:
isRequired
in interfaceAttributes
-
validate
- Specified by:
validate
in interfaceAttributes
-
getValues
- Specified by:
getValues
in interfaceAttributes
-
contains
- Specified by:
contains
in interfaceAttributes
-
nameSet
- Specified by:
nameSet
in interfaceAttributes
-
getWritable
- Specified by:
getWritable
in interfaceAttributes
-
getMetadata
- Specified by:
getMetadata
in interfaceAttributes
-
getReadable
- Specified by:
getReadable
in interfaceAttributes
-
toMap
- Specified by:
toMap
in interfaceAttributes
-
isServiceAccountUser
protected boolean isServiceAccountUser() -
createAttributeContext
-
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
Map
and 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:
true
if the attribute is readonly. Otherwise, returnsfalse
-