org.hackystat.sensorbase.resource.users
Class UserManager

java.lang.Object
  extended by org.hackystat.sensorbase.resource.users.UserManager

public class UserManager
extends java.lang.Object

Manages access to the User resources. Loads default definitions if available. Thread Safety Note: This class must NOT invoke any methods from ProjectManager or SensorDataManager in order to avoid potential deadlock. (ProjectManager and SensorDataManager both invoke methods from UserManager, so if UserManager were to invoke a method from either of these two classes, then we would have multiple locks not being acquired in the same order, which produces the potential for deadlock.)

Author:
Philip Johnson

Field Summary
(package private)  DbManager dbManager
          The DbManager associated with this server.
(package private)  Server server
          The Server associated with this UserManager.
static java.lang.String userIndexCloseTag
          The UserIndex close tag.
static java.lang.String userIndexOpenTag
          The UserIndex open tag.
 
Constructor Summary
UserManager(Server server)
          The constructor for UserManagers.
 
Method Summary
 void deleteUser(java.lang.String email)
          Ensures that the passed User is no longer present in this Manager, and deletes all Projects associated with this user.
 User getUser(java.lang.String email)
          Returns the User associated with this email address if they are currently registered, or null if not found.
 java.lang.String getUserIndex()
          Returns the XML string containing the UserIndex with all defined Users.
 java.util.Set<User> getUsers()
          Returns a set containing the current User instances.
 java.lang.String getUserString(java.lang.String email)
          Returns the User Xml String associated with this email address if they are registered, or null if user not found.
 boolean isAdmin(java.lang.String email)
          Returns true if email is a defined User with Admin privileges.
 boolean isTestUser(User user)
          Returns true if the passed user is a test user.
 boolean isUser(java.lang.String email)
          Returns true if the User as identified by their email address is known to this Manager.
 boolean isUser(java.lang.String email, java.lang.String password)
          Returns true if the User as identified by their email address and password is known to this Manager.
 java.lang.String makeProperties(Properties properties)
          Returns the passed Properties instance as a String encoding of its XML representation.
 Properties makeProperties(java.lang.String xmlString)
          Takes a String encoding of a Properties in XML format and converts it to an instance.
 User makeUser(java.lang.String xmlString)
          Takes a String encoding of a User in XML format and converts it to an instance.
 java.lang.String makeUser(User user)
          Returns the passed User instance as a String encoding of its XML representation.
 UserIndex makeUserIndex(java.lang.String xmlString)
          Takes a String encoding of a UserIndex in XML format and converts it to an instance.
 UserRef makeUserRef(User user)
          Returns a UserRef instance constructed from a User instance.
 java.lang.String makeUserRefString(User user)
          Returns the passed User instance as a String encoding of its XML representation as a UserRef object.
 void putUser(User user)
          Updates the Manager with this User.
 User registerUser(java.lang.String email)
          Registers a User, given their email address.
 void updateProperties(User user, Properties properties)
          Updates the given User with the passed Properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

Server server
The Server associated with this UserManager.


dbManager

DbManager dbManager
The DbManager associated with this server.


userIndexOpenTag

public static final java.lang.String userIndexOpenTag
The UserIndex open tag.

See Also:
Constant Field Values

userIndexCloseTag

public static final java.lang.String userIndexCloseTag
The UserIndex close tag.

See Also:
Constant Field Values
Constructor Detail

UserManager

public UserManager(Server server)
The constructor for UserManagers.

Parameters:
server - The Server instance associated with this UserManager.
Method Detail

getUserIndex

public java.lang.String getUserIndex()
Returns the XML string containing the UserIndex with all defined Users. Uses the in-memory cache of UserRef strings.

Returns:
The XML string providing an index to all current Users.

putUser

public void putUser(User user)
Updates the Manager with this User. Any old definition is overwritten.

Parameters:
user - The User.

deleteUser

public void deleteUser(java.lang.String email)
Ensures that the passed User is no longer present in this Manager, and deletes all Projects associated with this user.

Parameters:
email - The email address of the User to remove if currently present.

getUser

public User getUser(java.lang.String email)
Returns the User associated with this email address if they are currently registered, or null if not found.

Parameters:
email - The email address
Returns:
The User, or null if not found.

getUserString

public java.lang.String getUserString(java.lang.String email)
Returns the User Xml String associated with this email address if they are registered, or null if user not found.

Parameters:
email - The email address
Returns:
The User XML string, or null if not found.

updateProperties

public void updateProperties(User user,
                             Properties properties)
Updates the given User with the passed Properties.

Parameters:
user - The User whose properties are to be updated.
properties - The Properties.

getUsers

public java.util.Set<User> getUsers()
Returns a set containing the current User instances. For thread safety, a fresh Set of Users is built each time this is called.

Returns:
A Set containing the current Users.

isUser

public boolean isUser(java.lang.String email)
Returns true if the User as identified by their email address is known to this Manager.

Parameters:
email - The email address of the User of interest.
Returns:
True if found in this Manager.

isUser

public boolean isUser(java.lang.String email,
                      java.lang.String password)
Returns true if the User as identified by their email address and password is known to this Manager.

Parameters:
email - The email address of the User of interest.
password - The password of this user.
Returns:
True if found in this Manager.

isAdmin

public boolean isAdmin(java.lang.String email)
Returns true if email is a defined User with Admin privileges.

Parameters:
email - An email address.
Returns:
True if email is a User with Admin privileges.

isTestUser

public boolean isTestUser(User user)
Returns true if the passed user is a test user. This is defined as a User whose email address uses the TEST_DOMAIN.

Parameters:
user - The user.
Returns:
True if the user is a test user.

registerUser

public User registerUser(java.lang.String email)
Registers a User, given their email address. If a User with the passed email address exists, then return the previously registered User. Otherwise create a new User and return it. If the email address ends with the test domain, then the password will be the email. Otherwise, a unique, randomly generated 12 character key is generated as the password. Defines the Default Project for each new user.

Parameters:
email - The email address for the user.
Returns:
The retrieved or newly created User.

makeProperties

public final Properties makeProperties(java.lang.String xmlString)
                                throws java.lang.Exception
Takes a String encoding of a Properties in XML format and converts it to an instance.

Parameters:
xmlString - The XML string representing a Properties.
Returns:
The corresponding Properties instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeUser

public final User makeUser(java.lang.String xmlString)
                    throws java.lang.Exception
Takes a String encoding of a User in XML format and converts it to an instance.

Parameters:
xmlString - The XML string representing a User
Returns:
The corresponding User instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeUserIndex

public final UserIndex makeUserIndex(java.lang.String xmlString)
                              throws java.lang.Exception
Takes a String encoding of a UserIndex in XML format and converts it to an instance.

Parameters:
xmlString - The XML string representing a UserIndex.
Returns:
The corresponding UserIndex instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeUser

public final java.lang.String makeUser(User user)
                                throws java.lang.Exception
Returns the passed User instance as a String encoding of its XML representation. Final because it's called in constructor.

Parameters:
user - The User instance.
Returns:
The XML String representation.
Throws:
java.lang.Exception - If problems occur during translation.

makeProperties

public java.lang.String makeProperties(Properties properties)
                                throws java.lang.Exception
Returns the passed Properties instance as a String encoding of its XML representation.

Parameters:
properties - The Properties instance.
Returns:
The XML String representation.
Throws:
java.lang.Exception - If problems occur during translation.

makeUserRefString

public final java.lang.String makeUserRefString(User user)
                                         throws java.lang.Exception
Returns the passed User instance as a String encoding of its XML representation as a UserRef object. Final because it's called in constructor.

Parameters:
user - The User instance.
Returns:
The XML String representation of it as a UserRef
Throws:
java.lang.Exception - If problems occur during translation.

makeUserRef

public UserRef makeUserRef(User user)
Returns a UserRef instance constructed from a User instance.

Parameters:
user - The User instance.
Returns:
A UserRef instance.