Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Add UserPasswordChangedEvent jmix-framework/jmix#215
Browse files Browse the repository at this point in the history
  • Loading branch information
glebshalyganov committed Aug 20, 2021
1 parent 8f24f7f commit 3c98578
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.jmix.core.security.UserManager;
import io.jmix.core.security.UserRepository;
import io.jmix.core.security.event.UserDisabledEvent;
import io.jmix.core.security.event.SingleUserPasswordChangeEvent;
import io.jmix.core.security.event.UserPasswordResetEvent;
import io.jmix.core.security.event.UserRemovedEvent;
import io.jmix.security.authentication.AcceptsGrantedAuthorities;
Expand Down Expand Up @@ -202,6 +203,7 @@ public void changePassword(String userName, @Nullable String oldPassword, @Nulla
Preconditions.checkNotNullArgument(newPassword, "Null new password");
T userDetails = loadUserByUsername(userName);
changePassword(userDetails, oldPassword, newPassword);
eventPublisher.publishEvent(new SingleUserPasswordChangeEvent(userName, newPassword));
}

private void changePassword(T userDetails, @Nullable String oldPassword, @Nullable String newPassword) throws PasswordNotMatchException {
Expand All @@ -227,7 +229,7 @@ public Map<UserDetails, String> resetPasswords(Set<UserDetails> users) {
do {
newPassword = generateRandomPassword();
try {
changePassword(user.getUsername(), null, newPassword);
changePassword(loadUserByUsername(user.getUsername()), null, newPassword);
} catch (PasswordNotMatchException e) {
continue;
}
Expand Down

0 comments on commit 3c98578

Please sign in to comment.