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 |
---|---|
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 . |
boolean |
isReadOnly(String attributeName)
Checks whether an attribute is read-only.
|
boolean |
isRequired(String name)
Returns whether the attribute with the given
name is required. |
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, values
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
getFirstValue, getReadable, isRootAttribute
public static final String READ_ONLY_ATTRIBUTE_KEY
protected final UserModel user
public DefaultAttributes(UserProfileContext context, Map<String,?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session)
public boolean isReadOnly(String attributeName)
Attributes
isReadOnly
in interface Attributes
public boolean isRequired(String name)
Attributes
name
is required.isRequired
in interface Attributes
name
- the attribute nametrue
if the attribute is required. Otherwise, false
.public boolean validate(String name, Consumer<ValidationError>... listeners)
Attributes
name
.validate
in interface Attributes
name
- 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)
Attributes
name
.getValues
in interface Attributes
name
- the name of the attributepublic boolean contains(String name)
Attributes
name
is defined.contains
in interface Attributes
name
- the name of the attributetrue
if the attribute is defined. Otherwise, false
public Set<String> nameSet()
Attributes
nameSet
in interface Attributes
public Set<Map.Entry<String,List<String>>> attributeSet()
Attributes
attributeSet
in interface Attributes
public AttributeMetadata getMetadata(String name)
Attributes
Returns 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 Attributes
name
- the attribute namepublic Map<String,List<String>> getReadable()
Attributes
getReadable
in interface Attributes
protected AttributeContext createAttributeContext(AttributeMetadata metadata)
Copyright © 2021 JBoss by Red Hat. All rights reserved.