OpenNMS API 1.1.4

org.opennms.netmgt.config
Class UserFactory

java.lang.Object
  extended byorg.opennms.netmgt.config.UserFactory

public class UserFactory
extends java.lang.Object


Field Summary
protected static java.io.InputStream configIn
          An input stream for the users configuration file
private static GroupFactory groupFactory
           
private static boolean initialized
          Boolean indicating if the init() method has been called
private static UserFactory instance
          The static singleton instance of the UserFactory
protected static java.util.HashMap m_dutySchedules
          The duty schedules for each user
private static long m_lastModified
           
protected static java.util.HashMap m_users
          A mapping of user ids to the User objects
private static java.io.File m_usersConfFile
           
private static Header oldHeader
           
protected static java.io.File usersFile
          File path of users.xml
 
Constructor Summary
UserFactory()
          Initializes the factory
 
Method Summary
private static void buildDutySchedules(java.util.Map users)
          Builds a mapping between user ids and duty schedules.
 boolean comparePasswords(java.lang.String userID, java.lang.String aPassword)
          This method compares two encrypted strings for equality.
 void deleteUser(java.lang.String name)
          Removes the user from the list of users.
static java.lang.String encryptPassword(java.lang.String aPassword)
          This method encrypts the password using MD5 hashing.
 java.lang.String getContactInfo(java.lang.String userID, java.lang.String command)
          Get the contact info given a command string
 java.lang.String getEmail(java.lang.String userid)
          Get a email by name
static UserFactory getInstance()
          Singleton static call to get the only instance that should exist for the UserFactory
 java.lang.String getNumericPage(java.lang.String userid)
          Get a numeric service provider
 java.lang.String getNumericPin(java.lang.String userid)
          Get a numeric pin
 java.lang.String getPagerEmail(java.lang.String userid)
          Get a pager email by name
 java.lang.String getTextPage(java.lang.String userid)
          Get a Text Page Service Provider
 java.lang.String getTextPin(java.lang.String userid)
          Get a text pin
 User getUser(java.lang.String name)
          Get a user by name
 java.util.List getUserNames()
           
 java.util.Map getUsers()
          Return a Map of usernames to user instances.
 boolean hasUser(java.lang.String userName)
          Returns a boolean indicating if the user name appears in the xml file
private static java.lang.String hexToString(byte[] data)
          Converts a byte array into a hexadecimal String representation.
static void init()
           
 boolean isUserOnDuty(java.lang.String user, java.util.Calendar time)
          Determines if a user is on duty at a given time.
static void reload()
          Parses the users.xml via the Castor classes
 void renameUser(java.lang.String oldName, java.lang.String newName)
          When this method is called users name is changed, so also is the username belonging to the group and the view.
private  void saveCurrent()
          Saves into "users.xml" file
 void saveUser(java.lang.String name, User details)
          Adds a new user and overwrites the "users.xml"
 void saveUsers(java.util.Collection usersList)
           
 void setEncryptedPassword(java.lang.String userID, java.lang.String aPassword)
          Sets the password for this user, assuming that the value passed in is already encrypted properly
 void setUnencryptedPassword(java.lang.String userID, java.lang.String aPassword)
          Sets the password for this user, first encrypting it
private static void updateFromFile()
           
static boolean updateNeeded()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static UserFactory instance
The static singleton instance of the UserFactory


groupFactory

private static GroupFactory groupFactory

usersFile

protected static java.io.File usersFile
File path of users.xml


configIn

protected static java.io.InputStream configIn
An input stream for the users configuration file


m_users

protected static java.util.HashMap m_users
A mapping of user ids to the User objects


m_dutySchedules

protected static java.util.HashMap m_dutySchedules
The duty schedules for each user


initialized

private static boolean initialized
Boolean indicating if the init() method has been called


oldHeader

private static Header oldHeader

m_usersConfFile

private static java.io.File m_usersConfFile

m_lastModified

private static long m_lastModified
Constructor Detail

UserFactory

public UserFactory()
Initializes the factory

Method Detail

init

public static void init()
                 throws java.io.IOException,
                        java.io.FileNotFoundException,
                        org.exolab.castor.xml.MarshalException,
                        org.exolab.castor.xml.ValidationException
Throws:
java.io.IOException
java.io.FileNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getInstance

public static UserFactory getInstance()
Singleton static call to get the only instance that should exist for the UserFactory

Returns:
the single user factory instance

reload

public static void reload()
                   throws java.io.IOException,
                          java.io.FileNotFoundException,
                          org.exolab.castor.xml.MarshalException,
                          org.exolab.castor.xml.ValidationException
Parses the users.xml via the Castor classes

Throws:
java.io.IOException
java.io.FileNotFoundException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

saveUser

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

Throws:
java.lang.Exception

buildDutySchedules

private static void buildDutySchedules(java.util.Map users)
Builds a mapping between user ids and duty schedules. These are used by Notifd when determining to send a notice to a given user. This helps speed up the decision process.

Parameters:
users - the map of users parsed from the xml config file

isUserOnDuty

public boolean isUserOnDuty(java.lang.String user,
                            java.util.Calendar time)
                     throws java.io.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 config 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:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUsers

public java.util.Map getUsers()
                       throws java.io.IOException,
                              org.exolab.castor.xml.MarshalException,
                              org.exolab.castor.xml.ValidationException
Return a Map of usernames to user instances.

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

hasUser

public boolean hasUser(java.lang.String userName)
                throws java.io.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:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUserNames

public java.util.List getUserNames()
                            throws java.io.IOException,
                                   org.exolab.castor.xml.MarshalException,
                                   org.exolab.castor.xml.ValidationException
Throws:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getUser

public User getUser(java.lang.String name)
             throws java.io.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:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getContactInfo

public java.lang.String getContactInfo(java.lang.String userID,
                                       java.lang.String command)
                                throws java.io.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:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

getEmail

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

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

getPagerEmail

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

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

getNumericPage

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

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

getTextPin

public java.lang.String getTextPin(java.lang.String userid)
                            throws java.io.IOException,
                                   org.exolab.castor.xml.MarshalException,
                                   org.exolab.castor.xml.ValidationException
Get a text pin

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

getTextPage

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

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

getNumericPin

public java.lang.String getNumericPin(java.lang.String userid)
                               throws java.io.IOException,
                                      org.exolab.castor.xml.MarshalException,
                                      org.exolab.castor.xml.ValidationException
Get a numeric pin

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

saveUsers

public void saveUsers(java.util.Collection usersList)
               throws java.lang.Exception
Throws:
java.lang.Exception

deleteUser

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

Throws:
java.lang.Exception

saveCurrent

private void saveCurrent()
                  throws java.lang.Exception
Saves into "users.xml" file

Throws:
java.lang.Exception

renameUser

public void renameUser(java.lang.String oldName,
                       java.lang.String newName)
                throws java.lang.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:
java.lang.Exception

setEncryptedPassword

public void setEncryptedPassword(java.lang.String userID,
                                 java.lang.String aPassword)
                          throws java.lang.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 pasword for
aPassword - the encrypted password
Throws:
java.lang.Exception

setUnencryptedPassword

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

Parameters:
userID - the user ID to change the pasword for
aPassword - the password
Throws:
java.lang.Exception

encryptPassword

public static java.lang.String encryptPassword(java.lang.String aPassword)
                                        throws java.lang.IllegalStateException
This method encrypts the password using MD5 hashing.

Parameters:
aPassword - the password to encrypt
Returns:
the MD5 hash of the password, or null if the encryption fails
Throws:
java.lang.IllegalStateException

hexToString

private static java.lang.String hexToString(byte[] data)
Converts a byte array into a hexadecimal String representation. The byte array must have an even number of elements (otherwise it would not be convertable to a valid String).

Parameters:
data - containing the bytes to convert
Returns:
the converted string, or null if encoding failed

comparePasswords

public boolean comparePasswords(java.lang.String userID,
                                java.lang.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

updateNeeded

public static boolean updateNeeded()

updateFromFile

private static void updateFromFile()
                            throws java.io.IOException,
                                   org.exolab.castor.xml.MarshalException,
                                   org.exolab.castor.xml.ValidationException
Throws:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException

OpenNMS API 1.1.4

Generated by eevans on November 12 2004 1715.