Class DefaultSessionInfo

java.lang.Object
org.tentackle.session.DefaultSessionInfo
All Implemented Interfaces:
Serializable, Cloneable, Immutable, SessionInfo

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

The password is encrypted if a Cryptor is configured.

Author:
harald
See Also:
  • Constructor Details

    • DefaultSessionInfo

      public DefaultSessionInfo(String username, char[] password, 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
      password - is the password, null if none
      propertiesName - name of the session's properties file, null if "backend"
    • DefaultSessionInfo

      public DefaultSessionInfo(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(org.tentackle.common.EncryptedProperties properties)
      Creates a session from a properties object.
      Parameters:
      properties - the properties
  • Method Details

    • equals

      public boolean equals(Object obj)
      Session infos are equal if their login credentials are equal.
      Overrides:
      equals in class 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 Object
    • isImmutable

      public boolean isImmutable()
      Specified by:
      isImmutable in interface Immutable
    • setImmutable

      public void setImmutable(boolean immutable)
      Specified by:
      setImmutable in interface Immutable
    • setFinallyImmutable

      public void setFinallyImmutable()
      Specified by:
      setFinallyImmutable in interface Immutable
    • isFinallyImmutable

      public boolean isFinallyImmutable()
      Specified by:
      isFinallyImmutable in interface Immutable
    • setImmutableLoggingLevel

      public void setImmutableLoggingLevel(Logger.Level immutableLoggingLevel)
      Specified by:
      setImmutableLoggingLevel in interface Immutable
    • getImmutableLoggingLevel

      public Logger.Level getImmutableLoggingLevel()
      Specified by:
      getImmutableLoggingLevel in interface 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, 0 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, 0 if not logged in
    • setUserName

      public void setUserName(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 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 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(String clientVersion)
      Description copied from interface: SessionInfo
      Sets the client's version.
      Specified by:
      setClientVersion in interface SessionInfo
      Parameters:
      clientVersion - the client version
    • getLocale

      public Locale getLocale()
      Description copied from interface: SessionInfo
      Gets the session's locale.
      Returns the JVM's default locale if not set explicitly via SessionInfo.setLocale(java.util.Locale).
      Specified by:
      getLocale in interface SessionInfo
      Returns:
      the locale, never null
    • setLocale

      public void setLocale(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 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(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 TimeZone getTimeZone()
      Description copied from interface: SessionInfo
      Gets the timezone.
      Specified by:
      getTimeZone in interface SessionInfo
      Returns:
      the timezone
    • setTimeZone

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

      public 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(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 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(String hostInfo)
      Description copied from interface: SessionInfo
      Sets the host info.
      Specified by:
      setHostInfo in interface SessionInfo
      Parameters:
      hostInfo - the info
    • toString

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

      public DefaultSessionInfo clone()
      Clones a session info.
      The password is copied, if not null.
      The properties are cloned as well.
      Cloned session infos are mutable by default and have no sessionName.
      Specified by:
      clone in interface SessionInfo
      Overrides:
      clone in class 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
      Clears the cloned flag.
      Useful if the session-info should no longer be treated as cloned.
      Specified by:
      clearCloned in interface SessionInfo
    • getPropertiesName

      public 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(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 org.tentackle.common.EncryptedProperties getProperties()
      Description copied from interface: SessionInfo
      Gets the connection properties.
      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 fails a PersistenceException is thrown.
      Specified by:
      getProperties in interface SessionInfo
      Returns:
      the connection properties, never null
    • setProperties

      public void setProperties(org.tentackle.common.EncryptedProperties 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, password and application-name from properties, if given.
      Specified by:
      applyProperties in interface SessionInfo
    • getApplicationName

      public 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(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
    • setSessionName

      public void setSessionName(String sessionName)
      Description copied from interface: SessionInfo
      Sets an optional session name.
      May be used to describe the purpose of the session.
      Specified by:
      setSessionName in interface SessionInfo
      Parameters:
      sessionName - the session name, null if none
    • getSessionName

      public String getSessionName()
      Description copied from interface: SessionInfo
      Gets the optional session name.
      Specified by:
      getSessionName in interface SessionInfo
      Returns:
      the name, null if none
    • checkServerVersion

      public void checkServerVersion(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 token-locks 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 token-locks are removed when session is closed.
      Specified by:
      setLockLingerEnabled in interface SessionInfo
      Parameters:
      enabled - true if leave locks untouched, false to remove locks
    • loadProperties

      protected org.tentackle.common.EncryptedProperties loadProperties(String propertiesName)
      Loads the properties.
      Parameters:
      propertiesName - the resource or filename
      Returns:
      the properties