Class DefaultAttributes
- java.lang.Object
- 
- java.util.AbstractMap<K,V>
- 
- java.util.HashMap<String,List<String>>
- 
- org.keycloak.userprofile.DefaultAttributes
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<String,List<String>>,- Attributes
 - Direct Known Subclasses:
- LegacyAttributes
 
 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 ofUserProfileProvider.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:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected UserProfileContextcontextstatic StringREAD_ONLY_ATTRIBUTE_KEYTo reference dynamic attributes that can be configured as read-only when setting up the provider.protected UserModeluser- 
Fields inherited from interface org.keycloak.userprofile.AttributesEMPTY_VALUE
 
- 
 - 
Constructor SummaryConstructors Constructor Description DefaultAttributes(UserProfileContext context, Map<String,?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<Map.Entry<String,List<String>>>attributeSet()Returns all attributes defined.booleancontains(String name)Checks whether an attribute with the givennameis defined.protected AttributeContextcreateAttributeContext(AttributeMetadata metadata)AttributeMetadatagetMetadata(String name)Returns the metadata associated with the attribute with the givenname.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 givenname.protected booleanisIncludeAttributeIfNotProvided(AttributeMetadata metadata)booleanisReadOnly(String attributeName)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.Set<String>nameSet()Returns the names of all defined attributes.Map<String,List<String>>toMap()booleanvalidate(String name, Consumer<ValidationError>... listeners)Validates the attribute with the givenname.- 
Methods inherited from class java.util.HashMapclear, 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.AbstractMapequals, hashCode, toString
 - 
Methods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.userprofile.AttributesgetFirstValue, getReadable, isRootAttribute
 
- 
 
- 
- 
- 
Field Detail- 
READ_ONLY_ATTRIBUTE_KEYpublic static final String 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:
- Constant Field Values
 
 - 
contextprotected final UserProfileContext context 
 - 
userprotected final UserModel user 
 
- 
 - 
Constructor Detail- 
DefaultAttributespublic DefaultAttributes(UserProfileContext context, Map<String,?> attributes, UserModel user, UserProfileMetadata profileMetadata, KeycloakSession session) 
 
- 
 - 
Method Detail- 
isReadOnlypublic boolean isReadOnly(String attributeName) Description copied from interface:AttributesChecks whether an attribute is read-only.- Specified by:
- isReadOnlyin interface- Attributes
- Returns:
 
 - 
isReadOnlyFromMetadataprotected boolean isReadOnlyFromMetadata(String attributeName) Checks whether an attribute is marked as read only by looking at its metadata.- Parameters:
- attributeName- the attribute name
- Returns:
 
 - 
isRequiredpublic boolean isRequired(String name) Description copied from interface:AttributesReturns whether the attribute with the givennameis required.- Specified by:
- isRequiredin interface- Attributes
- Parameters:
- name- the attribute name
- Returns:
- trueif the attribute is required. Otherwise,- false.
 
 - 
validatepublic boolean validate(String name, Consumer<ValidationError>... listeners) Description copied from interface:AttributesValidates the attribute with the givenname.- Specified by:
- validatein interface- Attributes
- Parameters:
- name- the name of the attribute
- listeners- 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 given- name,- falseis also returned but without triggering listeners
 
 - 
getValuespublic List<String> getValues(String name) Description copied from interface:AttributesReturns all values for an attribute with the givenname.- Specified by:
- getValuesin interface- Attributes
- Parameters:
- name- the name of the attribute
- Returns:
- the attribute values
 
 - 
containspublic boolean contains(String name) Description copied from interface:AttributesChecks whether an attribute with the givennameis defined.- Specified by:
- containsin interface- Attributes
- Parameters:
- name- the name of the attribute
- Returns:
- trueif the attribute is defined. Otherwise,- false
 
 - 
nameSetpublic Set<String> nameSet() Description copied from interface:AttributesReturns the names of all defined attributes.- Specified by:
- nameSetin interface- Attributes
- Returns:
- the set of attribute names
 
 - 
attributeSetpublic Set<Map.Entry<String,List<String>>> attributeSet() Description copied from interface:AttributesReturns all attributes defined.- Specified by:
- attributeSetin interface- Attributes
- Returns:
- the attributes
 
 - 
getMetadatapublic AttributeMetadata getMetadata(String name) 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 interface- Attributes
- Parameters:
- name- the attribute name
- Returns:
- the metadata
 
 - 
getReadablepublic Map<String,List<String>> getReadable() Description copied from interface:AttributesReturns only the attributes that have read/write permissions.- Specified by:
- getReadablein interface- Attributes
- Returns:
- the attributes with read/write permission.
 
 - 
createAttributeContextprotected AttributeContext createAttributeContext(AttributeMetadata metadata) 
 - 
isIncludeAttributeIfNotProvidedprotected boolean isIncludeAttributeIfNotProvided(AttributeMetadata metadata) 
 - 
isSupportedAttributeprotected 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 Mapand not normalized.- Parameters:
- name- the name of the attribute
- Returns:
 
 - 
isReadOnlyInternalAttributeprotected 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. - Parameters:
- attributeName- the attribute name
- Returns:
- trueif the attribute is readonly. Otherwise, returns- false
 
 
- 
 
-