public interface UserService extends OpenmrsService
List<User> users = Context.getUserService().getAllUsers();
Context
Modifier and Type | Field and Description |
---|---|
static String |
ADMIN_PASSWORD_LOCKED_PROPERTY |
Modifier and Type | Method and Description |
---|---|
void |
changeHashedPassword(User user,
String hashedPassword,
String salt)
Changes the current user's password directly.
|
void |
changePassword(String oldPassword,
String newPassword)
Changes the current user's password.
|
void |
changePassword(User user,
String newPassword)
Changes password of
User passed in |
void |
changePassword(User user,
String oldPassword,
String newPassword)
Change user password.
|
void |
changePasswordUsingActivationKey(String activationKey,
String newPassword)
Change user password given the activation key
|
void |
changePasswordUsingSecretAnswer(String secretAnswer,
String pw)
Change user password given the answer to the secret question
|
void |
changeQuestionAnswer(String pw,
String q,
String a)
Changes the current user's secret question and answer.
|
void |
changeQuestionAnswer(User u,
String question,
String answer)
Changes the passed user's secret question and answer.
|
User |
createUser(User user,
String password)
Create user with given password.
|
String |
generateSystemId()
Get/generate/find the next system id to be doled out.
|
List<Privilege> |
getAllPrivileges()
Returns all privileges currently possible for any User
|
List<Role> |
getAllRoles()
Returns all roles currently possible for any User
|
List<User> |
getAllUsers()
Returns all users in the system
|
Integer |
getCountOfUsers(String name,
List<Role> roles,
boolean includeRetired)
Return the number of users with a matching name or system id and have at least one of the
given roles assigned to them
|
Locale |
getDefaultLocaleForUser(User user) |
String |
getLastLoginTime(User user)
Retrieves the last login time of the user in Unix Timestamp
|
Privilege |
getPrivilege(String p)
Returns Privilege in the system with given String privilege
|
Privilege |
getPrivilegeByUuid(String uuid)
Get Privilege by its UUID
|
Role |
getRole(String r)
Returns role object with given string role
|
Role |
getRoleByUuid(String uuid)
Get Role by its UUID
|
String |
getSecretQuestion(User user)
Returns secret question for the given user.
|
User |
getUser(Integer userId)
Get user by internal user identifier.
|
User |
getUserByActivationKey(String activationKey)
Gets a user with the specified activation key
|
User |
getUserByUsername(String username)
Get user by username (user's login identifier)
|
User |
getUserByUsernameOrEmail(String usernameOrEmail)
Gets a user by username or email
|
User |
getUserByUuid(String uuid)
Get user by the given uuid.
|
List<User> |
getUsers(String nameSearch,
List<Role> roles,
boolean includeVoided)
Return a list of users sorted by personName (see
PersonByNameComparator ) if any part
of the search matches first/last/system id and the user has one at least one of the given
roles assigned to them |
List<User> |
getUsers(String name,
List<Role> roles,
boolean includeRetired,
Integer start,
Integer length)
Return a batch of users of a specific size sorted by personName (see
PersonByNameComparator ) if any part of the search matches first/last/system id and
the user has one at least one of the given roles assigned to them. |
List<User> |
getUsersByName(String givenName,
String familyName,
boolean includeRetired)
Search for a list of users by exact first name and last name.
|
List<User> |
getUsersByPerson(Person person,
boolean includeRetired)
Get all user accounts that belong to a given person.
|
List<User> |
getUsersByRole(Role role)
Get users by role granted
|
boolean |
hasDuplicateUsername(User user)
true/false if username or systemId is already in db in username or system_id columns
|
boolean |
isSecretAnswer(User u,
String answer)
Compares
answer against the user 's secret answer. |
void |
purgePrivilege(Privilege privilege)
Completely remove a privilege from the database
|
void |
purgeRole(Role role)
Complete remove a role from the database
|
void |
purgeUser(User user)
Completely remove a location from the database (not reversible).
|
void |
purgeUser(User user,
boolean cascade)
Completely remove a user from the database (not reversible).
|
User |
removeUserProperty(User user,
String key)
Removes the property denoted by
key from the user 's properties. |
User |
retireUser(User user,
String reason)
Deactivate a user account so that it can no longer log in.
|
Privilege |
savePrivilege(Privilege privilege)
Save the given privilege in the database
|
Role |
saveRole(Role role)
Save the given role in the database
|
User |
saveUser(User user)
Updates a given
user in the database. |
User |
saveUserProperties(Map<String,String> properties)
Replaces all user properties with the given map of properties for the current user
|
User |
saveUserProperty(String key,
String value)
Saves the current key/value as a user property for the current user.
|
User |
setUserActivationKey(User user)
Sets a user's activation key
|
User |
setUserProperty(User user,
String key,
String value)
Adds the
key /value pair to the given user . |
User |
unretireUser(User user)
Clears retired flag for a user.
|
onShutdown, onStartup
static final String ADMIN_PASSWORD_LOCKED_PROPERTY
@Authorized(value="Add Users") @Logging(ignoredArgumentIndexes=1) User createUser(User user, String password) throws APIException
user
- the user to createpassword
- the password for created userAPIException
@Authorized(value="Edit User Passwords") @Logging(ignoredArgumentIndexes={1,2}) void changePassword(User user, String oldPassword, String newPassword) throws APIException
user
- the user to update passwordoldPassword
- the user password to updatenewPassword
- the new user passwordAPIException
- for not existing user and if old password is weak@Authorized(value="Get Users") User getUser(Integer userId) throws APIException
userId
- internal identifierAPIException
- Should fetch user with given userId@Authorized(value="Get Users") User getUserByUuid(String uuid) throws APIException
uuid
- APIException
- Should fetch user with given uuid
Should find object given valid uuid
Should return null if no object found with given uuid@Authorized(value="Get Users") User getUserByUsername(String username)
username
- User's identifier used for authentication@Authorized(value="Get Users") User getUserByUsernameOrEmail(String usernameOrEmail)
usernameOrEmail
- User's email address or username@Authorized(value="Get Users") User getUserByActivationKey(String activationKey)
activationKey
- User's activation key for password reset@Authorized(value="Get Users") boolean hasDuplicateUsername(User user) throws APIException
user
- User to compareAPIException
- Should verify that username and system id is unique@Authorized(value="Get Users") List<User> getUsersByRole(Role role) throws APIException
role
- Role that the Users must have to be returnedAPIException
- Should fetch users assigned given role
Should not fetch user that does not belong to given role@Authorized(value="Edit Users") User saveUser(User user) throws APIException
user
in the database.user
- APIException
@Authorized(value="Edit Users") User retireUser(User user, String reason) throws APIException
user
- reason
- APIException
- Should retire user and set attributes@Authorized(value="Edit Users") User unretireUser(User user) throws APIException
user
- APIException
- Should unretire and unmark all attributes@Authorized(value="Purge Users") void purgeUser(User user) throws APIException
user
- the User to remove from the database.
Should delete given userAPIException
@Authorized(value="Purge Users") void purgeUser(User user, boolean cascade) throws APIException
Users
should be
voided and not deleted altogether (since many foreign key constraints
depend on users, deleting a user would require deleting all traces, and any historical trail
would be lost). This method only clears user roles and attempts to delete the user record. If
the user has been included in any other parts of the database (through a foreign key), the
attempt to delete the user will violate foreign key constraints and fail.cascade
- true
to delete associated content
Should throw APIException if cascade is true
Should delete given user when cascade equals false
Should not delete user roles for given user when cascade equals falseAPIException
@Authorized(value="Manage Privileges") List<Privilege> getAllPrivileges() throws APIException
APIException
- Should return all privileges in the system@Authorized(value="Manage Roles") List<Role> getAllRoles() throws APIException
APIException
- Should return all roles in the system@Authorized(value="Manage Roles") Role saveRole(Role role) throws APIException
role
- Role to updateAPIException
- Should throw error if role inherits from itself
Should save given role to the database@Authorized(value="Purge Roles") void purgeRole(Role role) throws APIException
role
- Role to delete from the databaseAPIException
- Should throw error when role is a core role
Should return if role is null
Should delete given role from database@Authorized(value="Manage Privileges") Privilege savePrivilege(Privilege privilege) throws APIException
privilege
- Privilege to updateAPIException
- Should save given privilege to the database@Authorized(value="Purge Privileges") void purgePrivilege(Privilege privilege) throws APIException
privilege
- Privilege to deleteAPIException
- Should delete given privilege from the database
Should throw error when privilege is core privilege@Authorized(value="Get Roles") Role getRole(String r) throws APIException
APIException
- Should fetch role for given role name@Authorized(value="Get Roles") Role getRoleByUuid(String uuid) throws APIException
uuid
- APIException
@Authorized(value="Get Privileges") Privilege getPrivilege(String p) throws APIException
APIException
- Should fetch privilege for given name@Authorized(value="Get Privileges") Privilege getPrivilegeByUuid(String uuid) throws APIException
uuid
- APIException
@Authorized(value="Get Users") List<User> getAllUsers() throws APIException
APIException
- Should fetch all users in the system
Should not contains any duplicate users@Authorized @Logging(ignoredArgumentIndexes={0,1}) void changePassword(String oldPassword, String newPassword) throws APIException
oldPassword
- current passwordnewPassword
- new passwordAPIException
- Should match on correctly hashed sha1 stored password
Should match on incorrectly hashed sha1 stored password
Should match on sha512 hashed password
Should be able to update password multiple times
Should respect locking via runtime properties@Authorized(value="Edit User Passwords") void changePassword(User user, String newPassword) throws APIException
User
passed inuser
- user whose password is to be changednewPassword
- new password to setAPIException
- Should update password of given user when logged in user has edit users password privilege
Should not update password of given user when logged in user does not have edit users password privilege@Authorized(value="Edit User Passwords") void changeHashedPassword(User user, String hashedPassword, String salt) throws APIException
user
- the user whose password you want to changehashedPassword
- - the already hashed password to storesalt
- - the salt which should be used with this hashed passwordAPIException
@Authorized(value="Edit User Passwords") @Logging(ignoredArgumentIndexes={1,2}) void changeQuestionAnswer(User u, String question, String answer) throws APIException
u
- User to changequestion
- answer
- APIException
@Authorized @Logging(ignoreAllArgumentValues=true) void changeQuestionAnswer(String pw, String q, String a) throws APIException
pw
- user's passwordq
- questiona
- answerAPIException
- Should match on correctly hashed stored password
Should match on incorrectly hashed stored passwordString getSecretQuestion(User user) throws APIException
user
- APIException
@Logging(ignoredArgumentIndexes=1) boolean isSecretAnswer(User u, String answer) throws APIException
answer
against the user
's secret answer.u
- useranswer
- APIException
- Should return true when given answer matches stored secret answer
Should return false when given answer does not match the stored secret answer@Authorized(value="Get Users") List<User> getUsers(String nameSearch, List<Role> roles, boolean includeVoided) throws APIException
PersonByNameComparator
) if any part
of the search matches first/last/system id and the user has one at least one of the given
roles
assigned to themnameSearch
- string to compare to the beginning of user's given/middle/family/family2
namesroles
- all the Roles the user must containincludeVoided
- true/false whether to include voided usersAPIException
@Authorized(value="Get Users") List<User> getUsersByName(String givenName, String familyName, boolean includeRetired) throws APIException
givenName
- familyName
- includeRetired
- APIException
@Authorized(value="Get Users") List<User> getUsersByPerson(Person person, boolean includeRetired) throws APIException
person
- includeRetired
- APIException
- Should fetch all accounts for a person when include retired is true
Should not fetch retired accounts when include retired is false@Authorized User setUserProperty(User user, String key, String value) throws APIException
key
/value
pair to the given user
.
Implementations of this method should handle privileges
user
- key
- value
- APIException
@Authorized User removeUserProperty(User user, String key) throws APIException
key
from the user
's properties.
Implementations of this method should handle privilegesuser
- key
- APIException
@Authorized String generateSystemId()
@Authorized(value="Get Users") List<User> getUsers(String name, List<Role> roles, boolean includeRetired, Integer start, Integer length) throws APIException
PersonByNameComparator
) if any part of the search matches first/last/system id and
the user has one at least one of the given roles
assigned to them. If start and
length are not specified, then all matches are returned, If name is empty or null, then all
all users will be returned taking into consideration the values of start and length
arguments.name
- string to compare to the beginning of user's given/middle/family/family2 namesroles
- all the Roles the user must containincludeRetired
- true/false whether to include voided usersstart
- beginning index for the batchlength
- number of users to return in the batchAPIException
@Authorized(value="Get Users") Integer getCountOfUsers(String name, List<Role> roles, boolean includeRetired)
name
- patient nameroles
- all the Roles the user must containincludeRetired
- Specifies whether voided users should be included@Authorized User saveUserProperty(String key, String value)
key
- the authenticated user's propertyvalue
- value of the property@Authorized User saveUserProperties(Map<String,String> properties)
properties
- the authenticated user's properties@Authorized void changePasswordUsingSecretAnswer(String secretAnswer, String pw) throws APIException
secretAnswer
- the answer to secret questionpw
- the new password
Should update password if secret is correct
Should not update password if secret is not correctAPIException
@Authorized(value="Edit User Passwords") User setUserActivationKey(User user) throws MessageException
user
- The user for which the activation key will be setMessageException
void changePasswordUsingActivationKey(String activationKey, String newPassword)
activationKey
- the activation for password resetnewPassword
- the new password@Authorized Locale getDefaultLocaleForUser(User user)
user
- the User whose Locale to retrieve@Authorized String getLastLoginTime(User user)
user
- the subject userCopyright © 2024 OpenMRS Inc.. All rights reserved.