Class BasicUserProfile

java.lang.Object
org.pac4j.core.profile.BasicUserProfile
All Implemented Interfaces:
Externalizable, Serializable, UserProfile
Direct Known Subclasses:
CommonProfile

public class BasicUserProfile extends Object implements UserProfile, Externalizable
This class is the user profile retrieved from a provider after successful authentication: it's an identifier (string) and attributes (objects). Additional concepts are the "remember me" nature of the user profile, the associated roles, client name and linked identifier.
Since:
1.0.0
Author:
Jerome Leleu
See Also:
  • Field Details

    • logger

      protected final transient org.slf4j.Logger logger
  • Constructor Details

    • BasicUserProfile

      public BasicUserProfile()

      Constructor for BasicUserProfile.

    • BasicUserProfile

      public BasicUserProfile(boolean canAttributesBeMerged)
      Create a profile with possibility to merge attributes with the same name and collection-type values.
      Parameters:
      canAttributesBeMerged - if true - merge attributes with the same name and collection-type values, if false - overwrite them
      Since:
      3.1.0
  • Method Details

    • build

      public void build(Object id, Map<String,Object> attributes)
      Build a profile from user identifier and attributes.
      Parameters:
      id - user identifier
      attributes - user attributes
    • build

      public void build(Object id, Map<String,Object> attributes, Map<String,Object> authenticationAttributes)
      Build a profile from user identifier, attributes, and authentication attributes.
      Parameters:
      id - user identifier
      attributes - user attributes
      authenticationAttributes - authentication attributes
    • setId

      public void setId(String id)

      setId.

      Set the identifier.
      Specified by:
      setId in interface UserProfile
      Parameters:
      id - a String object
    • getTypedId

      public String getTypedId()

      getTypedId.

      Get the user identifier with a prefix which is the profile type (full class name with package). This identifier is unique through all providers.
      Specified by:
      getTypedId in interface UserProfile
      Returns:
      a String object
    • getUsername

      public String getUsername()

      getUsername.

      Specified by:
      getUsername in interface UserProfile
      Returns:
      a String object
    • addAttribute

      public void addAttribute(String key, Object value)
      Description copied from interface: UserProfile

      addAttribute.

      Specified by:
      addAttribute in interface UserProfile
      Parameters:
      key - a String object
      value - a Object object
    • addAuthenticationAttribute

      public void addAuthenticationAttribute(String key, Object value)
      Description copied from interface: UserProfile

      addAuthenticationAttribute.

      Specified by:
      addAuthenticationAttribute in interface UserProfile
      Parameters:
      key - a String object
      value - a Object object
    • addAttributes

      public void addAttributes(Map<String,Object> attributes)
      Add attributes.
      Parameters:
      attributes - use attributes
    • addAuthenticationAttributes

      public void addAuthenticationAttributes(Map<String,Object> attributeMap)
      Add authentication attributes.
      Parameters:
      attributeMap - the authentication attributes
    • removeAttribute

      public void removeAttribute(String key)

      removeAttribute.

      Remove an attribute by its key.
      Specified by:
      removeAttribute in interface UserProfile
      Parameters:
      key - a String object
    • removeAuthenticationAttribute

      public void removeAuthenticationAttribute(String key)

      removeAuthenticationAttribute.

      Remove an authentication attribute by its key
      Specified by:
      removeAuthenticationAttribute in interface UserProfile
      Parameters:
      key - a String object
    • getAttributes

      public Map<String,Object> getAttributes()

      getAttributes.

      Get all attributes as immutable map.
      Specified by:
      getAttributes in interface UserProfile
      Returns:
      a Map object
    • getAuthenticationAttributes

      public Map<String,Object> getAuthenticationAttributes()
      Get all authentication attributes as an immutable map
      Returns:
      the immutable authentication attributes
    • getAttribute

      public Object getAttribute(String name)

      getAttribute.

      Return the attribute with name.
      Specified by:
      getAttribute in interface UserProfile
      Parameters:
      name - a String object
      Returns:
      a Object object
    • extractAttributeValues

      public List<String> extractAttributeValues(String name)
      Return the attribute values with name.
      Parameters:
      name - attribute name
      Returns:
      the attribute values as List of strings.
    • getAuthenticationAttribute

      public Object getAuthenticationAttribute(String name)
      Return the authentication attribute with name.
      Parameters:
      name - authentication attribute name
      Returns:
      the authentication attribute with name
    • containsAttribute

      public boolean containsAttribute(String name)

      containsAttribute.

      Check to see if profile contains attribute name.
      Specified by:
      containsAttribute in interface UserProfile
      Parameters:
      name - a String object
      Returns:
      a boolean
    • containsAuthenticationAttribute

      public boolean containsAuthenticationAttribute(String name)
      Check to see if profile contains attribute name.
      Parameters:
      name - the name
      Returns:
      true/false
    • getAttribute

      public <T> T getAttribute(String name, Class<T> clazz)
      Return the attribute with name.
      Type Parameters:
      T - the type of the attribute
      Parameters:
      name - the attribute name
      clazz - the class of the attribute
      Returns:
      the attribute by its name
      Since:
      1.8
    • getAuthenticationAttribute

      public <T> T getAuthenticationAttribute(String name, Class<T> clazz)
      Return authentication attribute with name
      Type Parameters:
      T - The type of the authentication attribute
      Parameters:
      name - Name of authentication attribute
      clazz - The class of the authentication attribute
      Returns:
      the named attribute
    • addRole

      public void addRole(String role)

      addRole.

      Add a role.
      Specified by:
      addRole in interface UserProfile
      Parameters:
      role - a String object
    • addRoles

      public void addRoles(Collection<String> roles)

      addRoles.

      Add roles.
      Specified by:
      addRoles in interface UserProfile
      Parameters:
      roles - a Collection object
    • getRoles

      public Set<String> getRoles()

      getRoles.

      Get the roles of the user.
      Specified by:
      getRoles in interface UserProfile
      Returns:
      a Set object
    • setRoles

      public void setRoles(Set<String> roles)

      Setter for the field roles.

      Parameters:
      roles - a Set object
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • removeLoginData

      public void removeLoginData()
      Remove the specific data retrieved during the login process to only keep the user attributes and roles.
    • isExpired

      public boolean isExpired()

      isExpired.

      Specified by:
      isExpired in interface UserProfile
      Returns:
      a boolean
    • asPrincipal

      public Principal asPrincipal()

      asPrincipal.

      Specified by:
      asPrincipal in interface UserProfile
      Returns:
      a Principal object