Class ProfileManager


  • public class ProfileManager
    extends java.lang.Object
    This class is a generic way to manage the current user profile(s), i.e. the one(s) of the current authenticated user.
    Since:
    1.8.0
    Author:
    Jerome Leleu
    • Field Detail

      • logger

        protected final org.slf4j.Logger logger
      • config

        protected Config config
    • Method Detail

      • getProfile

        public java.util.Optional<UserProfile> getProfile()
        Retrieve the first user profile if it exists, ignoring any AnonymousProfile if possible.
        Returns:
        the user profile
      • getProfile

        public <U extends UserProfile> java.util.Optional<U> getProfile​(java.lang.Class<U> clazz)
      • getProfiles

        public java.util.List<UserProfile> getProfiles()
        Retrieve all user profiles.
        Returns:
        the user profiles
      • retrieveAll

        protected java.util.LinkedHashMap<java.lang.String,​UserProfile> retrieveAll​(boolean readFromSession)
        Retrieve the map of profiles from the session or the request.
        Parameters:
        readFromSession - if the user profiles must be read from session
        Returns:
        the map of profiles
      • removeOrRenewExpiredProfiles

        protected void removeOrRenewExpiredProfiles​(java.util.LinkedHashMap<java.lang.String,​UserProfile> profiles,
                                                    boolean readFromSession)
      • removeProfiles

        public void removeProfiles()
        Remove the current user profile(s).
      • save

        public void save​(boolean saveInSession,
                         UserProfile profile,
                         boolean multiProfile)
        Save the given user profile (replace the current one if multi profiles are not supported, add it otherwise).
        Parameters:
        saveInSession - if the user profile must be saved in session
        profile - a given user profile
        multiProfile - whether multiple profiles are supported
      • retrieveClientName

        protected java.lang.String retrieveClientName​(UserProfile profile)
      • saveAll

        protected void saveAll​(java.util.LinkedHashMap<java.lang.String,​UserProfile> profiles,
                               boolean saveInSession)
      • isAuthenticated

        public boolean isAuthenticated()
        Tests if the current user is authenticated (meaning a user profile exists which is not an AnonymousProfile).
        Returns:
        whether the current user is authenticated
      • getConfig

        public Config getConfig()
      • setConfig

        public void setConfig​(Config config)