Interface UserProfile

All Known Implementing Classes:
DefaultUserProfile

public interface UserProfile

An interface that serves an entry point for managing users and their attributes.

A UserProfile provides methods for creating, and updating users as well as for accessing their attributes. All its operations are based the UserProfileContext. By taking the context into account, the state and behavior of UserProfile instances depend on the context they are associated with where creating, updating, validating, and accessing the attribute set of a user is based on the configuration (see UPConfig) and the constraints associated with a given context.

The UserProfileContext represents the different areas in Keycloak where users, and their attributes are managed. Examples of contexts are: managing users through the Admin API, or through the Account API.

A UserProfile instance can be obtained through the UserProfileProvider:

 
 // resolve an existing user
 UserModel user = getExistingUser();
 // obtain the user profile provider
 UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
 // create a instance for managing the user profile through the USER_API context
 UserProfile profile = provider.create(USER_API, user);
 

The UserProfileProvider provides different methods for creating UserProfile instances, each one target for a specific scenario such as creating a new user, updating an existing one, or only for accessing the attributes for an existing user as shown in the above example.

Author:
Markus Till
See Also:
  • Method Details

    • validate

      void validate() throws ValidationException
      Validates the attributes associated with this instance.
      Throws:
      ValidationException - in case
    • create

      Creates a new UserModel based on the attributes associated with this instance.
      Returns:
      the UserModel instance created from this profile
      Throws:
      ValidationException - in case validation fails
    • update

      void update(boolean removeAttributes, AttributeChangeListener... changeListener) throws ValidationException

      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 validate() method was previously invoked. If not, the validation step is performed prior to updating the model.

      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
      Throws:
      ValidationException - in case of any validation error
    • update

      default void update(AttributeChangeListener... changeListener) throws ValidationException

      The same as update(boolean, AttributeChangeListener...)} but forcing the removal of attributes.

      Parameters:
      changeListener - a set of one or more listeners to listen for attribute changes
      Throws:
      ValidationException - in case of any validation error
    • getAttributes

      Attributes getAttributes()
      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.
      Returns:
      the attributes associated with this instance.
    • toRepresentation

      <R extends AbstractUserRepresentation> R toRepresentation()