org.opennms.netmgt.config
Class UserManager

java.lang.Object
  extended by org.opennms.netmgt.config.UserManager
Direct Known Subclasses:
UserFactory

public abstract class UserManager
extends Object

Author:
David Hustace, Matt Brozowski

Field Summary
protected  HashMap<String,List<DutySchedule>> m_dutySchedules
          The duty schedules for each user
protected  GroupManager m_groupManager
           
protected  HashMap<String,User> m_users
          A mapping of user IDs to the User objects
 
Constructor Summary
protected UserManager(GroupManager groupManager)
           
 
Method Summary
 boolean comparePasswords(String userID, String aPassword)
          This method compares two encrypted strings for equality.
 int countUsersWithRole(String roleid)
           
 void deleteUser(String name)
          Removes the user from the list of users.
 String encryptedPassword(String aPassword)
           
 String getContactInfo(String userID, String command)
          Get the contact info given a command string
 String getContactInfo(User user, String command)
           
 String getContactServiceProvider(String userID, String command)
          Get the contact service provider, given a command string
 String getContactServiceProvider(User user, String command)
           
 String getEmail(String userID)
          Get a email by name
 String getEmail(User user)
          Get a email by user
 String getNumericPage(String userID)
          Get a numeric service provider
 String getNumericPage(User user)
          Get a numeric service provider
 String getNumericPin(String userID)
          Get a numeric pin
 String getNumericPin(User user)
          Get a numeric pin
 String getPagerEmail(String userID)
          Get a pager email by name
 String getPagerEmail(User user)
          Get a pager email by user
 String getTextPage(String userID)
          Get a Text Page Service Provider
 String getTextPage(User user)
          Get a Text Page Service Provider
 String getTextPin(String userID)
          Get a text pin
 String getTextPin(User user)
          Get a text pin
 User getUser(String name)
          Get a user by name
 List<String> getUserNames()
           
 Map<String,User> getUsers()
          Return a Map of usernames to user instances.
 String[] getUsersScheduledForRole(String roleid, Date time)
           
 String[] getUsersWithRole(String roleid)
           
 String getXMPPAddress(String userID)
          Get an XMPP address by name
 String getXMPPAddress(User user)
          Get an XMPP address by name
 boolean hasRole(String roleid)
           
 boolean hasUser(String userName)
          Returns a boolean indicating if the user name appears in the XML file
abstract  boolean isUpdateNeeded()
           
 boolean isUserOnDuty(String user, Calendar time)
          Determines if a user is on duty at a given time.
 boolean isUserScheduledForRole(User user, String roleid, Date time)
           
 void parseXML(Reader reader)
           
 void renameUser(String oldName, String newName)
          When this method is called users name is changed, so also is the username belonging to the group and the view.
 void saveUser(String name, User details)
          Adds a new user and overwrites the "users.xml"
 void saveUsers(Collection<User> usersList)
           
protected abstract  void saveXML(String writerString)
           
 void setEncryptedPassword(String userID, String aPassword)
          Sets the password for this user, assuming that the value passed in is already encrypted properly
 void setUnencryptedPassword(String userID, String aPassword)
          Sets the password for this user, first encrypting it
protected abstract  void update()
           
 boolean userHasRole(User user, String roleid)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_groupManager

protected GroupManager m_groupManager

m_users

protected HashMap<String,User> m_users
A mapping of user IDs to the User objects


m_dutySchedules

protected HashMap<String,List<DutySchedule>> m_dutySchedules
The duty schedules for each user

Constructor Detail

UserManager

protected UserManager(GroupManager groupManager)
Method Detail

parseXML

public void parseXML(Reader reader)
              throws org.exolab.castor.xml.MarshalException,
                     org.exolab.castor.xml.ValidationException
Parameters:
reader -
Throws:
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

saveUser

public void saveUser(String name,
                     User details)
              throws Exception
Adds a new user and overwrites the "users.xml"

Throws:
Exception

isUserOnDuty

public boolean isUserOnDuty(String user,
                            Calendar time)
                     throws IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException
Determines if a user is on duty at a given time. If a user has no duty schedules listed in the configuration file, that user is assumed to always be on duty.

Parameters:
user - the user id
time - the time to check for a duty schedule
Returns:
boolean, true if the user is on duty, false otherwise.
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUsers

public Map<String,User> getUsers()
                          throws IOException,
                                 org.exolab.castor.xml.MarshalException,
                                 org.exolab.castor.xml.ValidationException
Return a Map of usernames to user instances.

Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

hasUser

public boolean hasUser(String userName)
                throws IOException,
                       org.exolab.castor.xml.MarshalException,
                       org.exolab.castor.xml.ValidationException
Returns a boolean indicating if the user name appears in the XML file

Returns:
true if the user exists in the XML file, false otherwise
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUserNames

public List<String> getUserNames()
                          throws IOException,
                                 org.exolab.castor.xml.MarshalException,
                                 org.exolab.castor.xml.ValidationException
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUser

public User getUser(String name)
             throws IOException,
                    org.exolab.castor.xml.MarshalException,
                    org.exolab.castor.xml.ValidationException
Get a user by name

Parameters:
name - the name of the user to return
Returns:
the user specified by name
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getContactInfo

public String getContactInfo(String userID,
                             String command)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Get the contact info given a command string

Parameters:
userID - the name of the user
command - the command to look up the contact info for
Returns:
the contact information
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getContactInfo

public String getContactInfo(User user,
                             String command)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getContactServiceProvider

public String getContactServiceProvider(String userID,
                                        String command)
                                 throws IOException,
                                        org.exolab.castor.xml.MarshalException,
                                        org.exolab.castor.xml.ValidationException
Get the contact service provider, given a command string

Parameters:
userID - the name of the user
command - the command to look up the contact info for
Returns:
the contact information
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getContactServiceProvider

public String getContactServiceProvider(User user,
                                        String command)
                                 throws IOException,
                                        org.exolab.castor.xml.MarshalException,
                                        org.exolab.castor.xml.ValidationException
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getEmail

public String getEmail(String userID)
                throws IOException,
                       org.exolab.castor.xml.MarshalException,
                       org.exolab.castor.xml.ValidationException
Get a email by name

Parameters:
userID - the user ID of the user to return
Returns:
String the email specified by name
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getEmail

public String getEmail(User user)
                throws IOException,
                       org.exolab.castor.xml.MarshalException,
                       org.exolab.castor.xml.ValidationException
Get a email by user

Parameters:
user - the user to find the email for
Returns:
String the email specified by name
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getPagerEmail

public String getPagerEmail(String userID)
                     throws IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException
Get a pager email by name

Parameters:
userID - the user ID of the user to return
Returns:
String the pager email
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getPagerEmail

public String getPagerEmail(User user)
                     throws IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException
Get a pager email by user

Parameters:
user -
Returns:
String the pager email
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getNumericPin

public String getNumericPin(String userID)
                     throws IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException
Get a numeric pin

Parameters:
userID - the user ID of the user to return
Returns:
String the numeric pin
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getNumericPin

public String getNumericPin(User user)
                     throws IOException,
                            org.exolab.castor.xml.MarshalException,
                            org.exolab.castor.xml.ValidationException
Get a numeric pin

Parameters:
userID - the user ID of the user to return
Returns:
String the numeric pin
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getXMPPAddress

public String getXMPPAddress(String userID)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Get an XMPP address by name

Parameters:
userID - the user ID of the user to return
Returns:
String the XMPP address
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getXMPPAddress

public String getXMPPAddress(User user)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Get an XMPP address by name

Parameters:
user -
Returns:
String the XMPP address
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getNumericPage

public String getNumericPage(String userID)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Get a numeric service provider

Parameters:
userID - the user ID of the user to return
Returns:
String the service provider
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getNumericPage

public String getNumericPage(User user)
                      throws IOException,
                             org.exolab.castor.xml.MarshalException,
                             org.exolab.castor.xml.ValidationException
Get a numeric service provider

Parameters:
userID - the user ID of the user to return
Returns:
String the service provider
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getTextPin

public String getTextPin(String userID)
                  throws IOException,
                         org.exolab.castor.xml.MarshalException,
                         org.exolab.castor.xml.ValidationException
Get a text pin

Parameters:
userID - the user ID of the user to return
Returns:
String the text pin
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getTextPin

public String getTextPin(User user)
                  throws IOException,
                         org.exolab.castor.xml.MarshalException,
                         org.exolab.castor.xml.ValidationException
Get a text pin

Parameters:
userID - the user ID of the user to return
Returns:
String the text pin
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getTextPage

public String getTextPage(String userID)
                   throws IOException,
                          org.exolab.castor.xml.MarshalException,
                          org.exolab.castor.xml.ValidationException
Get a Text Page Service Provider

Parameters:
userID - the user ID of the user to return
Returns:
String the text page service provider.
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getTextPage

public String getTextPage(User user)
                   throws IOException,
                          org.exolab.castor.xml.MarshalException,
                          org.exolab.castor.xml.ValidationException
Get a Text Page Service Provider

Parameters:
userID - the user ID of the user to return
Returns:
String the text page service provider.
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

saveUsers

public void saveUsers(Collection<User> usersList)
               throws Exception
Throws:
Exception

deleteUser

public void deleteUser(String name)
                throws Exception
Removes the user from the list of users. Then overwrites to the "users.xml"

Throws:
Exception

saveXML

protected abstract void saveXML(String writerString)
                         throws IOException
Parameters:
writerString -
Throws:
IOException

renameUser

public void renameUser(String oldName,
                       String newName)
                throws Exception
When this method is called users name is changed, so also is the username belonging to the group and the view. Also overwrites the "users.xml" file

Throws:
Exception

setEncryptedPassword

public void setEncryptedPassword(String userID,
                                 String aPassword)
                          throws Exception
Sets the password for this user, assuming that the value passed in is already encrypted properly

Parameters:
userID - the user ID to change the password for
aPassword - the encrypted password
Throws:
Exception

setUnencryptedPassword

public void setUnencryptedPassword(String userID,
                                   String aPassword)
                            throws Exception
Sets the password for this user, first encrypting it

Parameters:
userID - the user ID to change the password for
aPassword - the password
Throws:
Exception

encryptedPassword

public String encryptedPassword(String aPassword)
Parameters:
aPassword -
Returns:

comparePasswords

public boolean comparePasswords(String userID,
                                String aPassword)
This method compares two encrypted strings for equality.

Parameters:
userID - the user ID to check against.
aPassword - the password to check for equality
Returns:
true if the two passwords are equal (after encryption), false otherwise

update

protected abstract void update()
                        throws IOException,
                               FileNotFoundException,
                               org.exolab.castor.xml.MarshalException,
                               org.exolab.castor.xml.ValidationException
Throws:
IOException
FileNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUsersWithRole

public String[] getUsersWithRole(String roleid)
                          throws IOException,
                                 org.exolab.castor.xml.MarshalException,
                                 org.exolab.castor.xml.ValidationException
Throws:
IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

userHasRole

public boolean userHasRole(User user,
                           String roleid)
                    throws FileNotFoundException,
                           org.exolab.castor.xml.MarshalException,
                           org.exolab.castor.xml.ValidationException,
                           IOException
Throws:
FileNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
IOException

isUserScheduledForRole

public boolean isUserScheduledForRole(User user,
                                      String roleid,
                                      Date time)
                               throws FileNotFoundException,
                                      org.exolab.castor.xml.MarshalException,
                                      org.exolab.castor.xml.ValidationException,
                                      IOException
Throws:
FileNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
IOException

getUsersScheduledForRole

public String[] getUsersScheduledForRole(String roleid,
                                         Date time)
                                  throws org.exolab.castor.xml.MarshalException,
                                         org.exolab.castor.xml.ValidationException,
                                         IOException
Throws:
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
IOException

hasRole

public boolean hasRole(String roleid)
                throws org.exolab.castor.xml.MarshalException,
                       org.exolab.castor.xml.ValidationException,
                       IOException
Throws:
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
IOException

countUsersWithRole

public int countUsersWithRole(String roleid)
                       throws org.exolab.castor.xml.MarshalException,
                              org.exolab.castor.xml.ValidationException,
                              IOException
Throws:
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
IOException

isUpdateNeeded

public abstract boolean isUpdateNeeded()


Copyright © 2009. All Rights Reserved.