public class DefaultAttributes extends HashMap<String,List<String>> implements 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.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Modifier and Type | Field and Description |
|---|---|
protected UserProfileContext |
context |
static String |
READ_ONLY_ATTRIBUTE_KEY
To reference dynamic attributes that can be configured as read-only when setting up the provider.
|
protected UserModel |
user |
EMPTY_VALUE| Constructor and Description |
|---|
DefaultAttributes(UserProfileContext context,
Map<String,?> attributes,
UserModel user,
UserProfileMetadata profileMetadata,
KeycloakSession session) |
| Modifier and Type | Method and Description |
|---|---|
Set<Map.Entry<String,List<String>>> |
attributeSet()
Returns all attributes defined.
|
boolean |
contains(String name)
Checks whether an attribute with the given
name is defined. |
protected AttributeContext |
createAttributeContext(AttributeMetadata metadata) |
AttributeMetadata |
getMetadata(String name)
Returns the metadata associated with the attribute with the given
name. |
Map<String,List<String>> |
getReadable()
Returns only the attributes that have read/write permissions.
|
List<String> |
getValues(String name)
Returns all values for an attribute with the given
name. |
protected boolean |
isIncludeAttributeIfNotProvided(AttributeMetadata metadata) |
boolean |
isReadOnly(String attributeName)
Checks whether an attribute is read-only.
|
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)
Returns whether the attribute with the given
name is required. |
protected boolean |
isSupportedAttribute(String name)
Checks whether an attribute is support by the profile configuration and the current context.
|
Set<String> |
nameSet()
Returns the names of all defined attributes.
|
Map<String,List<String>> |
toMap() |
boolean |
validate(String name,
Consumer<ValidationError>... listeners)
Validates the attribute with the given
name. |
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesequals, hashCode, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitgetFirstValue, getReadable, isRootAttributepublic static final String READ_ONLY_ATTRIBUTE_KEY
protected final UserProfileContext context
protected final UserModel user
public DefaultAttributes(UserProfileContext context, Map<String,?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session)
public boolean isReadOnly(String attributeName)
AttributesisReadOnly in interface Attributesprotected boolean isReadOnlyFromMetadata(String attributeName)
attributeName - the attribute nametrue if the attribute is readonly. Otherwise, returns falsepublic boolean isRequired(String name)
Attributesname is required.isRequired in interface Attributesname - the attribute nametrue if the attribute is required. Otherwise, false.public boolean validate(String name, Consumer<ValidationError>... listeners)
Attributesname.validate in interface Attributesname - the name of the attributelisteners - the listeners for listening for errors. ValidationError.inputHint contains name of the attribute in error.true if validation is successful. Otherwise, false. In case there is no attribute with the given name,
false is also returned but without triggering listenerspublic List<String> getValues(String name)
Attributesname.getValues in interface Attributesname - the name of the attributepublic boolean contains(String name)
Attributesname is defined.contains in interface Attributesname - the name of the attributetrue if the attribute is defined. Otherwise, falsepublic Set<String> nameSet()
AttributesnameSet in interface Attributespublic Set<Map.Entry<String,List<String>>> attributeSet()
AttributesattributeSet in interface Attributespublic AttributeMetadata getMetadata(String name)
AttributesReturns the metadata associated with the attribute with the given name.
The AttributeMetadata is a copy of the original metadata. The original metadata
keeps immutable.
getMetadata in interface Attributesname - the attribute namepublic Map<String,List<String>> getReadable()
AttributesgetReadable in interface Attributesprotected AttributeContext createAttributeContext(AttributeMetadata metadata)
protected boolean isIncludeAttributeIfNotProvided(AttributeMetadata metadata)
protected boolean isSupportedAttribute(String name)
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.
name - the name of the attributeprotected 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.
For user-defined attributes, it should be preferable to use the user profile configuration.
attributeName - the attribute nametrue if the attribute is readonly. Otherwise, returns falseCopyright © 2021 JBoss by Red Hat. All rights reserved.