org.tentackle.db
Class UserInfo

java.lang.Object
  extended by org.tentackle.db.UserInfo
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AppUserInfo

public class UserInfo
extends Object
implements Serializable, Cloneable

Information about the user connecting to a database.

Author:
harald
See Also:
Serialized Form

Field Summary
static int SOCKETCONFIG_COMPRESSED
          compressed socket (no ssl)
static int SOCKETCONFIG_COMPRESSED_SSL
          ssl + compression
static int SOCKETCONFIG_PLAIN
          plain socket (no compression, no ssl)
static int SOCKETCONFIG_SESSION
          use session config (default for all RemoteDelegates)
static int SOCKETCONFIG_SSL
          ssl socket (no compression)
 
Constructor Summary
UserInfo(String username, char[] password, String dbPropertiesName)
          Create a db connection info from a username, password and property file holding the connection parameters.
 
Method Summary
 void bindDb(Db db)
          Binds the UserInfo to a logical db connection.
 void clearCloned()
          Cleares the cloned flag.
 void clearPassword()
          Clears the password.
 UserInfo clone()
          Clones a userinfo.
 void configureSsl()
          Configures the SSL system properties according to the settings in the dbProperties file.
 String getApplication()
          Gets the application name.
 Properties getDbProperties()
          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 dbPropertiesName (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 the db errorhandler will be invoked (which will usually terminate the application).
 String getDbPropertiesName()
          Gets the name of the property file.
 char[] getPassword()
          Gets the password.
 String getPasswordAsString()
          Gets the password as a string.
 long getSince()
          Gets the time since when logged in.
 int getSocketConfig()
          Gets the socket config from according to the current connection properties.
static int getSocketConfig(Properties props)
          Gets the socket config from according to given connection properties.
 String getUsername()
          Gets the username.
 boolean isCloned()
          Checks whether this UserInfo is cloned.
 Properties loadDbProperties(boolean asResource)
          Loads the properties according to getDbPropertiesName().
 void setApplication(String application)
          Sets the application name.
 void setDbProperties(Properties dbProperties)
          Sets the connection properties.
 void setDbPropertiesName(String dbPropertiesName)
          Sets the name of the property file, i.e.
 void setPassword(char[] password)
          Sets the password.
 void setSince(long since)
          Sets the epochal time when the user logged in.
 void setUsername(String username)
          Sets the username
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SOCKETCONFIG_SESSION

public static final int SOCKETCONFIG_SESSION
use session config (default for all RemoteDelegates)

See Also:
Constant Field Values

SOCKETCONFIG_PLAIN

public static final int SOCKETCONFIG_PLAIN
plain socket (no compression, no ssl)

See Also:
Constant Field Values

SOCKETCONFIG_COMPRESSED

public static final int SOCKETCONFIG_COMPRESSED
compressed socket (no ssl)

See Also:
Constant Field Values

SOCKETCONFIG_SSL

public static final int SOCKETCONFIG_SSL
ssl socket (no compression)

See Also:
Constant Field Values

SOCKETCONFIG_COMPRESSED_SSL

public static final int SOCKETCONFIG_COMPRESSED_SSL
ssl + compression

See Also:
Constant Field Values
Constructor Detail

UserInfo

public UserInfo(String username,
                char[] password,
                String dbPropertiesName)
Create a db connection info from a username, password and 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
dbPropertiesName - name of the db-properties, null if "Db"
Method Detail

bindDb

public void bindDb(Db db)
Binds the UserInfo to a logical db connection. For the default UserInfo this method does nothing. However, extended classes might need that, especially when sent over an rmi comlink.

Parameters:
db - the db connection

setSince

public void setSince(long since)
Sets the epochal time when the user logged in.

Parameters:
since - logged in since

getSince

public long getSince()
Gets the time since when logged in.

Returns:
logged in since, null if not logged in

setUsername

public void setUsername(String username)
Sets the username

Parameters:
username - the username

getUsername

public String getUsername()
Gets the username.

Returns:
the username

setPassword

public void setPassword(char[] password)
Sets the password.

Parameters:
password - the password

clearPassword

public void clearPassword()
Clears the password. Password should be cleared when no more used to remove them physically from memory. This is the reason why we store passwords as a character array and not a string.

Sadly enough, the JDBC api requires passwords as strings :-(


getPassword

public char[] getPassword()
Gets the password.

Returns:
the password

getPasswordAsString

public String getPasswordAsString()
Gets the password as a string. The password is stored as a character array. If the password is null the empty string will be returned bevaise some dbms drivers will nullp otherwise.

Returns:
the password, never null

toString

public String toString()
Description copied from class: java.lang.Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.

clone

public UserInfo clone()
Clones a userinfo. The password will be copied if not null.

Overrides:
clone in class Object
Returns:
a clone of this instance.
See Also:
Cloneable

isCloned

public boolean isCloned()
Checks whether this UserInfo is cloned.

Returns:
true if cloned

clearCloned

public void clearCloned()
Cleares the cloned flag. Useful if the userinfo should no longer be treated as cloned.


getDbPropertiesName

public String getDbPropertiesName()
Gets the name of the property file.

Returns:
the filename

setDbPropertiesName

public void setDbPropertiesName(String dbPropertiesName)
Sets the name of the property file, i.e. without the extension .properties.

Parameters:
dbPropertiesName - the filename

loadDbProperties

public Properties loadDbProperties(boolean asResource)
                            throws FileNotFoundException,
                                   IOException
Loads the properties according to getDbPropertiesName().

Does not setDbProperties(java.util.Properties) !

Parameters:
asResource - true if load from the classpath, false if from filesystem
Returns:
the properties
Throws:
FileNotFoundException - if no such property file
IOException - if reading the property file failed

getDbProperties

public Properties getDbProperties()
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 dbPropertiesName (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 the db errorhandler will be invoked (which will usually terminate the application).

Returns:
the connection properties, never null

setDbProperties

public void setDbProperties(Properties dbProperties)
Sets the connection properties.

Parameters:
dbProperties - the connection properties.

getApplication

public String getApplication()
Gets the application name.

Returns:
the name

setApplication

public void setApplication(String application)
Sets the application name. Application server may need that to classify the client.

Parameters:
application - the name

configureSsl

public void configureSsl()
Configures the SSL system properties according to the settings in the dbProperties file. Needs to be invoked before any method used from javax.net.ssl.* keystore= , default is null if not provided by command line truststore= for client auth, default is null if not provided by command line keystorepassword=, no default if not provided by command line truststorepassword=, no default if not provided by command line


getSocketConfig

public static int getSocketConfig(Properties props)
Gets the socket config from according to given connection properties.

Parameters:
props - the connection properties
Returns:
the socket config (one of SOCKETCONFIG_...)

getSocketConfig

public int getSocketConfig()
Gets the socket config from according to the current connection properties.

Returns:
the socket config (one of SOCKETCONFIG_...)


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de