Skip to content

Commit

Permalink
Merge 1fad635 into 7efc24b
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoodrich committed Oct 17, 2023
2 parents 7efc24b + 1fad635 commit 99a8cb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 12 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,18 @@ 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
*/
@Deprecated
@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
15 changes: 4 additions & 11 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,12 @@ 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()));
if ("admin".equals(user.getUsername()) && Boolean.valueOf(Context.getRuntimeProperties()
.getProperty(ADMIN_PASSWORD_LOCKED_PROPERTY, "false"))) {
throw new APIException("admin.password.is.locked");
}

updatePassword(user, newPassword);
}

Expand Down

0 comments on commit 99a8cb9

Please sign in to comment.