Package org.opennms.netmgt.config
Class UserManager
- java.lang.Object
-
- org.opennms.netmgt.config.UserManager
-
- All Implemented Interfaces:
UserConfig
- Direct Known Subclasses:
MockUserManager
,UserFactory
public abstract class UserManager extends java.lang.Object implements UserConfig
Abstract UserManager class.
- Author:
- David Hustace, Matt Brozowski, Benjamin Reed, Jeff Gehlbach
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.opennms.netmgt.config.api.UserConfig
UserConfig.ContactType
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALLOW_UNSALTED_PROPERTY
protected java.util.Map<java.lang.String,java.util.List<DutySchedule>>
m_dutySchedules
The duty schedules for each userprotected GroupManager
m_groupManager
protected java.util.Map<java.lang.String,User>
m_users
A mapping of user IDs to the User objects
-
Constructor Summary
Constructors Modifier Constructor Description protected
UserManager(GroupManager groupManager)
Constructor for UserManager.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
checkSaltedPassword(java.lang.String raw, java.lang.String encrypted)
checkSaltedPasswordboolean
comparePasswords(java.lang.String userID, java.lang.String aPassword)
This method compares two encrypted strings for equality.int
countUsersWithRole(java.lang.String roleid)
countUsersWithRolevoid
deleteUser(java.lang.String name)
Removes the user from the list of users.protected abstract void
doUpdate()
updatejava.lang.String
encryptedPassword(java.lang.String aPassword, boolean useSalt)
encryptedPasswordjava.lang.String
getContactInfo(java.lang.String userID, java.lang.String command)
Get the contact info given a command stringjava.lang.String
getContactInfo(java.lang.String userId, UserConfig.ContactType contactType)
getContactInfojava.lang.String
getContactInfo(User user, java.lang.String command)
getContactInfojava.lang.String
getContactServiceProvider(java.lang.String userID, java.lang.String command)
Get the contact service provider, given a command stringjava.lang.String
getContactServiceProvider(User user, java.lang.String command)
getContactServiceProviderjava.lang.String
getEmail(java.lang.String userID)
Get a email by namejava.lang.String
getEmail(User user)
Get a email by userabstract long
getFileSize()
java.lang.String
getHomePhone(java.lang.String userID)
Get a home phone numberjava.lang.String
getHomePhone(User user)
Get a home phone numberabstract long
getLastModified()
java.lang.String
getMicroblogName(java.lang.String name)
Get a user's microblog username by usernamejava.lang.String
getMicroblogName(User user)
Get a user's microblog username by Userjava.lang.String
getMobilePhone(java.lang.String userID)
Get a mobile phone numberjava.lang.String
getMobilePhone(User user)
Get a mobile phone numberjava.lang.String
getNumericPage(java.lang.String userID)
Get a numeric service providerjava.lang.String
getNumericPage(User user)
Get a numeric service providerjava.lang.String
getNumericPin(java.lang.String userID)
Get a numeric pinjava.lang.String
getNumericPin(User user)
Get a numeric pinOnmsUser
getOnmsUser(java.lang.String username)
getOnmsUserOnmsUserList
getOnmsUserList()
getOnmsUserListjava.lang.String
getPagerEmail(java.lang.String userID)
Get a pager email by namejava.lang.String
getPagerEmail(User user)
Get a pager email by userjava.lang.String
getTextPage(java.lang.String userID)
Get a Text Page Service Providerjava.lang.String
getTextPage(User user)
Get a Text Page Service Providerjava.lang.String
getTextPin(java.lang.String userID)
Get a text pinjava.lang.String
getTextPin(User user)
Get a text pinjava.lang.String
getTuiPin(java.lang.String name)
Get a user's telephone PIN by namejava.lang.String
getTuiPin(User user)
Get a user's telephone PIN by User objectUser
getUser(java.lang.String name)
Get a user by namejava.util.List<java.lang.String>
getUserNames()
getUserNamesjava.util.Map<java.lang.String,User>
getUsers()
Return aMap
of usernames to user instances.java.lang.String[]
getUsersScheduledForRole(java.lang.String roleid, java.util.Date time)
getUsersScheduledForRolejava.lang.String[]
getUsersWithRole(java.lang.String roleid)
getUsersWithRolejava.lang.String
getWorkPhone(java.lang.String userID)
Get a work phone numberjava.lang.String
getWorkPhone(User user)
Get a work phone numberjava.lang.String
getXMPPAddress(java.lang.String userID)
Get an XMPP address by namejava.lang.String
getXMPPAddress(User user)
Get an XMPP address by nameboolean
hasOnCallRole(java.lang.String roleid)
hasOnCallRoleboolean
hasUser(java.lang.String userName)
Returns a boolean indicating if the user name appears in the XML fileabstract boolean
isUpdateNeeded()
boolean
isUserOnDuty(java.lang.String user, java.util.Calendar time)
Determines if a user is on duty at a given time.boolean
isUserScheduledForRole(User user, java.lang.String roleid, java.util.Date time)
isUserScheduledForRolevoid
parseXML(java.io.InputStream in)
parseXMLabstract void
reload()
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.void
save(OnmsUser onmsUser)
savevoid
saveUser(java.lang.String name, User details)
Adds a new user and overwrites the "users.xml"void
saveUsers(java.util.Collection<User> usersList)
saveUsersprotected abstract void
saveXML(java.lang.String writerString)
saveXMLvoid
setContactInfo(java.lang.String userId, UserConfig.ContactType contactType, java.lang.String contactValue)
setContactInfovoid
setEncryptedPassword(java.lang.String userID, java.lang.String aPassword, boolean salted)
Sets the password for this user, assuming that the value passed in is already encrypted properlyvoid
setUnencryptedPassword(java.lang.String userID, java.lang.String aPassword)
Sets the password for this user, first encrypting itvoid
update()
updateboolean
userHasRole(User user, java.lang.String roleid)
userHasRole
-
-
-
Field Detail
-
ALLOW_UNSALTED_PROPERTY
public static final java.lang.String ALLOW_UNSALTED_PROPERTY
- See Also:
- Constant Field Values
-
m_groupManager
protected GroupManager m_groupManager
-
m_users
protected java.util.Map<java.lang.String,User> m_users
A mapping of user IDs to the User objects
-
m_dutySchedules
protected java.util.Map<java.lang.String,java.util.List<DutySchedule>> m_dutySchedules
The duty schedules for each user
-
-
Constructor Detail
-
UserManager
protected UserManager(GroupManager groupManager)
Constructor for UserManager.
- Parameters:
groupManager
- aGroupManager
object.
-
-
Method Detail
-
parseXML
public void parseXML(java.io.InputStream in)
parseXML
- Specified by:
parseXML
in interfaceUserConfig
- Parameters:
in
- aInputStream
object.
-
saveUser
public void saveUser(java.lang.String name, User details) throws java.lang.Exception
Adds a new user and overwrites the "users.xml"- Specified by:
saveUser
in interfaceUserConfig
- Parameters:
name
- aString
object.details
- aUser
object.- Throws:
java.lang.Exception
- if any.
-
save
public void save(OnmsUser onmsUser) throws java.lang.Exception
Description copied from interface:UserConfig
save
- Specified by:
save
in interfaceUserConfig
- Throws:
java.lang.Exception
-
isUserOnDuty
public boolean isUserOnDuty(java.lang.String user, java.util.Calendar time) throws java.io.IOException
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.- Specified by:
isUserOnDuty
in interfaceUserConfig
- Parameters:
user
- the user idtime
- the time to check for a duty schedule- Returns:
- boolean, true if the user is on duty, false otherwise.
- Throws:
java.io.IOException
- if any.
-
getUsers
public java.util.Map<java.lang.String,User> getUsers() throws java.io.IOException
Return aMap
of usernames to user instances.- Specified by:
getUsers
in interfaceUserConfig
- Returns:
- a
Map
object. - Throws:
java.io.IOException
- if any.
-
getOnmsUserList
public OnmsUserList getOnmsUserList() throws java.io.IOException
Description copied from interface:UserConfig
getOnmsUserList
- Specified by:
getOnmsUserList
in interfaceUserConfig
- Returns:
- an OnmsUserList
- Throws:
java.io.IOException
-
getOnmsUser
public OnmsUser getOnmsUser(java.lang.String username) throws java.io.IOException
Description copied from interface:UserConfig
getOnmsUser
- Specified by:
getOnmsUser
in interfaceUserConfig
- Returns:
- an OnmsUser
- Throws:
java.io.IOException
-
hasUser
public boolean hasUser(java.lang.String userName) throws java.io.IOException
Returns a boolean indicating if the user name appears in the XML file- Specified by:
hasUser
in interfaceUserConfig
- Parameters:
userName
- aString
object.- Returns:
- true if the user exists in the XML file, false otherwise
- Throws:
java.io.IOException
- if any.
-
getUserNames
public java.util.List<java.lang.String> getUserNames() throws java.io.IOException
getUserNames
- Specified by:
getUserNames
in interfaceUserConfig
- Returns:
- a
List
object. - Throws:
java.io.IOException
- if any.
-
getUser
public User getUser(java.lang.String name) throws java.io.IOException
Get a user by name- Specified by:
getUser
in interfaceUserConfig
- Parameters:
name
- the name of the user to return- Returns:
- the user specified by name
- Throws:
java.io.IOException
- if any.
-
getTuiPin
public java.lang.String getTuiPin(java.lang.String name) throws java.io.IOException
Get a user's telephone PIN by name- Specified by:
getTuiPin
in interfaceUserConfig
- Parameters:
name
- the name of the user to return- Returns:
- the telephone PIN of the user specified by name
- Throws:
java.io.IOException
- if any.
-
getTuiPin
public java.lang.String getTuiPin(User user) throws java.io.IOException
Get a user's telephone PIN by User object- Specified by:
getTuiPin
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- the telephone PIN of the user specified by user
- Throws:
java.io.IOException
- if any.
-
getMicroblogName
public java.lang.String getMicroblogName(java.lang.String name) throws java.io.FileNotFoundException, java.io.IOException
Get a user's microblog username by username- Specified by:
getMicroblogName
in interfaceUserConfig
- Parameters:
name
- the username of the user whose microblog username should be returned- Returns:
- the microblog username of the specified user
- Throws:
java.io.IOException
- if any.java.io.FileNotFoundException
- if any.
-
getMicroblogName
public java.lang.String getMicroblogName(User user) throws java.io.FileNotFoundException, java.io.IOException
Get a user's microblog username by User- Parameters:
user
- the user object of the user whose microblog username should be returned- Returns:
- the microblog username of the specified user
- Throws:
java.io.IOException
- if any.java.io.FileNotFoundException
- if any.
-
setContactInfo
public void setContactInfo(java.lang.String userId, UserConfig.ContactType contactType, java.lang.String contactValue) throws java.lang.Exception
Description copied from interface:UserConfig
setContactInfo
- Specified by:
setContactInfo
in interfaceUserConfig
- Throws:
java.lang.Exception
-
getContactInfo
public java.lang.String getContactInfo(java.lang.String userId, UserConfig.ContactType contactType) throws java.io.IOException
Description copied from interface:UserConfig
getContactInfo
- Specified by:
getContactInfo
in interfaceUserConfig
- Returns:
- a String
- Throws:
java.io.IOException
-
getContactInfo
public java.lang.String getContactInfo(java.lang.String userID, java.lang.String command) throws java.io.IOException
Get the contact info given a command string- Specified by:
getContactInfo
in interfaceUserConfig
- Parameters:
userID
- the name of the usercommand
- the command to look up the contact info for- Returns:
- the contact information
- Throws:
java.io.IOException
- if any.
-
getContactInfo
public java.lang.String getContactInfo(User user, java.lang.String command) throws java.io.IOException
getContactInfo
- Specified by:
getContactInfo
in interfaceUserConfig
- Parameters:
user
- aUser
object.command
- aString
object.- Returns:
- a
String
object. - Throws:
java.io.IOException
- if any.
-
getContactServiceProvider
public java.lang.String getContactServiceProvider(java.lang.String userID, java.lang.String command) throws java.io.IOException
Get the contact service provider, given a command string- Specified by:
getContactServiceProvider
in interfaceUserConfig
- Parameters:
userID
- the name of the usercommand
- the command to look up the contact info for- Returns:
- the contact information
- Throws:
java.io.IOException
- if any.
-
getContactServiceProvider
public java.lang.String getContactServiceProvider(User user, java.lang.String command) throws java.io.IOException
getContactServiceProvider
- Specified by:
getContactServiceProvider
in interfaceUserConfig
- Parameters:
user
- aUser
object.command
- aString
object.- Returns:
- a
String
object. - Throws:
java.io.IOException
- if any.
-
getEmail
public java.lang.String getEmail(java.lang.String userID) throws java.io.IOException
Get a email by name- Specified by:
getEmail
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the email specified by name
- Throws:
java.io.IOException
- if any.
-
getEmail
public java.lang.String getEmail(User user) throws java.io.IOException
Get a email by user- Specified by:
getEmail
in interfaceUserConfig
- Parameters:
user
- the user to find the email for- Returns:
- String the email specified by name
- Throws:
java.io.IOException
- if any.
-
getPagerEmail
public java.lang.String getPagerEmail(java.lang.String userID) throws java.io.IOException
Get a pager email by name- Specified by:
getPagerEmail
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the pager email
- Throws:
java.io.IOException
- if any.
-
getPagerEmail
public java.lang.String getPagerEmail(User user) throws java.io.IOException
Get a pager email by user- Specified by:
getPagerEmail
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the pager email
- Throws:
java.io.IOException
- if any.
-
getNumericPin
public java.lang.String getNumericPin(java.lang.String userID) throws java.io.IOException
Get a numeric pin- Specified by:
getNumericPin
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the numeric pin
- Throws:
java.io.IOException
- if any.
-
getNumericPin
public java.lang.String getNumericPin(User user) throws java.io.IOException
Get a numeric pin- Specified by:
getNumericPin
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the numeric pin
- Throws:
java.io.IOException
- if any.
-
getXMPPAddress
public java.lang.String getXMPPAddress(java.lang.String userID) throws java.io.IOException
Get an XMPP address by name- Specified by:
getXMPPAddress
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the XMPP address
- Throws:
java.io.IOException
- if any.
-
getXMPPAddress
public java.lang.String getXMPPAddress(User user) throws java.io.IOException
Get an XMPP address by name- Specified by:
getXMPPAddress
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the XMPP address
- Throws:
java.io.IOException
- if any.
-
getNumericPage
public java.lang.String getNumericPage(java.lang.String userID) throws java.io.IOException
Get a numeric service provider- Specified by:
getNumericPage
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the service provider
- Throws:
java.io.IOException
- if any.
-
getNumericPage
public java.lang.String getNumericPage(User user) throws java.io.IOException
Get a numeric service provider- Specified by:
getNumericPage
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the service provider
- Throws:
java.io.IOException
- if any.
-
getTextPin
public java.lang.String getTextPin(java.lang.String userID) throws java.io.IOException
Get a text pin- Specified by:
getTextPin
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the text pin
- Throws:
java.io.IOException
- if any.
-
getTextPin
public java.lang.String getTextPin(User user) throws java.io.IOException
Get a text pin- Specified by:
getTextPin
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the text pin
- Throws:
java.io.IOException
- if any.
-
getTextPage
public java.lang.String getTextPage(java.lang.String userID) throws java.io.IOException
Get a Text Page Service Provider- Specified by:
getTextPage
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the text page service provider.
- Throws:
java.io.IOException
- if any.
-
getTextPage
public java.lang.String getTextPage(User user) throws java.io.IOException
Get a Text Page Service Provider- Specified by:
getTextPage
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the text page service provider.
- Throws:
java.io.IOException
- if any.
-
getWorkPhone
public java.lang.String getWorkPhone(java.lang.String userID) throws java.io.IOException
Get a work phone number- Specified by:
getWorkPhone
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the work phone number
- Throws:
java.io.IOException
- if any.
-
getWorkPhone
public java.lang.String getWorkPhone(User user) throws java.io.IOException
Get a work phone number- Specified by:
getWorkPhone
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the work phone number
- Throws:
java.io.IOException
- if any.
-
getMobilePhone
public java.lang.String getMobilePhone(java.lang.String userID) throws java.io.IOException
Get a mobile phone number- Specified by:
getMobilePhone
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the mobile phone number
- Throws:
java.io.IOException
- if any.
-
getMobilePhone
public java.lang.String getMobilePhone(User user) throws java.io.IOException
Get a mobile phone number- Specified by:
getMobilePhone
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the mobile phone number
- Throws:
java.io.IOException
- if any.
-
getHomePhone
public java.lang.String getHomePhone(java.lang.String userID) throws java.io.IOException
Get a home phone number- Specified by:
getHomePhone
in interfaceUserConfig
- Parameters:
userID
- the user ID of the user to return- Returns:
- String the home phone number
- Throws:
java.io.IOException
- if any.
-
getHomePhone
public java.lang.String getHomePhone(User user) throws java.io.IOException
Get a home phone number- Specified by:
getHomePhone
in interfaceUserConfig
- Parameters:
user
- aUser
object.- Returns:
- String the home phone number
- Throws:
java.io.IOException
- if any.
-
saveUsers
public void saveUsers(java.util.Collection<User> usersList) throws java.lang.Exception
saveUsers
- Specified by:
saveUsers
in interfaceUserConfig
- Parameters:
usersList
- aCollection
object.- Throws:
java.lang.Exception
- if any.
-
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"- Specified by:
deleteUser
in interfaceUserConfig
- Parameters:
name
- aString
object.- Throws:
java.lang.Exception
- if any.
-
saveXML
protected abstract void saveXML(java.lang.String writerString) throws java.io.IOException
saveXML
- Parameters:
writerString
- aString
object.- Throws:
java.io.IOException
- if any.
-
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- Specified by:
renameUser
in interfaceUserConfig
- Parameters:
oldName
- aString
object.newName
- aString
object.- Throws:
java.lang.Exception
- if any.
-
setEncryptedPassword
public void setEncryptedPassword(java.lang.String userID, java.lang.String aPassword, boolean salted) throws java.lang.Exception
Sets the password for this user, assuming that the value passed in is already encrypted properly- Specified by:
setEncryptedPassword
in interfaceUserConfig
- Parameters:
userID
- the user ID to change the password foraPassword
- the encrypted password- Throws:
java.lang.Exception
- if any.
-
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- Specified by:
setUnencryptedPassword
in interfaceUserConfig
- Parameters:
userID
- the user ID to change the password foraPassword
- the password- Throws:
java.lang.Exception
- if any.
-
encryptedPassword
public java.lang.String encryptedPassword(java.lang.String aPassword, boolean useSalt)
encryptedPassword
- Specified by:
encryptedPassword
in interfaceUserConfig
- Parameters:
aPassword
- aString
object.useSalt
- TODO- Returns:
- a
String
object.
-
comparePasswords
public boolean comparePasswords(java.lang.String userID, java.lang.String aPassword)
This method compares two encrypted strings for equality.- Specified by:
comparePasswords
in interfaceUserConfig
- 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
-
checkSaltedPassword
public boolean checkSaltedPassword(java.lang.String raw, java.lang.String encrypted)
Description copied from interface:UserConfig
checkSaltedPassword
- Specified by:
checkSaltedPassword
in interfaceUserConfig
- Returns:
- a boolean
-
doUpdate
protected abstract void doUpdate() throws java.io.IOException, java.io.FileNotFoundException
update
- Throws:
java.io.IOException
- if any.java.io.FileNotFoundException
- if any.
-
update
public final void update() throws java.io.IOException
Description copied from interface:UserConfig
update
- Specified by:
update
in interfaceUserConfig
- Throws:
java.io.IOException
java.io.FileNotFoundException
-
getUsersWithRole
public java.lang.String[] getUsersWithRole(java.lang.String roleid) throws java.io.IOException
getUsersWithRole
- Specified by:
getUsersWithRole
in interfaceUserConfig
- Parameters:
roleid
- aString
object.- Returns:
- an array of
String
objects. - Throws:
java.io.IOException
- if any.
-
userHasRole
public boolean userHasRole(User user, java.lang.String roleid) throws java.io.FileNotFoundException, java.io.IOException
userHasRole
- Specified by:
userHasRole
in interfaceUserConfig
- Parameters:
user
- aUser
object.roleid
- aString
object.- Returns:
- a boolean.
- Throws:
java.io.FileNotFoundException
- if any.java.io.IOException
- if any.
-
isUserScheduledForRole
public boolean isUserScheduledForRole(User user, java.lang.String roleid, java.util.Date time) throws java.io.FileNotFoundException, java.io.IOException
isUserScheduledForRole
- Specified by:
isUserScheduledForRole
in interfaceUserConfig
- Parameters:
user
- aUser
object.roleid
- aString
object.time
- aDate
object.- Returns:
- a boolean.
- Throws:
java.io.FileNotFoundException
- if any.java.io.IOException
- if any.
-
getUsersScheduledForRole
public java.lang.String[] getUsersScheduledForRole(java.lang.String roleid, java.util.Date time) throws java.io.IOException
getUsersScheduledForRole
- Specified by:
getUsersScheduledForRole
in interfaceUserConfig
- Parameters:
roleid
- aString
object.time
- aDate
object.- Returns:
- an array of
String
objects. - Throws:
java.io.IOException
- if any.
-
hasOnCallRole
public boolean hasOnCallRole(java.lang.String roleid) throws java.io.IOException
hasOnCallRole
- Specified by:
hasOnCallRole
in interfaceUserConfig
- Parameters:
roleid
- aString
object.- Returns:
- a boolean.
- Throws:
java.io.IOException
- if any.
-
countUsersWithRole
public int countUsersWithRole(java.lang.String roleid) throws java.io.IOException
countUsersWithRole
- Specified by:
countUsersWithRole
in interfaceUserConfig
- Parameters:
roleid
- aString
object.- Returns:
- a int.
- Throws:
java.io.IOException
- if any.
-
isUpdateNeeded
public abstract boolean isUpdateNeeded()
-
getLastModified
public abstract long getLastModified()
-
getFileSize
public abstract long getFileSize()
-
reload
public abstract void reload() throws java.io.IOException, java.io.FileNotFoundException
- Throws:
java.io.IOException
java.io.FileNotFoundException
-
-