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.StringALLOW_UNSALTED_PROPERTYprotected java.util.Map<java.lang.String,java.util.List<DutySchedule>>m_dutySchedulesThe duty schedules for each userprotected GroupManagerm_groupManagerprotected java.util.Map<java.lang.String,User>m_usersA mapping of user IDs to the User objects
-
Constructor Summary
Constructors Modifier Constructor Description protectedUserManager(GroupManager groupManager)Constructor for UserManager.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancheckSaltedPassword(java.lang.String raw, java.lang.String encrypted)checkSaltedPasswordbooleancomparePasswords(java.lang.String userID, java.lang.String aPassword)This method compares two encrypted strings for equality.intcountUsersWithRole(java.lang.String roleid)countUsersWithRolevoiddeleteUser(java.lang.String name)Removes the user from the list of users.protected abstract voiddoUpdate()updatejava.lang.StringencryptedPassword(java.lang.String aPassword, boolean useSalt)encryptedPasswordjava.lang.StringgetContactInfo(java.lang.String userID, java.lang.String command)Get the contact info given a command stringjava.lang.StringgetContactInfo(java.lang.String userId, UserConfig.ContactType contactType)getContactInfojava.lang.StringgetContactInfo(User user, java.lang.String command)getContactInfojava.lang.StringgetContactServiceProvider(java.lang.String userID, java.lang.String command)Get the contact service provider, given a command stringjava.lang.StringgetContactServiceProvider(User user, java.lang.String command)getContactServiceProviderjava.lang.StringgetEmail(java.lang.String userID)Get a email by namejava.lang.StringgetEmail(User user)Get a email by userabstract longgetFileSize()java.lang.StringgetHomePhone(java.lang.String userID)Get a home phone numberjava.lang.StringgetHomePhone(User user)Get a home phone numberabstract longgetLastModified()java.lang.StringgetMicroblogName(java.lang.String name)Get a user's microblog username by usernamejava.lang.StringgetMicroblogName(User user)Get a user's microblog username by Userjava.lang.StringgetMobilePhone(java.lang.String userID)Get a mobile phone numberjava.lang.StringgetMobilePhone(User user)Get a mobile phone numberjava.lang.StringgetNumericPage(java.lang.String userID)Get a numeric service providerjava.lang.StringgetNumericPage(User user)Get a numeric service providerjava.lang.StringgetNumericPin(java.lang.String userID)Get a numeric pinjava.lang.StringgetNumericPin(User user)Get a numeric pinOnmsUsergetOnmsUser(java.lang.String username)getOnmsUserOnmsUserListgetOnmsUserList()getOnmsUserListjava.lang.StringgetPagerEmail(java.lang.String userID)Get a pager email by namejava.lang.StringgetPagerEmail(User user)Get a pager email by userjava.lang.StringgetTextPage(java.lang.String userID)Get a Text Page Service Providerjava.lang.StringgetTextPage(User user)Get a Text Page Service Providerjava.lang.StringgetTextPin(java.lang.String userID)Get a text pinjava.lang.StringgetTextPin(User user)Get a text pinjava.lang.StringgetTuiPin(java.lang.String name)Get a user's telephone PIN by namejava.lang.StringgetTuiPin(User user)Get a user's telephone PIN by User objectUsergetUser(java.lang.String name)Get a user by namejava.util.List<java.lang.String>getUserNames()getUserNamesjava.util.Map<java.lang.String,User>getUsers()Return aMapof 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.StringgetWorkPhone(java.lang.String userID)Get a work phone numberjava.lang.StringgetWorkPhone(User user)Get a work phone numberjava.lang.StringgetXMPPAddress(java.lang.String userID)Get an XMPP address by namejava.lang.StringgetXMPPAddress(User user)Get an XMPP address by namebooleanhasOnCallRole(java.lang.String roleid)hasOnCallRolebooleanhasUser(java.lang.String userName)Returns a boolean indicating if the user name appears in the XML fileabstract booleanisUpdateNeeded()booleanisUserOnDuty(java.lang.String user, java.util.Calendar time)Determines if a user is on duty at a given time.booleanisUserScheduledForRole(User user, java.lang.String roleid, java.util.Date time)isUserScheduledForRolevoidparseXML(java.io.InputStream in)parseXMLabstract voidreload()voidrenameUser(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.voidsave(OnmsUser onmsUser)savevoidsaveUser(java.lang.String name, User details)Adds a new user and overwrites the "users.xml"voidsaveUsers(java.util.Collection<User> usersList)saveUsersprotected abstract voidsaveXML(java.lang.String writerString)saveXMLvoidsetContactInfo(java.lang.String userId, UserConfig.ContactType contactType, java.lang.String contactValue)setContactInfovoidsetEncryptedPassword(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 properlyvoidsetUnencryptedPassword(java.lang.String userID, java.lang.String aPassword)Sets the password for this user, first encrypting itvoidupdate()updatebooleanuserHasRole(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- aGroupManagerobject.
-
-
Method Detail
-
parseXML
public void parseXML(java.io.InputStream in)
parseXML
- Specified by:
parseXMLin interfaceUserConfig- Parameters:
in- aInputStreamobject.
-
saveUser
public void saveUser(java.lang.String name, User details) throws java.lang.ExceptionAdds a new user and overwrites the "users.xml"- Specified by:
saveUserin interfaceUserConfig- Parameters:
name- aStringobject.details- aUserobject.- Throws:
java.lang.Exception- if any.
-
save
public void save(OnmsUser onmsUser) throws java.lang.Exception
Description copied from interface:UserConfigsave
- Specified by:
savein interfaceUserConfig- Throws:
java.lang.Exception
-
isUserOnDuty
public boolean isUserOnDuty(java.lang.String user, java.util.Calendar time) throws java.io.IOExceptionDetermines 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:
isUserOnDutyin 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 aMapof usernames to user instances.- Specified by:
getUsersin interfaceUserConfig- Returns:
- a
Mapobject. - Throws:
java.io.IOException- if any.
-
getOnmsUserList
public OnmsUserList getOnmsUserList() throws java.io.IOException
Description copied from interface:UserConfiggetOnmsUserList
- Specified by:
getOnmsUserListin interfaceUserConfig- Returns:
- an OnmsUserList
- Throws:
java.io.IOException
-
getOnmsUser
public OnmsUser getOnmsUser(java.lang.String username) throws java.io.IOException
Description copied from interface:UserConfiggetOnmsUser
- Specified by:
getOnmsUserin interfaceUserConfig- Returns:
- an OnmsUser
- Throws:
java.io.IOException
-
hasUser
public boolean hasUser(java.lang.String userName) throws java.io.IOExceptionReturns a boolean indicating if the user name appears in the XML file- Specified by:
hasUserin interfaceUserConfig- Parameters:
userName- aStringobject.- 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.IOExceptiongetUserNames
- Specified by:
getUserNamesin interfaceUserConfig- Returns:
- a
Listobject. - 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:
getUserin 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.IOExceptionGet a user's telephone PIN by name- Specified by:
getTuiPinin 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:
getTuiPinin interfaceUserConfig- Parameters:
user- aUserobject.- 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.IOExceptionGet a user's microblog username by username- Specified by:
getMicroblogNamein 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.ExceptionDescription copied from interface:UserConfigsetContactInfo
- Specified by:
setContactInfoin interfaceUserConfig- Throws:
java.lang.Exception
-
getContactInfo
public java.lang.String getContactInfo(java.lang.String userId, UserConfig.ContactType contactType) throws java.io.IOExceptionDescription copied from interface:UserConfiggetContactInfo
- Specified by:
getContactInfoin 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.IOExceptionGet the contact info given a command string- Specified by:
getContactInfoin 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:
getContactInfoin interfaceUserConfig- Parameters:
user- aUserobject.command- aStringobject.- Returns:
- a
Stringobject. - Throws:
java.io.IOException- if any.
-
getContactServiceProvider
public java.lang.String getContactServiceProvider(java.lang.String userID, java.lang.String command) throws java.io.IOExceptionGet the contact service provider, given a command string- Specified by:
getContactServiceProviderin 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:
getContactServiceProviderin interfaceUserConfig- Parameters:
user- aUserobject.command- aStringobject.- Returns:
- a
Stringobject. - Throws:
java.io.IOException- if any.
-
getEmail
public java.lang.String getEmail(java.lang.String userID) throws java.io.IOExceptionGet a email by name- Specified by:
getEmailin 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:
getEmailin 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.IOExceptionGet a pager email by name- Specified by:
getPagerEmailin 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:
getPagerEmailin interfaceUserConfig- Parameters:
user- aUserobject.- Returns:
- String the pager email
- Throws:
java.io.IOException- if any.
-
getNumericPin
public java.lang.String getNumericPin(java.lang.String userID) throws java.io.IOExceptionGet a numeric pin- Specified by:
getNumericPinin 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:
getNumericPinin interfaceUserConfig- Parameters:
user- aUserobject.- Returns:
- String the numeric pin
- Throws:
java.io.IOException- if any.
-
getXMPPAddress
public java.lang.String getXMPPAddress(java.lang.String userID) throws java.io.IOExceptionGet an XMPP address by name- Specified by:
getXMPPAddressin 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:
getXMPPAddressin interfaceUserConfig- Parameters:
user- aUserobject.- Returns:
- String the XMPP address
- Throws:
java.io.IOException- if any.
-
getNumericPage
public java.lang.String getNumericPage(java.lang.String userID) throws java.io.IOExceptionGet a numeric service provider- Specified by:
getNumericPagein 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:
getNumericPagein interfaceUserConfig- Parameters:
user- aUserobject.- Returns:
- String the service provider
- Throws:
java.io.IOException- if any.
-
getTextPin
public java.lang.String getTextPin(java.lang.String userID) throws java.io.IOExceptionGet a text pin- Specified by:
getTextPinin 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:
getTextPinin interfaceUserConfig- Parameters:
user- aUserobject.- Returns:
- String the text pin
- Throws:
java.io.IOException- if any.
-
getTextPage
public java.lang.String getTextPage(java.lang.String userID) throws java.io.IOExceptionGet a Text Page Service Provider- Specified by:
getTextPagein 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:
getTextPagein interfaceUserConfig- Parameters:
user- aUserobject.- 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.IOExceptionGet a work phone number- Specified by:
getWorkPhonein 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:
getWorkPhonein interfaceUserConfig- Parameters:
user- aUserobject.- 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.IOExceptionGet a mobile phone number- Specified by:
getMobilePhonein 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:
getMobilePhonein interfaceUserConfig- Parameters:
user- aUserobject.- 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.IOExceptionGet a home phone number- Specified by:
getHomePhonein 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:
getHomePhonein interfaceUserConfig- Parameters:
user- aUserobject.- 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:
saveUsersin interfaceUserConfig- Parameters:
usersList- aCollectionobject.- Throws:
java.lang.Exception- if any.
-
deleteUser
public void deleteUser(java.lang.String name) throws java.lang.ExceptionRemoves the user from the list of users. Then overwrites to the "users.xml"- Specified by:
deleteUserin interfaceUserConfig- Parameters:
name- aStringobject.- Throws:
java.lang.Exception- if any.
-
saveXML
protected abstract void saveXML(java.lang.String writerString) throws java.io.IOExceptionsaveXML
- Parameters:
writerString- aStringobject.- Throws:
java.io.IOException- if any.
-
renameUser
public void renameUser(java.lang.String oldName, java.lang.String newName) throws java.lang.ExceptionWhen 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:
renameUserin interfaceUserConfig- Parameters:
oldName- aStringobject.newName- aStringobject.- Throws:
java.lang.Exception- if any.
-
setEncryptedPassword
public void setEncryptedPassword(java.lang.String userID, java.lang.String aPassword, boolean salted) throws java.lang.ExceptionSets the password for this user, assuming that the value passed in is already encrypted properly- Specified by:
setEncryptedPasswordin 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.ExceptionSets the password for this user, first encrypting it- Specified by:
setUnencryptedPasswordin 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:
encryptedPasswordin interfaceUserConfig- Parameters:
aPassword- aStringobject.useSalt- TODO- Returns:
- a
Stringobject.
-
comparePasswords
public boolean comparePasswords(java.lang.String userID, java.lang.String aPassword)This method compares two encrypted strings for equality.- Specified by:
comparePasswordsin 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:UserConfigcheckSaltedPassword
- Specified by:
checkSaltedPasswordin interfaceUserConfig- Returns:
- a boolean
-
doUpdate
protected abstract void doUpdate() throws java.io.IOException, java.io.FileNotFoundExceptionupdate
- Throws:
java.io.IOException- if any.java.io.FileNotFoundException- if any.
-
update
public final void update() throws java.io.IOExceptionDescription copied from interface:UserConfigupdate
- Specified by:
updatein interfaceUserConfig- Throws:
java.io.IOExceptionjava.io.FileNotFoundException
-
getUsersWithRole
public java.lang.String[] getUsersWithRole(java.lang.String roleid) throws java.io.IOExceptiongetUsersWithRole
- Specified by:
getUsersWithRolein interfaceUserConfig- Parameters:
roleid- aStringobject.- Returns:
- an array of
Stringobjects. - 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:
userHasRolein interfaceUserConfig- Parameters:
user- aUserobject.roleid- aStringobject.- 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:
isUserScheduledForRolein interfaceUserConfig- Parameters:
user- aUserobject.roleid- aStringobject.time- aDateobject.- 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.IOExceptiongetUsersScheduledForRole
- Specified by:
getUsersScheduledForRolein interfaceUserConfig- Parameters:
roleid- aStringobject.time- aDateobject.- Returns:
- an array of
Stringobjects. - Throws:
java.io.IOException- if any.
-
hasOnCallRole
public boolean hasOnCallRole(java.lang.String roleid) throws java.io.IOExceptionhasOnCallRole
- Specified by:
hasOnCallRolein interfaceUserConfig- Parameters:
roleid- aStringobject.- Returns:
- a boolean.
- Throws:
java.io.IOException- if any.
-
countUsersWithRole
public int countUsersWithRole(java.lang.String roleid) throws java.io.IOExceptioncountUsersWithRole
- Specified by:
countUsersWithRolein interfaceUserConfig- Parameters:
roleid- aStringobject.- 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.IOExceptionjava.io.FileNotFoundException
-
-