Class AbstractProfileService<U extends CommonProfile>

All Implemented Interfaces:
Authenticator, ProfileService<U>
Direct Known Subclasses:
InMemoryProfileService

public abstract class AbstractProfileService<U extends CommonProfile> extends ProfileDefinitionAware implements ProfileService<U>, Authenticator
Abstract implementation of the ProfileService for the storage: LDAP, SQL and MongoDB.
Since:
2.0.0
Author:
Jerome Leleu
  • Field Details

  • Constructor Details

    • AbstractProfileService

      public AbstractProfileService()
  • Method Details

    • internalInit

      protected void internalInit(boolean forceReinit)
      Description copied from class: InitializableObject
      Internal initialization of the object.
      Specified by:
      internalInit in class InitializableObject
    • create

      public void create(U profile, String password)
      Description copied from interface: ProfileService
      Create a profile with the associated password in the storage.
      Specified by:
      create in interface ProfileService<U extends CommonProfile>
      Parameters:
      profile - the profile
      password - the password
    • update

      public void update(U profile, String password)
      Description copied from interface: ProfileService
      Update a profile (with the associated password) in the storage.
      Specified by:
      update in interface ProfileService<U extends CommonProfile>
      Parameters:
      profile - the profile
      password - the optional password
    • remove

      public void remove(U profile)
      Description copied from interface: ProfileService
      Rmove a profile in the storage.
      Specified by:
      remove in interface ProfileService<U extends CommonProfile>
      Parameters:
      profile - the profile
    • removeById

      public void removeById(String id)
      Description copied from interface: ProfileService
      Remove a profile by its identifier in the storage.
      Specified by:
      removeById in interface ProfileService<U extends CommonProfile>
      Parameters:
      id - the profile identifier
    • convertProfileAndPasswordToAttributes

      protected Map<String,Object> convertProfileAndPasswordToAttributes(U profile, String password)
      Convert a profile and a password into a map of attributes for the storage.
      Parameters:
      profile - the profile
      password - the password
      Returns:
      the attributes
    • insert

      protected abstract void insert(Map<String,Object> attributes)
      Insert the attributes in the storage.
      Parameters:
      attributes - the attributes
    • update

      protected abstract void update(Map<String,Object> attributes)
      Update the attributes in the storage.
      Parameters:
      attributes - the attributes
    • deleteById

      protected abstract void deleteById(String id)
      Delete a profile by its identifier in the storage.
      Parameters:
      id - the identifier
    • findById

      public U findById(String id)
      Description copied from interface: ProfileService
      Find a profile by its identifier.
      Specified by:
      findById in interface ProfileService<U extends CommonProfile>
      Parameters:
      id - the identifier
      Returns:
      the found profile
    • findByLinkedId

      public U findByLinkedId(String linkedId)
      Description copied from interface: ProfileService
      Find a profile by its linked identifier.
      Specified by:
      findByLinkedId in interface ProfileService<U extends CommonProfile>
      Parameters:
      linkedId - the linked identifier
      Returns:
      the found profile
    • defineAttributesToRead

      protected List<String> defineAttributesToRead()
      Define the attributes to read in the storage.
      Returns:
      the attributes
    • convertAttributesToProfile

      protected U convertAttributesToProfile(List<Map<String,Object>> listStorageAttributes, String username)
      Convert the list of map of attributes from the storage into a profile.
      Parameters:
      listStorageAttributes - the list of map of attributes
      username - the username used for login
      Returns:
      the profile
    • read

      protected abstract List<Map<String,Object>> read(List<String> names, String key, String value)
      Read the list of defined attributes in the storage for key=value query.
      Parameters:
      names - the attribute names to read
      key - the key for the query
      value - the value for the query
      Returns:
      the list of map of attributes
    • validate

      public void validate(Credentials cred, WebContext context, SessionStore sessionStore)
      Description copied from interface: Authenticator
      Validate the credentials. It should throw a CredentialsException in case of failure.
      Specified by:
      validate in interface Authenticator
      Parameters:
      cred - the given credentials
      context - the web context
      sessionStore - the session store
    • isLegacyMode

      protected boolean isLegacyMode()
    • getPasswordEncoder

      public PasswordEncoder getPasswordEncoder()
    • setPasswordEncoder

      public void setPasswordEncoder(PasswordEncoder passwordEncoder)
    • getAttributes

      public String getAttributes()
    • setAttributes

      public void setAttributes(String attributes)

      Since version 2.0 of pac4j, the profile can be saved, updated and deleted in the storage by serializing the profile (in the serializedprofile attribute).

      In addition to what existed in previous versions, the profile was built from existing attributes. Setting this attribute with a list of attributes separated by commas (no aliasing) allows you to use different attributes of the storage instead of the serializedprofile attribute.

      Parameters:
      attributes - the attributes
    • getSerializer

      public Serializer getSerializer()
    • setSerializer

      public void setSerializer(Serializer serializer)
    • getUsernameAttribute

      public String getUsernameAttribute()
    • setUsernameAttribute

      public void setUsernameAttribute(String usernameAttribute)
    • getPasswordAttribute

      public String getPasswordAttribute()
    • setPasswordAttribute

      public void setPasswordAttribute(String passwordAttribute)
    • getIdAttribute

      public String getIdAttribute()
    • setIdAttribute

      public void setIdAttribute(String idAttribute)