Class DefaultSessionInfo

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.tentackle.misc.Immutable, SessionInfo

    public class DefaultSessionInfo
    extends java.lang.Object
    implements SessionInfo, java.lang.Cloneable
    The default implementation for a session info.

    The password is encrypted if a Cryptor is configured.

    Author:
    harald
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultSessionInfo()
      Creates a session info from the default properties file.
      The property file's name is "backend".
      DefaultSessionInfo​(java.lang.String propertiesName)
      Creates a session info from a property file holding the connection parameters.
      DefaultSessionInfo​(java.lang.String username, char[] password, java.lang.String propertiesName)
      Creates a session info from an optional username, optional password and a property file holding the connection parameters.
      DefaultSessionInfo​(java.util.Properties properties)
      Creates a session from a properties object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applyProperties()
      Applies the properties to this session info.
      Sets user and password from properties, if given.
      protected void assertMutable()
      Asserts that this session info is mutable.
      void checkServerVersion​(java.lang.String serverVersion)
      Checks the version of the server.
      void clearCloned()
      Cleares the cloned flag.
      void clearPassword()
      Clears the password.
      Will remove it from memory by overwriting each element in the character array.
      DefaultSessionInfo clone()
      Clones a userinfo.
      The password is copied, if not null.
      The properties are cloned as well.
      Cloned session infos are mutable by default.
      boolean equals​(java.lang.Object obj)
      Session infos are equal if their login credentials are equal.
      long getApplicationId()
      Returns the application id.
      java.lang.String getApplicationName()
      Gets the name of the application.
      java.lang.String getClientVersion()
      Gets the client version.
      java.lang.String getHostInfo()
      Gets the host info.
      org.tentackle.log.Logger.Level getImmutableLoggingLevel()  
      java.util.Locale getLocale()
      Gets the session's locale.
      Returns the JVM's default locale if not set explicitly via SessionInfo.setLocale(java.util.Locale).
      java.lang.String getOsInfo()
      Gets the operating system info.
      char[] getPassword()
      Gets the password.
      java.util.Properties getProperties()
      Gets the connection properties.
      The the properties are not set so far, the method will load the properties file by adding the extension ".properties" to SessionInfo.getPropertiesName() (if it does not contain an extension already).
      If there is no such file, the properties will be read as a resource according to the classpath.
      If all failes a PersistenceException is thrown.
      java.lang.String getPropertiesName()
      Gets the name of the property file.
      long getSince()
      Gets the epochal time since when logged in.
      java.util.TimeZone getTimeZone()
      Gets the timezone.
      int getUserClassId()
      Gets the class id of the current user.
      long getUserId()
      Gets the user id.
      java.lang.String getUserName()
      Gets the username.
      java.lang.String getVmInfo()
      Gets the info string describing the JVM.
      int hashCode()  
      boolean isCloned()
      Checks whether this session info is cloned.
      boolean isFinallyImmutable()  
      boolean isImmutable()  
      boolean isLockLingerEnabled()
      Determines whether tokenlocks are removed when session is closed.
      By default, locks are not removed for cloned sessions.
      void setApplicationId​(long applicationId)
      Sets the application id.
      Should be unique among the same application name.
      void setApplicationName​(java.lang.String application)
      Sets the name of the application.
      void setClientVersion​(java.lang.String clientVersion)
      Sets the client's version.
      void setFinallyImmutable()  
      void setHostInfo​(java.lang.String hostInfo)
      Sets the host info.
      void setImmutable​(boolean immutable)  
      void setImmutableLoggingLevel​(org.tentackle.log.Logger.Level immutableLoggingLevel)  
      void setLocale​(java.util.Locale locale)
      Sets the session's locale.
      void setLockLingerEnabled​(boolean enabled)
      Sets whether tokenlocks are removed when session is closed.
      void setOsInfo​(java.lang.String osInfo)
      Sets the operating system info.
      void setPassword​(char[] password)
      Sets the password.
      void setProperties​(java.util.Properties properties)
      Sets the connection properties.
      void setPropertiesName​(java.lang.String propertiesName)
      Sets the name of the property file.
      (without the extension .properties)
      void setSince​(long since)
      Sets the epochal time since when logged in.
      void setTimeZone​(java.util.TimeZone timeZone)
      Sets the timezone.
      void setUserClassId​(int userClassId)
      Sets the class id of the current user.
      void setUserId​(long userId)
      Sets the user id.
      void setUserName​(java.lang.String userName)
      Sets the username.
      void setVmInfo​(java.lang.String vmInfo)
      Sets the info string describing the JVM.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DefaultSessionInfo

        public DefaultSessionInfo​(java.lang.String username,
                                  char[] password,
                                  java.lang.String propertiesName)
        Creates a session info from an optional username, optional password and a property file holding the connection parameters.
        Parameters:
        username - is the name of the user, null if System.getProperty("user.name")
        password - is the password, null if none
        propertiesName - name of the session's properties file, null if "backend"
      • DefaultSessionInfo

        public DefaultSessionInfo​(java.lang.String propertiesName)
        Creates a session info from a property file holding the connection parameters.
        Parameters:
        propertiesName - name of the session's properties file, null if "backend"
      • DefaultSessionInfo

        public DefaultSessionInfo()
        Creates a session info from the default properties file.
        The property file's name is "backend".
      • DefaultSessionInfo

        public DefaultSessionInfo​(java.util.Properties properties)
        Creates a session from a properties object.
        Parameters:
        properties - the properties
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        Session infos are equal if their login credentials are equal.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other object
        Returns:
        true if obj is a SessionInfo and belongs to the same 'user'
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isImmutable

        public boolean isImmutable()
        Specified by:
        isImmutable in interface org.tentackle.misc.Immutable
      • setImmutable

        public void setImmutable​(boolean immutable)
        Specified by:
        setImmutable in interface org.tentackle.misc.Immutable
      • setFinallyImmutable

        public void setFinallyImmutable()
        Specified by:
        setFinallyImmutable in interface org.tentackle.misc.Immutable
      • isFinallyImmutable

        public boolean isFinallyImmutable()
        Specified by:
        isFinallyImmutable in interface org.tentackle.misc.Immutable
      • setImmutableLoggingLevel

        public void setImmutableLoggingLevel​(org.tentackle.log.Logger.Level immutableLoggingLevel)
        Specified by:
        setImmutableLoggingLevel in interface org.tentackle.misc.Immutable
      • getImmutableLoggingLevel

        public org.tentackle.log.Logger.Level getImmutableLoggingLevel()
        Specified by:
        getImmutableLoggingLevel in interface org.tentackle.misc.Immutable
      • assertMutable

        protected void assertMutable()
        Asserts that this session info is mutable.
      • setSince

        public void setSince​(long since)
        Description copied from interface: SessionInfo
        Sets the epochal time since when logged in.
        Specified by:
        setSince in interface SessionInfo
        Parameters:
        since - logged in since, null if not logged in
      • getSince

        public long getSince()
        Description copied from interface: SessionInfo
        Gets the epochal time since when logged in.
        Specified by:
        getSince in interface SessionInfo
        Returns:
        logged in since, null if not logged in
      • setUserName

        public void setUserName​(java.lang.String userName)
        Description copied from interface: SessionInfo
        Sets the username.
        Specified by:
        setUserName in interface SessionInfo
        Parameters:
        userName - the name of the user
      • getUserName

        public java.lang.String getUserName()
        Description copied from interface: SessionInfo
        Gets the username.
        Specified by:
        getUserName in interface SessionInfo
        Returns:
        the username
      • setPassword

        public void setPassword​(char[] password)
        Description copied from interface: SessionInfo
        Sets the password.
        Specified by:
        setPassword in interface SessionInfo
        Parameters:
        password - the password
      • getPassword

        public char[] getPassword()
        Description copied from interface: SessionInfo
        Gets the password.
        Specified by:
        getPassword in interface SessionInfo
        Returns:
        the password
      • clearPassword

        public void clearPassword()
        Description copied from interface: SessionInfo
        Clears the password.
        Will remove it from memory by overwriting each element in the character array.
        Specified by:
        clearPassword in interface SessionInfo
      • getClientVersion

        public java.lang.String getClientVersion()
        Description copied from interface: SessionInfo
        Gets the client version.
        Specified by:
        getClientVersion in interface SessionInfo
        Returns:
        the client version
      • setClientVersion

        public void setClientVersion​(java.lang.String clientVersion)
        Description copied from interface: SessionInfo
        Sets the client's version.
        Specified by:
        setClientVersion in interface SessionInfo
        Parameters:
        clientVersion - the client version
      • setLocale

        public void setLocale​(java.util.Locale locale)
        Description copied from interface: SessionInfo
        Sets the session's locale.
        Specified by:
        setLocale in interface SessionInfo
        Parameters:
        locale - the locale, null to use JVM's locale
      • getVmInfo

        public java.lang.String getVmInfo()
        Description copied from interface: SessionInfo
        Gets the info string describing the JVM.
        Specified by:
        getVmInfo in interface SessionInfo
        Returns:
        the jvm info
      • setVmInfo

        public void setVmInfo​(java.lang.String vmInfo)
        Description copied from interface: SessionInfo
        Sets the info string describing the JVM.
        Specified by:
        setVmInfo in interface SessionInfo
        Parameters:
        vmInfo - the jvm info
      • getTimeZone

        public java.util.TimeZone getTimeZone()
        Description copied from interface: SessionInfo
        Gets the timezone.
        Specified by:
        getTimeZone in interface SessionInfo
        Returns:
        the timezone
      • setTimeZone

        public void setTimeZone​(java.util.TimeZone timeZone)
        Description copied from interface: SessionInfo
        Sets the timezone.
        Specified by:
        setTimeZone in interface SessionInfo
        Parameters:
        timeZone - the timezone
      • getOsInfo

        public java.lang.String getOsInfo()
        Description copied from interface: SessionInfo
        Gets the operating system info.
        Specified by:
        getOsInfo in interface SessionInfo
        Returns:
        the OS info
      • setOsInfo

        public void setOsInfo​(java.lang.String osInfo)
        Description copied from interface: SessionInfo
        Sets the operating system info.
        Specified by:
        setOsInfo in interface SessionInfo
        Parameters:
        osInfo - the OS info
      • getHostInfo

        public java.lang.String getHostInfo()
        Description copied from interface: SessionInfo
        Gets the host info.
        Specified by:
        getHostInfo in interface SessionInfo
        Returns:
        the hostname or similar info
      • setHostInfo

        public void setHostInfo​(java.lang.String hostInfo)
        Description copied from interface: SessionInfo
        Sets the host info.
        Specified by:
        setHostInfo in interface SessionInfo
        Parameters:
        hostInfo - the info
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • clone

        public DefaultSessionInfo clone()
        Clones a userinfo.
        The password is copied, if not null.
        The properties are cloned as well.
        Cloned session infos are mutable by default.
        Specified by:
        clone in interface SessionInfo
        Overrides:
        clone in class java.lang.Object
        Returns:
        the cloned session info
      • isCloned

        public boolean isCloned()
        Description copied from interface: SessionInfo
        Checks whether this session info is cloned.
        Specified by:
        isCloned in interface SessionInfo
        Returns:
        true if cloned
      • clearCloned

        public void clearCloned()
        Description copied from interface: SessionInfo
        Cleares the cloned flag. Useful if the sessioninfo should no longer be treated as cloned.
        Specified by:
        clearCloned in interface SessionInfo
      • getPropertiesName

        public java.lang.String getPropertiesName()
        Description copied from interface: SessionInfo
        Gets the name of the property file.
        Specified by:
        getPropertiesName in interface SessionInfo
        Returns:
        the filename
      • setPropertiesName

        public void setPropertiesName​(java.lang.String propertiesName)
        Description copied from interface: SessionInfo
        Sets the name of the property file.
        (without the extension .properties)
        Specified by:
        setPropertiesName in interface SessionInfo
        Parameters:
        propertiesName - the filename
      • getProperties

        public java.util.Properties getProperties()
        Description copied from interface: SessionInfo
        Gets the connection properties.
        The the properties are not set so far, the method will load the properties file by adding the extension ".properties" to SessionInfo.getPropertiesName() (if it does not contain an extension already).
        If there is no such file, the properties will be read as a resource according to the classpath.
        If all failes a PersistenceException is thrown.
        Specified by:
        getProperties in interface SessionInfo
        Returns:
        the connection properties, never null
      • setProperties

        public void setProperties​(java.util.Properties properties)
        Description copied from interface: SessionInfo
        Sets the connection properties.
        Specified by:
        setProperties in interface SessionInfo
        Parameters:
        properties - the connection properties.
      • applyProperties

        public void applyProperties()
        Description copied from interface: SessionInfo
        Applies the properties to this session info.
        Sets user and password from properties, if given.
        Specified by:
        applyProperties in interface SessionInfo
      • getApplicationName

        public java.lang.String getApplicationName()
        Description copied from interface: SessionInfo
        Gets the name of the application.
        Specified by:
        getApplicationName in interface SessionInfo
        Returns:
        the name, null if none
      • setApplicationName

        public void setApplicationName​(java.lang.String application)
        Description copied from interface: SessionInfo
        Sets the name of the application.
        Specified by:
        setApplicationName in interface SessionInfo
        Parameters:
        application - the name
      • setApplicationId

        public void setApplicationId​(long applicationId)
        Description copied from interface: SessionInfo
        Sets the application id.
        Should be unique among the same application name.
        Specified by:
        setApplicationId in interface SessionInfo
        Parameters:
        applicationId - the optional application id
      • getApplicationId

        public long getApplicationId()
        Description copied from interface: SessionInfo
        Returns the application id.
        Specified by:
        getApplicationId in interface SessionInfo
        Returns:
        the id, 0 if none
      • checkServerVersion

        public void checkServerVersion​(java.lang.String serverVersion)
        Description copied from interface: SessionInfo
        Checks the version of the server.

        The default implementation does nothing.

        Specified by:
        checkServerVersion in interface SessionInfo
        Parameters:
        serverVersion - the server's version
      • getUserId

        public long getUserId()
        Description copied from interface: SessionInfo
        Gets the user id.
        Specified by:
        getUserId in interface SessionInfo
        Returns:
        the object Id of the current user
      • setUserId

        public void setUserId​(long userId)
        Description copied from interface: SessionInfo
        Sets the user id.
        Specified by:
        setUserId in interface SessionInfo
        Parameters:
        userId - the object ID of the user
      • getUserClassId

        public int getUserClassId()
        Description copied from interface: SessionInfo
        Gets the class id of the current user.
        Specified by:
        getUserClassId in interface SessionInfo
        Returns:
        the class id
      • setUserClassId

        public void setUserClassId​(int userClassId)
        Description copied from interface: SessionInfo
        Sets the class id of the current user.
        Specified by:
        setUserClassId in interface SessionInfo
        Parameters:
        userClassId - the class id
      • isLockLingerEnabled

        public boolean isLockLingerEnabled()
        Description copied from interface: SessionInfo
        Determines whether tokenlocks are removed when session is closed.
        By default, locks are not removed for cloned sessions.
        Specified by:
        isLockLingerEnabled in interface SessionInfo
        Returns:
        true if leave locks untouched, false to remove locks
      • setLockLingerEnabled

        public void setLockLingerEnabled​(boolean enabled)
        Description copied from interface: SessionInfo
        Sets whether tokenlocks are removed when session is closed.
        Specified by:
        setLockLingerEnabled in interface SessionInfo
        Parameters:
        enabled - true if leave locks untouched, false to remove locks