|
|
@@ -153,19 +153,10 @@ public class UserController{ |
|
|
|
@PatchMapping("/admin-change-password") |
|
|
|
@ResponseStatus(HttpStatus.NO_CONTENT) |
|
|
|
@PreAuthorize("hasAuthority('MAINTAIN_USER')") |
|
|
|
public void adminChangePassword(@RequestBody @Valid ChangePwdReq req) { |
|
|
|
public void adminChangePassword(@RequestBody @Valid AdminChangePwdReq req) { |
|
|
|
long id = req.getId(); |
|
|
|
User instance = userService.find(id).orElseThrow(NotFoundException::new); |
|
|
|
|
|
|
|
logger.info("TEST req: "+req.getPassword()); |
|
|
|
logger.info("TEST instance: "+instance.getPassword()); |
|
|
|
// if (!passwordEncoder.matches(req.getPassword(), instance.getPassword())) { |
|
|
|
// throw new BadRequestException(); |
|
|
|
// } |
|
|
|
PasswordRule rule = new PasswordRule(settingsService); |
|
|
|
if (!PasswordUtils.checkPwd(req.getNewPassword(), rule)) { |
|
|
|
throw new UnprocessableEntityException(ErrorCodes.USER_WRONG_NEW_PWD); |
|
|
|
} |
|
|
|
instance.setPassword(passwordEncoder.encode(req.getNewPassword())); |
|
|
|
userService.save(instance); |
|
|
|
} |
|
|
@@ -188,6 +179,20 @@ public class UserController{ |
|
|
|
return new PasswordRule(settingsService); |
|
|
|
} |
|
|
|
|
|
|
|
public static class AdminChangePwdReq { |
|
|
|
private Long id; |
|
|
|
@NotBlank |
|
|
|
private String newPassword; |
|
|
|
|
|
|
|
public Long getId() { return id; } |
|
|
|
public Long setId(Long id) { return this.id = id; } |
|
|
|
public String getNewPassword() { |
|
|
|
return newPassword; |
|
|
|
} |
|
|
|
public void setNewPassword(String newPassword) { |
|
|
|
this.newPassword = newPassword; |
|
|
|
} |
|
|
|
} |
|
|
|
public static class ChangePwdReq { |
|
|
|
private Long id; |
|
|
|
@NotBlank |
|
|
|