Class AuthenticatedUser

  • All Implemented Interfaces:
    IBasicUserInfoDetailNames

    public class AuthenticatedUser
    extends java.lang.Object
    implements IBasicUserInfoDetailNames
    Instance holding data for the "authenticated" user. This instance can be retrieved also for non-authenticated users in the system, but the user information is available in the server's users database.
    Author:
    Christopher Mindus
    • Field Detail

      • UNDEFINED_USER_NAME

        public static final java.lang.String UNDEFINED_USER_NAME
        The user name for undefined user: "@undefined".
        See Also:
        Constant Field Values
      • ADMIN_USER_NAME

        public static final java.lang.String ADMIN_USER_NAME
        The user name for default administrator user: "iiziAdmin".
        See Also:
        Constant Field Values
      • ADMIN_BACKUP_USER_NAME

        public static final java.lang.String ADMIN_BACKUP_USER_NAME
        The user name for default backup administrator user: "iiziAdmin BACKUP".
        See Also:
        Constant Field Values
      • PROFILE_IMAGE_FILE_NAME_BASE

        public static final java.lang.String PROFILE_IMAGE_FILE_NAME_BASE
        The base name of the file name for profile images of a certain size. The name is "profileImage-WWxHH[-quality].[png|jpg]" where HH is the height and WW the width. The quality only applies for JPG images.
        See Also:
        Constant Field Values
      • UNDEFINED_USER_PROFILE_IMAGE

        public static final java.lang.String UNDEFINED_USER_PROFILE_IMAGE
        The file name for the undefined user profile image in huge format.
        See Also:
        Constant Field Values
      • ADMIN_PROFILE_IMAGE

        public static final java.lang.String ADMIN_PROFILE_IMAGE
        The file name for the undefined user profile image in huge format.
        See Also:
        Constant Field Values
      • ADMIN_BACKUP_PROFILE_IMAGE

        public static final java.lang.String ADMIN_BACKUP_PROFILE_IMAGE
        The file name for the undefined user profile image in huge format.
        See Also:
        Constant Field Values
      • userName

        public final java.lang.String userName
        The user name.
    • Method Detail

      • getUndefinedUserProfileImage

        public static java.io.File getUndefinedUserProfileImage()
                                                         throws java.io.FileNotFoundException
        Gets the file for the undefined profile image that can be used to create the requested sizes.
        Returns:
        The file, null if not found.
        Throws:
        java.io.FileNotFoundException
      • getUndefinedUserProfileImage

        public static java.io.File getUndefinedUserProfileImage​(java.io.File webServerRoot)
                                                         throws java.io.FileNotFoundException
        Gets the file for the undefined profile image that can be used to create the requested sizes.
        Parameters:
        webServerRoot - The root of the web server.
        Returns:
        The file, null if not found.
        Throws:
        java.io.FileNotFoundException
      • getUndefinedUser

        public static AuthenticatedUser getUndefinedUser()
        Gets the undefined "authenticated" user.
        Returns:
        The instance of the undefined "authenticated" user with its file provider.
      • markAccessed

        public void markAccessed()
        Marks the user as accessed and updates the "last access" time.
      • getLastAccessedTime

        public long getLastAccessedTime()
        Gets the last access time for the user.
        Returns:
        Time in millis since the epoch.
      • equals

        public boolean equals​(java.lang.Object o)
        Checks for equality.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - The object to compare with.
        Returns:
        When equals, false otherwise.
      • toString

        public java.lang.String toString()
        String representation of the class.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string with user and distance.
      • isUndefined

        public boolean isUndefined()
        Checks if this user is the "undefined" user that is used for external login. Once the user is authenticated by the external framework, a real user is assigned for the session.
        Returns:
        true if user is "undefined" and false for normal users.
      • getBasicUserInfo

        public BasicUserInfo getBasicUserInfo()
        Gets the basic user information that was last refreshed from the database.
        Returns:
        The basic user information, or null if user is the "undefined" user.
      • removeAccount

        public boolean removeAccount​(java.sql.Connection conn)
                              throws java.sql.SQLException,
                                     java.lang.IllegalStateException
        Removes the user from the database. The "iiziAdmin" and "iiziAdmin Backup" users cannot be removed.
        Parameters:
        conn - The connection.
        Returns:
        true for success, false if not found.
        Throws:
        java.sql.SQLException - For SQL errors.
        java.lang.IllegalStateException - If the basic user information is not present or if it's one of the admin users.
      • getLocationHistory

        public UserLocationHistory getLocationHistory()
        Gets the user's location history. The history is fed with locations from the background location service.
        Returns:
        An instance of the users locations history.
        Throws:
        java.lang.IllegalStateException - If this call is done when the information of the user is undefined.
      • getUserFileProvider

        public WSFileProvider getUserFileProvider()
                                           throws java.io.IOException
        Gets the user file provider for private user files such as images. The directory is created if required. Files placed in this directory can be published to the web for use in a user-local context by means of uniquely generated names to be used as URL's.
        Returns:
        The WSFileProvider with files in a directory.
        Throws:
        java.io.IOException - If the user private directory failed to be created.
        java.lang.IllegalStateException - If the WSFile engine is disposed (server has been stopped).
      • getUserFileProvider

        public WSFileProvider getUserFileProvider​(WSFileProviderEngine engine)
                                           throws java.io.IOException
        Gets the user file provider for private user files such as images. The directory is created if required. Files placed in this directory can be published to the web for use in a user-local context by means of uniquely generated names to be used as URL's.
        Parameters:
        engine - The file provider engine (when Designer creates a profile image).
        Returns:
        The WSFileProvider with files in a directory.
        Throws:
        java.io.IOException - If the user private directory failed to be created.
        java.lang.IllegalStateException - If the WSFile engine is disposed (server has been stopped).
      • loadAllUserFiles

        public java.util.Map<java.lang.String,​WSFile> loadAllUserFiles()
                                                                      throws java.io.IOException
        Loads the directory of all user files that are currently present and reserves the names in the WSFileProvider of this user.

        The key is the file name and the value is the WSFile with a reserved name ready for publishing, but not yet published.

        Returns:
        A map of the user files, where the key string is the file name without path and the value is the WSFile instance.
        Throws:
        java.io.IOException - If the user private directory failed to be created or the directory failed to list its files.
      • setProfileImage

        public WSFile setProfileImage​(java.sql.Connection conn,
                                      java.lang.String detail,
                                      java.io.File imageFile)
                               throws java.io.IOException,
                                      java.sql.SQLException
        Sets a new profile image for the user. A previous image file is upon success deleted and unpublished. The new image file is not published.
        Parameters:
        conn - The connection.
        detail - The image detail: IBasicUserInfoDetailNames.DETAIL_UploadedProfileImage, IBasicUserInfoDetailNames.DETAIL_ThumbnailProfileImage or IBasicUserInfoDetailNames.DETAIL_LargeProfileImage.
        imageFile - The new profile image located inside the files provider.
        Returns:
        The WSFile created.
        Throws:
        java.io.IOException - For I/O errors.
        java.sql.SQLException - For SQL errors.
        NotFoundException - If the file doesn't exist.
        java.lang.IllegalArgumentException - If the file parent is not this providers root directory.
        java.lang.IllegalArgumentException - If the detail is not valid.
        java.lang.IllegalStateException - If the WSFile engine is disposed (server has been stopped), or if the user is undefined.
      • getProfileImageName

        public java.lang.String getProfileImageName​(int width,
                                                    int height,
                                                    int quality)
        Gets the name of the profile image for this particular user. This name is typically used in the AppSessionGyro instance to hold images for multiple users.
        Parameters:
        width - The width requested (minimum 16, maximum 400).
        height - The height requested (minimum 16, maximum 400).
        quality - JPG quality 0-100, if zero a PNG is used. 100 means loss-less and 1 means really bad quality.
        Returns:
        The image name.
      • getProfileImage

        public RuntimeImageDefinition getProfileImage​(IClientSessionGyro clientGyro,
                                                      int width,
                                                      int height,
                                                      int quality)
                                               throws java.io.IOException
        Gets the profile image for the user scaled to the requested size. The image is created and cached in the requested size if not available. The Device Pixel Ratio is taken from the client session gyro.
        Parameters:
        clientGyro - The client session gyro.
        width - The width requested (minimum 16, maximum 400).
        height - The height requested (minimum 16, maximum 400).
        quality - JPG quality 0-100, if zero a PNG is used. 100 means loss-less and 1 means really bad quality.
        Returns:
        The image definition, or null if a profile image is not available.
        Throws:
        java.io.IOException - For file I/O errors.
        java.lang.IllegalArgumentException - If the width, height or quality is invalid, or if DPR=1 is not present.
      • getProfileImage

        public RuntimeImageDefinition getProfileImage​(IAppSessionGyro appGyro,
                                                      int width,
                                                      int height,
                                                      int quality,
                                                      boolean createDefault)
                                               throws java.io.IOException
        Gets the profile image for the user scaled to the requested size. The image is created and cached in the requested size if not available.

        This method will create images for the most common DPR's: 1, 1.5, 2, 3, and 4.

        Profile images runtime definition is cached in the instance of the app session gyro.

        Parameters:
        appGyro - The application session gyro.
        width - The width requested (minimum 16, maximum 400).
        height - The height requested (minimum 16, maximum 400).
        quality - JPG quality 0-100, if zero a PNG is used. 100 means loss-less and 1 means really bad quality.
        createDefault - Flag indicating the image will be created from the undefined profile image if no image is present.
        Returns:
        The image definition, or null if a profile image is not available.
        Throws:
        java.io.IOException - For file I/O errors.
        java.lang.IllegalArgumentException - If the width, height or quality is invalid, or if DPR=1 is not present.
      • getProfileImage

        public RuntimeImageDefinition getProfileImage​(int width,
                                                      int height,
                                                      int quality,
                                                      boolean createDefault)
                                               throws java.io.IOException
        Gets the profile image for the user scaled to the requested size. The image is created and cached in the requested size if not available.

        This method will create images for the most common DPR's: 1, 1.5, 2, 3, and 4.

        Profile images runtime definition is cached in this instance of the authenticated user.

        Parameters:
        width - The width requested (minimum 16, maximum 400).
        height - The height requested (minimum 16, maximum 400).
        quality - JPG quality 0-100, if zero a PNG is used. 100 means loss-less and 1 means really bad quality.
        createDefault - Flag indicating the image will be created from the undefined profile image if no image is present.
        Returns:
        The image definition, or null if a profile image is not available.
        Throws:
        java.io.IOException - For file I/O errors.
        java.lang.IllegalArgumentException - If the width, height or quality is invalid, or if DPR=1 is not present.
      • getProfilePictureFile

        public java.io.File getProfilePictureFile()
                                           throws java.io.IOException
        Gets the File for the full profile picture, or any lower resolution(s) if the full profile picture is not found.
        Returns:
        File The file for the profile picture, or null if it doesn't exist.
        Throws:
        java.io.IOException - If the file provider for the user or its root directory fails retrieving.
      • getProfilePictureFile

        public java.io.File getProfilePictureFile​(java.lang.String[] rcDetail)
                                           throws java.io.IOException
        Gets the File for the full profile picture, or any lower resolution(s) if the full profile picture is not found.
        Parameters:
        rcDetail - The detail of the file, must be an array of length 1, or null. Upon return and a file is found, the rcDetail[0] contains the value IBasicUserInfoDetailNames.DETAIL_UploadedProfileImage, IBasicUserInfoDetailNames.DETAIL_UploadedProfileImage or IBasicUserInfoDetailNames.DETAIL_UploadedProfileImage. If a file is not found, it is set to null (if array is not null).
        Returns:
        File The file for the profile picture, or null if it doesn't exist.
        Throws:
        java.io.IOException - If the file provider for the user or its root directory fails retrieving.