Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
5.7 KiB
5.7 KiB
Design
Context
- Create today:
AdminUserService.create(mobile-api) saves the user through services-system/user/savewithlogin = N. It then calls/user/resetAdminPassword, which generates a password, stores it and emails it. If the email is not sent, create returns 502TEMP_PASSWORD_NOT_SENT. - Emailed reset:
POST /api/admin/users/{id}/resetPasswordusesloadManaged, which gives 404 for an unknown user and 403 for a super admin when the caller is not one. It then calls/user/resetAdminPassword, which only acts on an enabled type-Auser. /user/savenever writes the password. For an existing user it copies the stored hash back. A new user is saved without one.- Password rules: services-system
/user/firstTimeLoginchecks the new password against theADMIN_PWD_FORMATrules (PasswordRuleProperty.validatePasswordRoles)./user/validatePasswordFromRulesForMemberdoes the same check against the member rules. - Sign-in:
login = Nmakes mobile-api answer every admin call with 403PASSWORD_RESET_REQUIREDuntil/api/admin/auth/first-login. The portal then sends the user to the change-password page. - Generator:
ValidateUtil.getRandomPasswordStringusesjava.util.Random. - Legacy: in the Tastefully backoffice,
newUser.htmlhaspasswordandmatchingPassword.UserControllercreates the account with the typed password and setsLoginStatus.N.
Goals / Non-Goals
Goals:
- Onboard and unlock staff without email, the legacy way.
- Make every generated temporary password unpredictable.
Non-Goals:
- Configuring email.
- Ending the user's existing sessions when an admin sets a password. The emailed reset does not do this today either.
- Showing or generating a password for the admin.
Decisions
- SecureRandom at the shared generator.
getRandomPasswordStringdraws from one staticSecureRandom, with the same alphabet. - services-system: two internal endpoints next to
resetAdminPassword.POST /user/validatePasswordFromRulesForAdmin {password}mirrors the member endpoint withADMIN_PWD_FORMAT. It returns the rules that fail; an empty list means the password passes.POST /user/setAdminPassword {id, password}:- acts only on an existing, enabled type-
Auser; - re-checks the admin rules itself;
- stores the bcrypt hash with
login = Nthrough the existinguserService.resetPassword; - returns rows updated: 0 means refused.
- acts only on an existing, enabled type-
- Both endpoints are reachable only inside the cluster, through the gateway
/user/**route, like the existing ones. - mobile-api is the only authority for who may set whose password: services-system does not check the caller or a super-admin target. So
appkeys.jsonmust never give a second key access to/user/. - Alternative: let
/user/saveaccept a password. Rejected: save copies the stored hash on purpose, and it serves every user update.
- mobile-api create (
AdminUserRequestgainspasswordandconfirmPassword):- Missing password: 400
REQUIRED_FIELD. - No match: 400
PASSWORD_MISMATCH. - Fails the rules: 400
PASSWORD_POLICY. - All three checks run before the user is saved, so a refused password creates no user.
- After the save it calls
setAdminPassword. If that returns 0, create answers 500SAVE_FAILED. The user then exists without a usable password, and the admin can fix it with "Set temporary password". - The
resetAdminPasswordcall andTEMP_PASSWORD_NOT_SENTare removed.
- Missing password: 400
- mobile-api
POST /api/admin/users/{id}/password({password, confirmPassword}) inAdminUserController, under the class-levelBO_USERS:- Own account: 400
SELF_NOT_ALLOWED. loadManagedgives 404 for an unknown user, and 403 for a super admin when the caller is not one.- Disabled user: 409
USER_DISABLED. - Then the same
REQUIRED_FIELD,PASSWORD_MISMATCHandPASSWORD_POLICYchecks as create. - On success: 204.
- It logs one audit line,
temporary password set by <caller> for user <id>, and never the password.
- Own account: 400
- Portal:
/users/newgets Password and Confirm Password inputs (type="password",autocomplete="new-password"). The client checks that they match before submitting./users/[id]gets a "Set temporary password" form beside the emailed reset, with the same two inputs.- It is hidden on the caller's own account.
- It goes through a new proxy route.
- On success it clears both fields and shows "Temporary password set. The user must change it at next sign-in."
- Refusals show the server's message, like the portal's other forms do.
- The form is hidden on the caller's own account, and while the signed-in admin is still unknown.
- The password lives only in form state. It never goes into the URL, storage or logs.
- Handover:
docs/deployment.mdsection 2 (step 6) and section 10 say the admin types each staff member's first password and passes it on in person.
Risks / Trade-offs
- The admin knows the password. The user must change it at first sign-in before any other call works. The legacy backoffice worked the same way.
- The user's existing sessions survive a password set. The emailed reset has the same gap. Recorded with the existing "refreshed token stays valid" follow-up.
- Breaking API change: create without
passwordnow fails with 400. The only caller is the portal, which ships in the same release. - Create is two calls (save, then set password). A failure between them leaves a user without a password. That is the same exposure as today's emailed create, and "Set temporary password" fixes it.
Migration Plan
No data change. Deploy services-system, mobile-api and the portal together; the core-libs change ships inside each service jar. Rollback is the previous images.