Class AuthenticatedUser

java.lang.Object
com.iizix.server.user.AuthenticatedUser
All Implemented Interfaces:
IAuthenticatedUser, IBasicUserInfoDetailNames

public class AuthenticatedUser extends Object implements IBasicUserInfoDetailNames, IAuthenticatedUser
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 Details

    • PROFILE_IMAGE_FILE_NAME_BASE

      public static final 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:
    • UNDEFINED_USER_PROFILE_IMAGE

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

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

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

      public final String userName
      The user name.
  • Method Details

    • getUndefinedUserProfileImage

      public static File getUndefinedUserProfileImage() throws 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:
      FileNotFoundException
    • getUndefinedUserProfileImage

      public static File getUndefinedUserProfileImage(File webServerRoot) throws 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:
      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.
      Specified by:
      getLastAccessedTime in interface IAuthenticatedUser
      Returns:
      Time in millis since the epoch.
    • hashCode

      public int hashCode()
      Gets the hash code of this instance.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code.
    • equals

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

      public String toString()
      String representation of the class.
      Overrides:
      toString in class 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.
      Specified by:
      isUndefined in interface IAuthenticatedUser
      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.
      Specified by:
      getBasicUserInfo in interface IAuthenticatedUser
      Returns:
      The basic user information, or null if user is the "undefined" user.
    • removeAccount

      public boolean removeAccount(Connection conn) throws SQLException, 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:
      SQLException - For SQL errors.
      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.
      Specified by:
      getLocationHistory in interface IAuthenticatedUser
      Returns:
      An instance of the users locations history.
      Throws:
      IllegalStateException - If this call is done when the information of the user is undefined.
    • getUserFileProvider

      public WSFileProvider getUserFileProvider() throws 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:
      IOException - If the user private directory failed to be created.
      IllegalStateException - If the WSFileProvider is disposed (server has been stopped).
    • getUserFileProvider

      public WSFileProvider getUserFileProvider(WSFileProviderEngine engine) throws IOException
      Gets the user file provider for database backup up user files such as images. The cache 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:
      IOException - If the user private directory failed to be created.
      IllegalStateException - If the WSFileProvider is disposed (server has been stopped).
    • loadAllUserFiles

      public Map<String,IWSFile> loadAllUserFiles() throws 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 IWSFile 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 IWSFile instance.
      Throws:
      IOException - If the user private directory failed to be created or the directory failed to list its files.
    • setProfileImage

      public IWSFile setProfileImage(Connection conn, String detail, File imageFile) throws IOException, 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 IWSFile created.
      Throws:
      IOException - For I/O errors.
      SQLException - For SQL errors.
      NotFoundException - If the file doesn't exist.
      IllegalArgumentException - If the file parent is not this providers root directory.
      IllegalArgumentException - If the detail is not valid.
      IllegalStateException - If the WSFileProvider is disposed (server has been stopped), or if the user is undefined.
    • setProfileImage

      public IWSFile setProfileImage(WSFileProviderEngine engine, Connection conn, String detail, File imageFile) throws IOException, 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. If you set the detail to IBasicUserInfoDetailNames.DETAIL_UploadedProfileImage, the two others IBasicUserInfoDetailNames.DETAIL_LargeProfileImage and IBasicUserInfoDetailNames.DETAIL_ThumbnailProfileImage will be removed.
      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 IWSFile created.
      Throws:
      IOException - For I/O errors.
      SQLException - For SQL errors.
      NotFoundException - If the file doesn't exist.
      IllegalArgumentException - If the file parent is not this providers root directory.
      IllegalArgumentException - If the detail is not valid.
      IllegalStateException - If the WSFileProvider is disposed (server has been stopped), or if the user is undefined.
    • getProfileImageName

      public 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.
    • getProfileImageName

      public String getProfileImageName(int width, int height, int quality, int rounded)
      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.
      rounded - Rounded corners pixel value: if -1 half the width and height is used as rounding values, otherwise zero means no rounded corners (keep rectangular corners), or a pixel value if greater than zero.
      Returns:
      The image name.
    • getProfileImage

      public RuntimeImageDefinition getProfileImage(IClientSessionGyro clientGyro, int width, int height, int quality) throws 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:
      IOException - For file I/O errors.
      IllegalArgumentException - If the width, height or quality is invalid, or if DPR=1 is not present.
    • getProfileImage

      public RuntimeImageDefinition getProfileImage(IClientSessionGyro clientGyro, int width, int height, int quality, int rounded) throws 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.
      rounded - Value for rounded corners in pixels. If zero, rectangular corners are used. The special value -1 will round the corners to half the width and height. if rounded is greater than zero, it will be the rounding value in pixels of the corners. If a rounding value is used, it is multiplied with the DPR used for the created image.
      Returns:
      The image definition, or null if a profile image is not available.
      Throws:
      IOException - For file I/O errors.
      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 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:
      IOException - For file I/O errors.
      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, int rounded) throws 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.
      rounded - Value for rounded corners in pixels. If zero, rectangular corners are used. The special value -1 will round the corners to half the width and height. if rounded is greater than zero, it will be the rounding value in pixels of the corners. If a rounding value is used, it is multiplied with the DPR used for the created image.
      Returns:
      The image definition, or null if a profile image is not available.
      Throws:
      IOException - For file I/O errors.
      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 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:
      IOException - For file I/O errors.
      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, int rounded) throws 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.
      rounded - Value for rounded corners in pixels. If zero, rectangular corners are used. The special value -1 will round the corners to half the width and height. if rounded is greater than zero, it will be the rounding value in pixels of the corners. If a rounding value is used, it is multiplied with the DPR used for the created image.
      Returns:
      The image definition, or null if a profile image is not available.
      Throws:
      IOException - For file I/O errors.
      IllegalArgumentException - If the width, height or quality is invalid, or if DPR=1 is not present.
    • getProfilePictureFile

      public File getProfilePictureFile() throws 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:
      IOException - If the file provider for the user or its root directory fails retrieving.
    • getProfilePictureFile

      public File getProfilePictureFile(String[] rcDetail) throws 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:
      IOException - If the file provider for the user or its root directory fails retrieving.
    • getProfilePictureFile

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