public class UserServiceImpl extends BaseOpenmrsService implements UserService
UserService,
Context| Modifier and Type | Field and Description |
|---|---|
protected UserDAO |
dao |
protected org.apache.commons.logging.Log |
log |
| 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 pw,
String pw2)
Changes the current user's password.
|
void |
changePassword(User u,
String pw)
Changes the
user |
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)
Deprecated.
|
void |
deleteUser(User user)
Deprecated.
|
List<User> |
findUsers(String name,
List<String> roles,
boolean includeVoided)
Deprecated.
|
List<User> |
findUsers(String givenName,
String familyName,
boolean includeVoided)
Deprecated.
|
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
|
List<User> |
getAllUsers(List<Role> roles,
boolean includeVoided)
Deprecated.
|
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
|
List<Role> |
getInheritingRoles(Role role)
Deprecated.
|
Privilege |
getPrivilege(String p)
Returns Privilege in the system with given String privilege
|
Privilege |
getPrivilegeByUuid(String uuid)
Get Privilege by its UUID
|
List<Privilege> |
getPrivileges()
Deprecated.
|
Role |
getRole(String r)
Returns role object with given string role
|
Role |
getRoleByUuid(String uuid)
Get Role by its UUID
|
List<Role> |
getRoles()
Deprecated.
|
User |
getUser(Integer userId)
Get user by internal user identifier.
|
User |
getUserByUsername(String username)
Get user by username (user's login identifier)
|
User |
getUserByUuid(String uuid)
Get user by the given uuid.
|
List<User> |
getUsers()
Deprecated.
|
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
|
void |
grantUserRole(User user,
Role role)
Deprecated.
|
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 |
notifyPrivilegeListeners(User user,
String privilege,
boolean hasPrivilege)
Notifies privilege listener beans about any privilege check.
|
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)
Deactive a user account so that it can no longer log in.
|
void |
revokeUserRole(User user,
Role role)
Deprecated.
|
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,
String password)
Saves a user to the database.
|
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)
Clear voided flag for user (equivalent to an "undelete" or Lazarus Effect for user)
|
void |
updateUser(User user)
Deprecated.
replaced by
saveUser(User, String) |
User |
voidUser(User user,
String reason)
Mark user as voided (effectively deleting user without removing their data — since
anything the user touched in the database will still have their internal identifier and point
to the voided user for historical tracking purposes.
|
onShutdown, onStartupclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonShutdown, onStartupprotected final org.apache.commons.logging.Log log
protected UserDAO dao
public void setUserDAO(UserDAO dao)
public User createUser(User user, String password) throws APIException
createUser in interface UserServiceAPIExceptionUserService.createUser(org.openmrs.User, java.lang.String)public User saveUser(User user, String password) throws APIException
UserServicesaveUser in interface UserServiceAPIExceptionUserService.saveUser(org.openmrs.User, java.lang.String)public User getUser(Integer userId) throws APIException
UserServicegetUser in interface UserServiceuserId - internal identifierAPIExceptionUserService.getUser(java.lang.Integer)public User getUserByUsername(String username) throws APIException
UserServicegetUserByUsername in interface UserServiceusername - user's identifier used for authenticationAPIExceptionUserService.getUserByUsername(java.lang.String)public boolean hasDuplicateUsername(User user) throws APIException
UserServicehasDuplicateUsername in interface UserServiceuser - User to compareAPIExceptionUserService.hasDuplicateUsername(org.openmrs.User)public List<User> getUsersByRole(Role role) throws APIException
UserServicegetUsersByRole in interface UserServicerole - Role that the Users must have to be returnedAPIExceptionUserService.getUsersByRole(org.openmrs.Role)public void updateUser(User user) throws APIException
saveUser(User, String)UserServiceuser to the database.updateUser in interface UserServiceAPIExceptionUserService.updateUser(org.openmrs.User)public void grantUserRole(User user, Role role) throws APIException
UserServicegrantUserRole in interface UserServiceAPIExceptionUserService.grantUserRole(org.openmrs.User, org.openmrs.Role)public void revokeUserRole(User user, Role role) throws APIException
UserServicerevokeUserRole in interface UserServiceAPIExceptionUserService.revokeUserRole(org.openmrs.User, org.openmrs.Role)public User voidUser(User user, String reason) throws APIException
UserServicevoidUser in interface UserServiceAPIExceptionUserService.voidUser(org.openmrs.User, java.lang.String)public User retireUser(User user, String reason) throws APIException
UserServiceretireUser in interface UserServiceAPIExceptionUserService.retireUser(org.openmrs.User, java.lang.String)public User unvoidUser(User user) throws APIException
UserServiceunvoidUser in interface UserServiceAPIExceptionUserService.unvoidUser(org.openmrs.User)public User unretireUser(User user) throws APIException
UserServiceunretireUser in interface UserServiceAPIExceptionUserService.unretireUser(org.openmrs.User)public void deleteUser(User user) throws APIException
deleteUser in interface UserServiceAPIExceptionUserService.deleteUser(org.openmrs.User)public List<User> getUsers() throws APIException
getUsers in interface UserServiceAPIExceptionUserService.getUsers()public List<User> getAllUsers() throws APIException
UserServicegetAllUsers in interface UserServiceAPIExceptionUserService.getAllUsers()public List<Privilege> getPrivileges() throws APIException
getPrivileges in interface UserServiceAPIExceptionUserService.getPrivileges()public List<Privilege> getAllPrivileges() throws APIException
UserServicegetAllPrivileges in interface UserServiceAPIExceptionUserService.getAllPrivileges()public Privilege getPrivilege(String p) throws APIException
UserServicegetPrivilege in interface UserServiceAPIExceptionUserService.getPrivilege(java.lang.String)public void purgePrivilege(Privilege privilege) throws APIException
UserServicepurgePrivilege in interface UserServiceprivilege - Privilege to deleteAPIExceptionUserService.purgePrivilege(org.openmrs.Privilege)public Privilege savePrivilege(Privilege privilege) throws APIException
UserServicesavePrivilege in interface UserServiceprivilege - Privilege to updateAPIExceptionUserService.savePrivilege(org.openmrs.Privilege)public List<Role> getRoles() throws APIException
getRoles in interface UserServiceAPIExceptionUserService.getRoles()public List<Role> getAllRoles() throws APIException
UserServicegetAllRoles in interface UserServiceAPIExceptionUserService.getAllRoles()public List<Role> getInheritingRoles(Role role) throws APIException
getInheritingRoles in interface UserServiceAPIExceptionUserService.getInheritingRoles(org.openmrs.Role)public Role getRole(String r) throws APIException
UserServicegetRole in interface UserServiceAPIExceptionUserService.getRole(java.lang.String)public void purgeRole(Role role) throws APIException
UserServicepurgeRole in interface UserServicerole - Role to delete from the databaseAPIExceptionUserService.purgeRole(org.openmrs.Role)public Role saveRole(Role role) throws APIException
UserServicesaveRole in interface UserServicerole - Role to updateAPIExceptionUserService.saveRole(org.openmrs.Role)public void changePassword(User u, String pw) throws APIException
UserServiceuser's password
** Restricted to Super User access**changePassword in interface UserServiceu - userpw - new passwordAPIExceptionUserService.changePassword(org.openmrs.User, java.lang.String)public void changePassword(String pw, String pw2) throws APIException
UserServicechangePassword in interface UserServicepw - current passwordpw2 - new passwordAPIExceptionUserService.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)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)public List<User> findUsers(String name, List<String> roles, boolean includeVoided)
findUsers in interface UserServiceUserService.findUsers(String, List, boolean)public List<User> findUsers(String givenName, String familyName, boolean includeVoided)
findUsers in interface UserServiceUserService.findUsers(String, String, boolean)public List<User> getUsersByName(String givenName, String familyName, boolean includeVoided) throws APIException
UserServicegetUsersByName in interface UserServiceAPIExceptionUserService.getUsersByName(java.lang.String, java.lang.String, boolean)public List<User> getUsersByPerson(Person person, boolean includeRetired) throws APIException
UserServicegetUsersByPerson in interface UserServiceAPIExceptionUserService.getUsersByPerson(org.openmrs.Person, boolean)public List<User> getAllUsers(List<Role> roles, boolean includeVoided)
getAllUsers in interface UserServiceUserService.getAllUsers(List, boolean)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)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.APIExceptionUserService.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 contentAPIExceptionUserService.purgeUser(org.openmrs.User, boolean)public Privilege getPrivilegeByUuid(String uuid) throws APIException
UserServicegetPrivilegeByUuid in interface UserServiceAPIExceptionUserService.getPrivilegeByUuid(java.lang.String)public Role getRoleByUuid(String uuid) throws APIException
UserServicegetRoleByUuid in interface UserServiceAPIExceptionUserService.getRoleByUuid(java.lang.String)public User getUserByUuid(String uuid) throws APIException
UserServicegetUserByUuid in interface UserServiceAPIExceptionUserService.getUserByUuid(java.lang.String)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)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 void notifyPrivilegeListeners(User user, String privilege, boolean hasPrivilege)
UserService
It is called by UserContext.hasPrivilege(java.lang.String).
notifyPrivilegeListeners in interface UserServiceuser - the authenticated user or null if not authenticatedprivilege - the checked privilegehasPrivilege - true if the authenticated user has the required privilege or if it is a proxy privilegeUserService.notifyPrivilegeListeners(User, String, boolean)Copyright © 2018 OpenMRS LLC.. All Rights Reserved.