- java.lang.Object
-
- org.tentackle.session.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
Cryptoris 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 voidapplyProperties()Applies the properties to this session info.
Sets user and password from properties, if given.protected voidassertMutable()Asserts that this session info is mutable.voidcheckServerVersion(java.lang.String serverVersion)Checks the version of the server.voidclearCloned()Cleares the cloned flag.voidclearPassword()Clears the password.
Will remove it from memory by overwriting each element in the character array.DefaultSessionInfoclone()Clones a userinfo.
The password is copied, if not null.
The properties are cloned as well.
Cloned session infos are mutable by default.booleanequals(java.lang.Object obj)Session infos are equal if their login credentials are equal.longgetApplicationId()Returns the application id.java.lang.StringgetApplicationName()Gets the name of the application.java.lang.StringgetClientVersion()Gets the client version.java.lang.StringgetHostInfo()Gets the host info.org.tentackle.log.Logger.LevelgetImmutableLoggingLevel()java.util.LocalegetLocale()Gets the session's locale.
Returns the JVM's default locale if not set explicitly viaSessionInfo.setLocale(java.util.Locale).java.lang.StringgetOsInfo()Gets the operating system info.char[]getPassword()Gets the password.java.util.PropertiesgetProperties()Gets the connection properties.
The the properties are not set so far, the method will load the properties file by adding the extension".properties"toSessionInfo.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 aPersistenceExceptionis thrown.java.lang.StringgetPropertiesName()Gets the name of the property file.longgetSince()Gets the epochal time since when logged in.java.util.TimeZonegetTimeZone()Gets the timezone.intgetUserClassId()Gets the class id of the current user.longgetUserId()Gets the user id.java.lang.StringgetUserName()Gets the username.java.lang.StringgetVmInfo()Gets the info string describing the JVM.inthashCode()booleanisCloned()Checks whether this session info is cloned.booleanisFinallyImmutable()booleanisImmutable()booleanisLockLingerEnabled()Determines whether tokenlocks are removed when session is closed.
By default, locks are not removed for cloned sessions.voidsetApplicationId(long applicationId)Sets the application id.
Should be unique among the same application name.voidsetApplicationName(java.lang.String application)Sets the name of the application.voidsetClientVersion(java.lang.String clientVersion)Sets the client's version.voidsetFinallyImmutable()voidsetHostInfo(java.lang.String hostInfo)Sets the host info.voidsetImmutable(boolean immutable)voidsetImmutableLoggingLevel(org.tentackle.log.Logger.Level immutableLoggingLevel)voidsetLocale(java.util.Locale locale)Sets the session's locale.voidsetLockLingerEnabled(boolean enabled)Sets whether tokenlocks are removed when session is closed.voidsetOsInfo(java.lang.String osInfo)Sets the operating system info.voidsetPassword(char[] password)Sets the password.voidsetProperties(java.util.Properties properties)Sets the connection properties.voidsetPropertiesName(java.lang.String propertiesName)Sets the name of the property file.
(without the extension.properties)voidsetSince(long since)Sets the epochal time since when logged in.voidsetTimeZone(java.util.TimeZone timeZone)Sets the timezone.voidsetUserClassId(int userClassId)Sets the class id of the current user.voidsetUserId(long userId)Sets the user id.voidsetUserName(java.lang.String userName)Sets the username.voidsetVmInfo(java.lang.String vmInfo)Sets the info string describing the JVM.java.lang.StringtoString()
-
-
-
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 ifSystem.getProperty("user.name")password- is the password, null if nonepropertiesName- 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:
equalsin classjava.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:
hashCodein classjava.lang.Object
-
isImmutable
public boolean isImmutable()
- Specified by:
isImmutablein interfaceorg.tentackle.misc.Immutable
-
setImmutable
public void setImmutable(boolean immutable)
- Specified by:
setImmutablein interfaceorg.tentackle.misc.Immutable
-
setFinallyImmutable
public void setFinallyImmutable()
- Specified by:
setFinallyImmutablein interfaceorg.tentackle.misc.Immutable
-
isFinallyImmutable
public boolean isFinallyImmutable()
- Specified by:
isFinallyImmutablein interfaceorg.tentackle.misc.Immutable
-
setImmutableLoggingLevel
public void setImmutableLoggingLevel(org.tentackle.log.Logger.Level immutableLoggingLevel)
- Specified by:
setImmutableLoggingLevelin interfaceorg.tentackle.misc.Immutable
-
getImmutableLoggingLevel
public org.tentackle.log.Logger.Level getImmutableLoggingLevel()
- Specified by:
getImmutableLoggingLevelin interfaceorg.tentackle.misc.Immutable
-
assertMutable
protected void assertMutable()
Asserts that this session info is mutable.
-
setSince
public void setSince(long since)
Description copied from interface:SessionInfoSets the epochal time since when logged in.- Specified by:
setSincein interfaceSessionInfo- Parameters:
since- logged in since, null if not logged in
-
getSince
public long getSince()
Description copied from interface:SessionInfoGets the epochal time since when logged in.- Specified by:
getSincein interfaceSessionInfo- Returns:
- logged in since, null if not logged in
-
setUserName
public void setUserName(java.lang.String userName)
Description copied from interface:SessionInfoSets the username.- Specified by:
setUserNamein interfaceSessionInfo- Parameters:
userName- the name of the user
-
getUserName
public java.lang.String getUserName()
Description copied from interface:SessionInfoGets the username.- Specified by:
getUserNamein interfaceSessionInfo- Returns:
- the username
-
setPassword
public void setPassword(char[] password)
Description copied from interface:SessionInfoSets the password.- Specified by:
setPasswordin interfaceSessionInfo- Parameters:
password- the password
-
getPassword
public char[] getPassword()
Description copied from interface:SessionInfoGets the password.- Specified by:
getPasswordin interfaceSessionInfo- Returns:
- the password
-
clearPassword
public void clearPassword()
Description copied from interface:SessionInfoClears the password.
Will remove it from memory by overwriting each element in the character array.- Specified by:
clearPasswordin interfaceSessionInfo
-
getClientVersion
public java.lang.String getClientVersion()
Description copied from interface:SessionInfoGets the client version.- Specified by:
getClientVersionin interfaceSessionInfo- Returns:
- the client version
-
setClientVersion
public void setClientVersion(java.lang.String clientVersion)
Description copied from interface:SessionInfoSets the client's version.- Specified by:
setClientVersionin interfaceSessionInfo- Parameters:
clientVersion- the client version
-
getLocale
public java.util.Locale getLocale()
Description copied from interface:SessionInfoGets the session's locale.
Returns the JVM's default locale if not set explicitly viaSessionInfo.setLocale(java.util.Locale).- Specified by:
getLocalein interfaceSessionInfo- Returns:
- the locale, never null
-
setLocale
public void setLocale(java.util.Locale locale)
Description copied from interface:SessionInfoSets the session's locale.- Specified by:
setLocalein interfaceSessionInfo- Parameters:
locale- the locale, null to use JVM's locale
-
getVmInfo
public java.lang.String getVmInfo()
Description copied from interface:SessionInfoGets the info string describing the JVM.- Specified by:
getVmInfoin interfaceSessionInfo- Returns:
- the jvm info
-
setVmInfo
public void setVmInfo(java.lang.String vmInfo)
Description copied from interface:SessionInfoSets the info string describing the JVM.- Specified by:
setVmInfoin interfaceSessionInfo- Parameters:
vmInfo- the jvm info
-
getTimeZone
public java.util.TimeZone getTimeZone()
Description copied from interface:SessionInfoGets the timezone.- Specified by:
getTimeZonein interfaceSessionInfo- Returns:
- the timezone
-
setTimeZone
public void setTimeZone(java.util.TimeZone timeZone)
Description copied from interface:SessionInfoSets the timezone.- Specified by:
setTimeZonein interfaceSessionInfo- Parameters:
timeZone- the timezone
-
getOsInfo
public java.lang.String getOsInfo()
Description copied from interface:SessionInfoGets the operating system info.- Specified by:
getOsInfoin interfaceSessionInfo- Returns:
- the OS info
-
setOsInfo
public void setOsInfo(java.lang.String osInfo)
Description copied from interface:SessionInfoSets the operating system info.- Specified by:
setOsInfoin interfaceSessionInfo- Parameters:
osInfo- the OS info
-
getHostInfo
public java.lang.String getHostInfo()
Description copied from interface:SessionInfoGets the host info.- Specified by:
getHostInfoin interfaceSessionInfo- Returns:
- the hostname or similar info
-
setHostInfo
public void setHostInfo(java.lang.String hostInfo)
Description copied from interface:SessionInfoSets the host info.- Specified by:
setHostInfoin interfaceSessionInfo- Parameters:
hostInfo- the info
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.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:
clonein interfaceSessionInfo- Overrides:
clonein classjava.lang.Object- Returns:
- the cloned session info
-
isCloned
public boolean isCloned()
Description copied from interface:SessionInfoChecks whether this session info is cloned.- Specified by:
isClonedin interfaceSessionInfo- Returns:
- true if cloned
-
clearCloned
public void clearCloned()
Description copied from interface:SessionInfoCleares the cloned flag. Useful if the sessioninfo should no longer be treated as cloned.- Specified by:
clearClonedin interfaceSessionInfo
-
getPropertiesName
public java.lang.String getPropertiesName()
Description copied from interface:SessionInfoGets the name of the property file.- Specified by:
getPropertiesNamein interfaceSessionInfo- Returns:
- the filename
-
setPropertiesName
public void setPropertiesName(java.lang.String propertiesName)
Description copied from interface:SessionInfoSets the name of the property file.
(without the extension.properties)- Specified by:
setPropertiesNamein interfaceSessionInfo- Parameters:
propertiesName- the filename
-
getProperties
public java.util.Properties getProperties()
Description copied from interface:SessionInfoGets the connection properties.
The the properties are not set so far, the method will load the properties file by adding the extension".properties"toSessionInfo.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 aPersistenceExceptionis thrown.- Specified by:
getPropertiesin interfaceSessionInfo- Returns:
- the connection properties, never null
-
setProperties
public void setProperties(java.util.Properties properties)
Description copied from interface:SessionInfoSets the connection properties.- Specified by:
setPropertiesin interfaceSessionInfo- Parameters:
properties- the connection properties.
-
applyProperties
public void applyProperties()
Description copied from interface:SessionInfoApplies the properties to this session info.
Sets user and password from properties, if given.- Specified by:
applyPropertiesin interfaceSessionInfo
-
getApplicationName
public java.lang.String getApplicationName()
Description copied from interface:SessionInfoGets the name of the application.- Specified by:
getApplicationNamein interfaceSessionInfo- Returns:
- the name, null if none
-
setApplicationName
public void setApplicationName(java.lang.String application)
Description copied from interface:SessionInfoSets the name of the application.- Specified by:
setApplicationNamein interfaceSessionInfo- Parameters:
application- the name
-
setApplicationId
public void setApplicationId(long applicationId)
Description copied from interface:SessionInfoSets the application id.
Should be unique among the same application name.- Specified by:
setApplicationIdin interfaceSessionInfo- Parameters:
applicationId- the optional application id
-
getApplicationId
public long getApplicationId()
Description copied from interface:SessionInfoReturns the application id.- Specified by:
getApplicationIdin interfaceSessionInfo- Returns:
- the id, 0 if none
-
checkServerVersion
public void checkServerVersion(java.lang.String serverVersion)
Description copied from interface:SessionInfoChecks the version of the server.The default implementation does nothing.
- Specified by:
checkServerVersionin interfaceSessionInfo- Parameters:
serverVersion- the server's version
-
getUserId
public long getUserId()
Description copied from interface:SessionInfoGets the user id.- Specified by:
getUserIdin interfaceSessionInfo- Returns:
- the object Id of the current user
-
setUserId
public void setUserId(long userId)
Description copied from interface:SessionInfoSets the user id.- Specified by:
setUserIdin interfaceSessionInfo- Parameters:
userId- the object ID of the user
-
getUserClassId
public int getUserClassId()
Description copied from interface:SessionInfoGets the class id of the current user.- Specified by:
getUserClassIdin interfaceSessionInfo- Returns:
- the class id
-
setUserClassId
public void setUserClassId(int userClassId)
Description copied from interface:SessionInfoSets the class id of the current user.- Specified by:
setUserClassIdin interfaceSessionInfo- Parameters:
userClassId- the class id
-
isLockLingerEnabled
public boolean isLockLingerEnabled()
Description copied from interface:SessionInfoDetermines whether tokenlocks are removed when session is closed.
By default, locks are not removed for cloned sessions.- Specified by:
isLockLingerEnabledin interfaceSessionInfo- Returns:
- true if leave locks untouched, false to remove locks
-
setLockLingerEnabled
public void setLockLingerEnabled(boolean enabled)
Description copied from interface:SessionInfoSets whether tokenlocks are removed when session is closed.- Specified by:
setLockLingerEnabledin interfaceSessionInfo- Parameters:
enabled- true if leave locks untouched, false to remove locks
-
-