@Transactional public class UserServiceImpl extends BaseOpenmrsService implements UserService
UserService,
Context| Modifier and Type | Field and Description |
|---|---|
protected UserDAO |
dao |
ADMIN_PASSWORD_LOCKED_PROPERTY| Constructor and Description |
|---|
UserServiceImpl() |
| 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()
Generates system ids based on the following algorithm scheme: user_id-check digit
|
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 includeVoided)
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
|
void |
setUserDAO(UserDAO dao) |
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.
|
User |
unvoidUser(User user) |
User |
voidUser(User user,
String reason) |
onShutdown, onStartupclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonShutdown, onStartupprotected UserDAO dao
public void setUserDAO(UserDAO dao)
public User createUser(User user, String password) throws APIException
UserServicecreateUser in interface UserServiceuser - the user to createpassword - the password for created userAPIExceptionUserService.createUser(org.openmrs.User, java.lang.String)@Transactional(readOnly=true) public User getUser(Integer userId) throws APIException
UserServicegetUser in interface UserServiceuserId - internal identifierAPIException - Should fetch user with given userIdUserService.getUser(java.lang.Integer)@Transactional(readOnly=true) public User getUserByUsername(String username) throws APIException
UserServicegetUserByUsername in interface UserServiceusername - User's identifier used for authenticationAPIExceptionUserService.getUserByUsername(java.lang.String)@Transactional(readOnly=true) public boolean hasDuplicateUsername(User user) throws APIException
UserServicehasDuplicateUsername in interface UserServiceuser - User to compareAPIException - Should verify that username and system id is uniqueUserService.hasDuplicateUsername(org.openmrs.User)@Transactional(readOnly=true) public List<User> getUsersByRole(Role role) throws APIException
UserServicegetUsersByRole in interface UserServicerole - 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 roleUserService.getUsersByRole(org.openmrs.Role)@CacheEvict(value="userSearchLocales",
allEntries=true)
public User saveUser(User user)
throws APIException
UserServiceuser in the database.saveUser in interface UserServiceAPIExceptionUserService.saveUser(org.openmrs.User)public User voidUser(User user, String reason) throws APIException
APIExceptionpublic User retireUser(User user, String reason) throws APIException
UserServiceretireUser in interface UserServiceAPIException - Should retire user and set attributesUserService.retireUser(org.openmrs.User, java.lang.String)public User unvoidUser(User user) throws APIException
APIExceptionpublic User unretireUser(User user) throws APIException
UserServiceunretireUser in interface UserServiceAPIException - Should unretire and unmark all attributesUserService.unretireUser(org.openmrs.User)@Transactional(readOnly=true) public List<User> getAllUsers() throws APIException
UserServicegetAllUsers in interface UserServiceAPIException - Should fetch all users in the system
Should not contains any duplicate usersUserService.getAllUsers()@Transactional(readOnly=true) public List<Privilege> getAllPrivileges() throws APIException
UserServicegetAllPrivileges in interface UserServiceAPIException - Should return all privileges in the systemUserService.getAllPrivileges()@Transactional(readOnly=true) public Privilege getPrivilege(String p) throws APIException
UserServicegetPrivilege in interface UserServiceAPIException - Should fetch privilege for given nameUserService.getPrivilege(java.lang.String)public void purgePrivilege(Privilege privilege) throws APIException
UserServicepurgePrivilege in interface UserServiceprivilege - Privilege to deleteAPIException - Should delete given privilege from the database
Should throw error when privilege is core privilegeUserService.purgePrivilege(org.openmrs.Privilege)public Privilege savePrivilege(Privilege privilege) throws APIException
UserServicesavePrivilege in interface UserServiceprivilege - Privilege to updateAPIException - Should save given privilege to the databaseUserService.savePrivilege(org.openmrs.Privilege)@Transactional(readOnly=true) public List<Role> getAllRoles() throws APIException
UserServicegetAllRoles in interface UserServiceAPIException - Should return all roles in the systemUserService.getAllRoles()@Transactional(readOnly=true) public Role getRole(String r) throws APIException
UserServicegetRole in interface UserServiceAPIException - Should fetch role for given role nameUserService.getRole(java.lang.String)public void purgeRole(Role role) throws APIException
UserServicepurgeRole in interface UserServicerole - 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 databaseUserService.purgeRole(org.openmrs.Role)public Role saveRole(Role role) throws APIException
UserServicesaveRole in interface UserServicerole - Role to updateAPIException - Should throw error if role inherits from itself
Should save given role to the databaseUserService.saveRole(org.openmrs.Role)public void changePassword(String oldPassword, String newPassword) throws APIException
UserServicechangePassword in interface UserServiceoldPassword - 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 propertiesUserService.changePassword(java.lang.String, java.lang.String)public void changeHashedPassword(User user, String hashedPassword, String salt) throws APIException
UserServicechangeHashedPassword in interface UserServiceuser - the user whose password you want to changehashedPassword - - the already hashed password to storesalt - - the salt which should be used with this hashed passwordAPIExceptionUserService.changeHashedPassword(User, String, String)public void changeQuestionAnswer(User u, String question, String answer) throws APIException
UserServicechangeQuestionAnswer in interface UserServiceu - User to changeAPIExceptionUserService.changeQuestionAnswer(User, String, String)public void changeQuestionAnswer(String pw, String q, String a)
UserServicechangeQuestionAnswer in interface UserServicepw - user's passwordq - questiona - answerUserService.changeQuestionAnswer(java.lang.String, java.lang.String,
java.lang.String)@Transactional(readOnly=true) public boolean isSecretAnswer(User u, String answer)
UserServiceanswer against the user's secret answer.isSecretAnswer in interface UserServiceu - userUserService.isSecretAnswer(org.openmrs.User, java.lang.String)@Transactional(readOnly=true) public List<User> getUsersByName(String givenName, String familyName, boolean includeVoided) throws APIException
UserServicegetUsersByName in interface UserServiceAPIExceptionUserService.getUsersByName(java.lang.String, java.lang.String, boolean)@Transactional(readOnly=true) public List<User> getUsersByPerson(Person person, boolean includeRetired) throws APIException
UserServicegetUsersByPerson in interface UserServiceAPIException - Should fetch all accounts for a person when include retired is true
Should not fetch retired accounts when include retired is falseUserService.getUsersByPerson(org.openmrs.Person, boolean)@Transactional(readOnly=true) public List<User> getUsers(String nameSearch, List<Role> roles, boolean includeVoided) throws APIException
UserServicePersonByNameComparator) 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 themgetUsers in interface UserServicenameSearch - 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 usersAPIExceptionUserService.getUsers(java.lang.String, java.util.List, boolean)public User setUserProperty(User user, String key, String value)
UserServicekey/value pair to the given user.
Implementations of this method should handle privileges
setUserProperty in interface UserServiceUserService.setUserProperty(User, String, String)public User removeUserProperty(User user, String key)
UserServicekey from the user's properties.
Implementations of this method should handle privilegesremoveUserProperty in interface UserServiceUserService.removeUserProperty(org.openmrs.User, java.lang.String)@Transactional(readOnly=true) public String generateSystemId()
generateSystemId in interface UserServiceUserService.generateSystemId()public void purgeUser(User user) throws APIException
UserServicepurgeUser in interface UserServiceuser - the User to remove from the database.
Should delete given userAPIExceptionUserService.purgeUser(org.openmrs.User)public void purgeUser(User user, boolean cascade) throws APIException
UserServiceUsers 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.purgeUser in interface UserServicecascade - 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 falseAPIExceptionUserService.purgeUser(org.openmrs.User, boolean)@Transactional(readOnly=true) public Privilege getPrivilegeByUuid(String uuid) throws APIException
UserServicegetPrivilegeByUuid in interface UserServiceAPIExceptionUserService.getPrivilegeByUuid(java.lang.String)@Transactional(readOnly=true) public Role getRoleByUuid(String uuid) throws APIException
UserServicegetRoleByUuid in interface UserServiceAPIExceptionUserService.getRoleByUuid(java.lang.String)@Transactional(readOnly=true) public User getUserByUuid(String uuid) throws APIException
UserServicegetUserByUuid in interface UserServiceAPIException - Should fetch user with given uuid
Should find object given valid uuid
Should return null if no object found with given uuidUserService.getUserByUuid(java.lang.String)@Transactional(readOnly=true) public Integer getCountOfUsers(String name, List<Role> roles, boolean includeRetired)
UserServicegetCountOfUsers in interface UserServicename - patient nameroles - all the Roles the user must containincludeRetired - Specifies whether voided users should be includedUserService.getCountOfUsers(String, List, boolean)@Transactional(readOnly=true) public List<User> getUsers(String name, List<Role> roles, boolean includeRetired, Integer start, Integer length) throws APIException
UserServicePersonByNameComparator) 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.getUsers in interface UserServicename - 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 batchAPIExceptionUserService.getUsers(String, List, boolean, Integer, Integer)public User saveUserProperty(String key, String value)
UserServicesaveUserProperty in interface UserServicekey - the authenticated user's propertyvalue - value of the propertypublic User saveUserProperties(Map<String,String> properties)
UserServicesaveUserProperties in interface UserServiceproperties - the authenticated user's properties@Authorized(value="Edit User Passwords") @Logging(ignoredArgumentIndexes={1,2}) public void changePassword(User user, String oldPassword, String newPassword) throws APIException
UserServicechangePassword in interface UserServiceuser - the user to update passwordoldPassword - the user password to updatenewPassword - the new user passwordAPIException - for not existing user and if old password is weakUserService.changePassword(User, String, String)public void changePassword(User user, String newPassword)
UserServiceUser passed inchangePassword in interface UserServiceuser - user whose password is to be changednewPassword - new password to setpublic void changePasswordUsingSecretAnswer(String secretAnswer, String pw) throws APIException
UserServicechangePasswordUsingSecretAnswer in interface UserServicesecretAnswer - the answer to secret questionpw - the new password
Should update password if secret is correct
Should not update password if secret is not correctAPIExceptionpublic String getSecretQuestion(User user) throws APIException
UserServicegetSecretQuestion in interface UserServiceAPIException@Transactional(readOnly=true) public User getUserByUsernameOrEmail(String usernameOrEmail)
UserServicegetUserByUsernameOrEmail in interface UserServiceusernameOrEmail - User's email address or usernameUserService.getUserByUsernameOrEmail(java.lang.String)@Transactional(readOnly=true) public User getUserByActivationKey(String activationKey)
UserServicegetUserByActivationKey in interface UserServiceactivationKey - User's activation key for password resetUserService.getUserByActivationKey(java.lang.String)public User setUserActivationKey(User user) throws MessageException
UserServicesetUserActivationKey in interface UserServiceuser - The user for which the activation key will be setAPIExceptionMessageExceptionUserService.setUserActivationKey(org.openmrs.User)public Locale getDefaultLocaleForUser(User user)
getDefaultLocaleForUser in interface UserServiceuser - the User whose Locale to retrieveUserService.getDefaultLocaleForUser(User)public void changePasswordUsingActivationKey(String activationKey, String newPassword)
UserServicechangePasswordUsingActivationKey in interface UserServiceactivationKey - the activation for password resetnewPassword - the new passwordUserService.changePasswordUsingActivationKey(String, String);public String getLastLoginTime(User user)
UserServicegetLastLoginTime in interface UserServiceuser - the subject userUserService.getLastLoginTime(User)Copyright © 2024 OpenMRS Inc.. All rights reserved.