Class DefaultUserProfile

java.lang.Object
org.keycloak.userprofile.DefaultUserProfile
All Implemented Interfaces:
UserProfile

public final class DefaultUserProfile extends Object implements UserProfile

The default implementation for UserProfile. Should be reused as much as possible by the different implementations of UserProfileProvider.

This implementation is not specific to any user profile implementation.

Author:
Pedro Igor
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultUserProfile(org.keycloak.userprofile.UserProfileMetadata metadata, org.keycloak.userprofile.Attributes attributes, Function<org.keycloak.userprofile.Attributes,org.keycloak.models.UserModel> userCreator, org.keycloak.models.UserModel user, org.keycloak.models.KeycloakSession session)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.keycloak.models.UserModel
    Creates a new UserModel based on the attributes associated with this instance.
    org.keycloak.models.UserModel
    create(boolean validate)
    Creates a new UserModel based on the attributes associated with this instance.
    org.keycloak.userprofile.Attributes
    Returns the attributes associated with this instance.
    <R extends org.keycloak.representations.idm.AbstractUserRepresentation>
    R
    toRepresentation(boolean full)
    Returns the user representation
    void
    update(boolean removeAttributes, AttributeChangeListener... changeListener)
    Updates the UserModel associated with this instance.
    void
    Validates the attributes associated with this instance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.keycloak.userprofile.UserProfile

    toRepresentation, update
  • Constructor Details

    • DefaultUserProfile

      public DefaultUserProfile(org.keycloak.userprofile.UserProfileMetadata metadata, org.keycloak.userprofile.Attributes attributes, Function<org.keycloak.userprofile.Attributes,org.keycloak.models.UserModel> userCreator, org.keycloak.models.UserModel user, org.keycloak.models.KeycloakSession session)
  • Method Details

    • validate

      public void validate()
      Description copied from interface: UserProfile
      Validates the attributes associated with this instance.
      Specified by:
      validate in interface UserProfile
    • create

      public org.keycloak.models.UserModel create() throws ValidationException
      Description copied from interface: UserProfile
      Creates a new UserModel based on the attributes associated with this instance.
      Specified by:
      create in interface UserProfile
      Returns:
      the UserModel instance created from this profile
      Throws:
      ValidationException - in case validation fails
    • create

      public org.keycloak.models.UserModel create(boolean validate) throws ValidationException
      Description copied from interface: UserProfile
      Creates a new UserModel based on the attributes associated with this instance.
      Specified by:
      create in interface UserProfile
      Parameters:
      validate - if true, execute validations on create. Otherwise, validation should be done programmatically by calling UserProfile.validate()
      Returns:
      the UserModel instance created from this profile
      Throws:
      ValidationException - in case validation fails
    • update

      public void update(boolean removeAttributes, AttributeChangeListener... changeListener)
      Description copied from interface: UserProfile

      Updates the UserModel associated with this instance. If no UserModel is associated with this instance, this operation has no effect.

      Before updating the UserModel, this method first checks whether the UserProfile.validate() method was previously invoked. If not, the validation step is performed prior to updating the model.

      Specified by:
      update in interface UserProfile
      Parameters:
      removeAttributes - if attributes should be removed from the UserModel if they are not among the attributes associated with this instance.
      changeListener - a set of one or more listeners to listen for attribute changes
    • getAttributes

      public org.keycloak.userprofile.Attributes getAttributes()
      Description copied from interface: UserProfile
      Returns the attributes associated with this instance. Note that the attributes returned by this method are not necessarily the same from the UserModel as they are based on the configurations set in the UPConfig and the context this instance is based on.
      Specified by:
      getAttributes in interface UserProfile
      Returns:
      the attributes associated with this instance.
    • toRepresentation

      public <R extends org.keycloak.representations.idm.AbstractUserRepresentation> R toRepresentation(boolean full)
      Description copied from interface: UserProfile
      Returns the user representation
      Specified by:
      toRepresentation in interface UserProfile
      Parameters:
      full - if the full representation should be returned
      Returns:
      the user representation