feat: admin-set passwords for staff, and a secure temporary-password generator
Creating a user takes the first password from the admin, and a new
POST /api/admin/users/{id}/password lets an admin set a temporary password
for another active user. Both store the bcrypt hash with login = N, so the
user must choose their own password at the next sign-in. No email is sent.
The password must match its confirmation and pass the admin password rules.
The emailed-password generator now draws from SecureRandom.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
b49c9f1bc3
commit
2c0a847b68
12 files changed
+386
-15
No files matched your search
+21
@@ -380,6 +380,27 @@ public class UserController {
|
||||
return list.stream().filter(pass -> (pass.validatePasswordRoles(password) != null)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@RequestMapping("/validatePasswordFromRulesForAdmin")
|
||||
public List<PasswordRuleProperty> validatePasswordFromRulesForAdmin(@RequestBody HashMap<String, Object> param) {
|
||||
return adminPasswordRuleFailures(param.get("password").toString());
|
||||
}
|
||||
|
||||
private List<PasswordRuleProperty> adminPasswordRuleFailures(String password) {
|
||||
List<PasswordRuleProperty> list = passwordRuleRepository.findByType(SystemPropertyType.ADMIN_PWD_FORMAT.getName());
|
||||
return list.stream().filter(pass -> (pass.validatePasswordRoles(password) != null)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/** Stores an admin-typed password for an enabled admin user with login = N; returns rows updated (0 = refused). Never emails or logs it. */
|
||||
@RequestMapping("/setAdminPassword")
|
||||
public int setAdminPassword(@RequestBody HashMap<String, Object> param) {
|
||||
Long id = Long.parseLong(param.get("id").toString());
|
||||
String password = param.get("password").toString();
|
||||
User user = userService.findById(id).orElse(null);
|
||||
if (user == null || user.getType() != UserType.A || !user.isEnabled()) return 0;
|
||||
if (!adminPasswordRuleFailures(password).isEmpty()) return 0;
|
||||
return userService.resetPassword(id, bCryptPasswordEncoder.encode(password), LoginStatus.N);
|
||||
}
|
||||
|
||||
@RequestMapping("/validateSecondaryPasswordFromRulesForMember")
|
||||
public List<PasswordRuleProperty> validateSecondaryPasswordFromRulesForMember(@RequestBody HashMap<String, Object> param) {
|
||||
String password = param.get("secondPassword").toString();
|
||||
|
||||
Reference in new issue
Block a user