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, onStartup
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onShutdown, onStartup
protected 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 UserService
APIException
UserService.createUser(org.openmrs.User, java.lang.String)
public User saveUser(User user, String password) throws APIException
UserService
saveUser
in interface UserService
APIException
UserService.saveUser(org.openmrs.User, java.lang.String)
public User getUser(Integer userId) throws APIException
UserService
getUser
in interface UserService
userId
- internal identifierAPIException
UserService.getUser(java.lang.Integer)
public User getUserByUsername(String username) throws APIException
UserService
getUserByUsername
in interface UserService
username
- user's identifier used for authenticationAPIException
UserService.getUserByUsername(java.lang.String)
public boolean hasDuplicateUsername(User user) throws APIException
UserService
hasDuplicateUsername
in interface UserService
user
- User to compareAPIException
UserService.hasDuplicateUsername(org.openmrs.User)
public List<User> getUsersByRole(Role role) throws APIException
UserService
getUsersByRole
in interface UserService
role
- Role that the Users must have to be returnedAPIException
UserService.getUsersByRole(org.openmrs.Role)
public void updateUser(User user) throws APIException
saveUser(User, String)
UserService
user
to the database.updateUser
in interface UserService
APIException
UserService.updateUser(org.openmrs.User)
public void grantUserRole(User user, Role role) throws APIException
UserService
grantUserRole
in interface UserService
APIException
UserService.grantUserRole(org.openmrs.User, org.openmrs.Role)
public void revokeUserRole(User user, Role role) throws APIException
UserService
revokeUserRole
in interface UserService
APIException
UserService.revokeUserRole(org.openmrs.User, org.openmrs.Role)
public User voidUser(User user, String reason) throws APIException
UserService
voidUser
in interface UserService
APIException
UserService.voidUser(org.openmrs.User, java.lang.String)
public User retireUser(User user, String reason) throws APIException
UserService
retireUser
in interface UserService
APIException
UserService.retireUser(org.openmrs.User, java.lang.String)
public User unvoidUser(User user) throws APIException
UserService
unvoidUser
in interface UserService
APIException
UserService.unvoidUser(org.openmrs.User)
public User unretireUser(User user) throws APIException
UserService
unretireUser
in interface UserService
APIException
UserService.unretireUser(org.openmrs.User)
public void deleteUser(User user) throws APIException
deleteUser
in interface UserService
APIException
UserService.deleteUser(org.openmrs.User)
public List<User> getUsers() throws APIException
getUsers
in interface UserService
APIException
UserService.getUsers()
public List<User> getAllUsers() throws APIException
UserService
getAllUsers
in interface UserService
APIException
UserService.getAllUsers()
public List<Privilege> getPrivileges() throws APIException
getPrivileges
in interface UserService
APIException
UserService.getPrivileges()
public List<Privilege> getAllPrivileges() throws APIException
UserService
getAllPrivileges
in interface UserService
APIException
UserService.getAllPrivileges()
public Privilege getPrivilege(String p) throws APIException
UserService
getPrivilege
in interface UserService
APIException
UserService.getPrivilege(java.lang.String)
public void purgePrivilege(Privilege privilege) throws APIException
UserService
purgePrivilege
in interface UserService
privilege
- Privilege to deleteAPIException
UserService.purgePrivilege(org.openmrs.Privilege)
public Privilege savePrivilege(Privilege privilege) throws APIException
UserService
savePrivilege
in interface UserService
privilege
- Privilege to updateAPIException
UserService.savePrivilege(org.openmrs.Privilege)
public List<Role> getRoles() throws APIException
getRoles
in interface UserService
APIException
UserService.getRoles()
public List<Role> getAllRoles() throws APIException
UserService
getAllRoles
in interface UserService
APIException
UserService.getAllRoles()
public List<Role> getInheritingRoles(Role role) throws APIException
getInheritingRoles
in interface UserService
APIException
UserService.getInheritingRoles(org.openmrs.Role)
public Role getRole(String r) throws APIException
UserService
getRole
in interface UserService
APIException
UserService.getRole(java.lang.String)
public void purgeRole(Role role) throws APIException
UserService
purgeRole
in interface UserService
role
- Role to delete from the databaseAPIException
UserService.purgeRole(org.openmrs.Role)
public Role saveRole(Role role) throws APIException
UserService
saveRole
in interface UserService
role
- Role to updateAPIException
UserService.saveRole(org.openmrs.Role)
public void changePassword(User u, String pw) throws APIException
UserService
user's password
** Restricted to Super User access**
changePassword
in interface UserService
u
- userpw
- new passwordAPIException
UserService.changePassword(org.openmrs.User, java.lang.String)
public void changePassword(String pw, String pw2) throws APIException
UserService
changePassword
in interface UserService
pw
- current passwordpw2
- new passwordAPIException
UserService.changePassword(java.lang.String, java.lang.String)
public void changeHashedPassword(User user, String hashedPassword, String salt) throws APIException
UserService
changeHashedPassword
in interface UserService
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
UserService.changeHashedPassword(User, String, String)
public void changeQuestionAnswer(User u, String question, String answer) throws APIException
UserService
changeQuestionAnswer
in interface UserService
u
- User to changeAPIException
UserService.changeQuestionAnswer(User, String, String)
public void changeQuestionAnswer(String pw, String q, String a)
UserService
changeQuestionAnswer
in interface UserService
pw
- user's passwordq
- questiona
- answerUserService.changeQuestionAnswer(java.lang.String, java.lang.String,
java.lang.String)
public boolean isSecretAnswer(User u, String answer)
UserService
answer
against the user
's secret answer.isSecretAnswer
in interface UserService
u
- userUserService.isSecretAnswer(org.openmrs.User, java.lang.String)
public List<User> findUsers(String name, List<String> roles, boolean includeVoided)
findUsers
in interface UserService
UserService.findUsers(String, List, boolean)
public List<User> findUsers(String givenName, String familyName, boolean includeVoided)
findUsers
in interface UserService
UserService.findUsers(String, String, boolean)
public List<User> getUsersByName(String givenName, String familyName, boolean includeVoided) throws APIException
UserService
getUsersByName
in interface UserService
APIException
UserService.getUsersByName(java.lang.String, java.lang.String, boolean)
public List<User> getUsersByPerson(Person person, boolean includeRetired) throws APIException
UserService
getUsersByPerson
in interface UserService
APIException
UserService.getUsersByPerson(org.openmrs.Person, boolean)
public List<User> getAllUsers(List<Role> roles, boolean includeVoided)
getAllUsers
in interface UserService
UserService.getAllUsers(List, boolean)
public List<User> getUsers(String nameSearch, List<Role> roles, boolean includeVoided) throws APIException
UserService
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 themgetUsers
in interface UserService
nameSearch
- 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
UserService.getUsers(java.lang.String, java.util.List, boolean)
public User setUserProperty(User user, String key, String value)
UserService
key
/value
pair to the given user
.
Implementations of this method should handle privileges
setUserProperty
in interface UserService
UserService.setUserProperty(User, String, String)
public User removeUserProperty(User user, String key)
UserService
key
from the user
's properties.
Implementations of this method should handle privilegesremoveUserProperty
in interface UserService
UserService.removeUserProperty(org.openmrs.User, java.lang.String)
public String generateSystemId()
generateSystemId
in interface UserService
UserService.generateSystemId()
public void purgeUser(User user) throws APIException
UserService
purgeUser
in interface UserService
user
- the User to remove from the database.APIException
UserService.purgeUser(org.openmrs.User)
public void purgeUser(User user, boolean cascade) throws APIException
UserService
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.purgeUser
in interface UserService
cascade
- true
to delete associated contentAPIException
UserService.purgeUser(org.openmrs.User, boolean)
public Privilege getPrivilegeByUuid(String uuid) throws APIException
UserService
getPrivilegeByUuid
in interface UserService
APIException
UserService.getPrivilegeByUuid(java.lang.String)
public Role getRoleByUuid(String uuid) throws APIException
UserService
getRoleByUuid
in interface UserService
APIException
UserService.getRoleByUuid(java.lang.String)
public User getUserByUuid(String uuid) throws APIException
UserService
getUserByUuid
in interface UserService
APIException
UserService.getUserByUuid(java.lang.String)
public Integer getCountOfUsers(String name, List<Role> roles, boolean includeRetired)
UserService
getCountOfUsers
in interface UserService
name
- 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
UserService
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.getUsers
in interface UserService
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
UserService.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 UserService
user
- 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.