Skip to content

Commit

Permalink
TRUNK-6187: Protect admin credentials with runtime property (#4413)
Browse files Browse the repository at this point in the history
* TRUNK-6187: Protect admin credentials with runtime property
add "changePassword" User Service API function back in

* TRUNK-6187: Protect admin credentials with runtime property
add "changePassword" User Service API function back in
  • Loading branch information
mogoodrich committed Oct 17, 2023
1 parent 7efc24b commit ebde188
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 11 additions & 0 deletions api/src/main/java/org/openmrs/api/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ public interface UserService extends OpenmrsService {
*/
@Logging(ignoredArgumentIndexes = { 0, 1 })
public void changePassword(String oldPassword, String newPassword) throws APIException;

/**
* Changes password of {@link User} passed in
* @param user user whose password is to be changed
* @param newPassword new password to set
* @throws APIException
* <strong>Should</strong> update password of given user when logged in user has edit users password privilege
* <strong>Should</strong> not update password of given user when logged in user does not have edit users password privilege
*/
@Authorized({PrivilegeConstants.EDIT_USER_PASSWORDS})
public void changePassword(User user, String newPassword) throws APIException;

/**
* Changes the current user's password directly. This is most useful if migrating users from
Expand Down
13 changes: 1 addition & 12 deletions api/src/main/java/org/openmrs/api/impl/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,19 +660,8 @@ public void changePassword(User user, String oldPassword, String newPassword) th
updatePassword(user, newPassword);
}

/**
* This is for internal use only. DO NOT CALL THIS METHOD.
*
* @param user The user's password to change
* @param newPassword The password to change it to
*/
@Authorized(PrivilegeConstants.EDIT_USER_PASSWORDS)
@Override
public void changePassword(User user, String newPassword) {
if (!Daemon.isDaemonThread() || !Context.getUserContext().getAuthenticatedUser().isSuperUser()) {
throw new APIAuthenticationException(Context.getMessageSourceService().getMessage("error.privilegesRequired",
new Object[] { "System Developer" }, Context.getLocale()));
}

updatePassword(user, newPassword);
}

Expand Down

0 comments on commit ebde188

Please sign in to comment.