docs(openspec): rework add-admin-temporary-password to the legacy admin-set password flow
The admin types the initial password on create and a temporary password on edit; the user is saved with login = N and must change it at first sign-in. No email is needed to onboard staff. 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
7c0a34508e
commit
b49c9f1bc3
4 files changed
+185
-98
No files matched your search
@@ -2,50 +2,68 @@
|
||||
|
||||
## Context
|
||||
|
||||
- **Emailed reset:** `POST /api/admin/users/{id}/resetPassword` (mobile-api, `@AdminModule("BO_USERS")`) runs `AdminUserService.resetPassword`. That loads the target with `loadManaged`, which refuses a super admin to a non-super caller, then calls services-system `/user/resetAdminPassword`. That endpoint:
|
||||
- checks the user is type `A`, enabled, and that the email matches;
|
||||
- generates `ValidateUtil.getRandomPasswordString(8)`;
|
||||
- stores it bcrypt-encoded with `login = N`;
|
||||
- emails it.
|
||||
- **Generator:** `getRandomPasswordString` uses `java.util.Random` over an alphabet without look-alike characters.
|
||||
- **Sign-in:** `login = N` makes mobile-api answer every admin call with 403 `PASSWORD_RESET_REQUIRED` until `/api/admin/auth/first-login`. The portal redirects to the change-password page on that code.
|
||||
- **Logging:** the gateway logs no bodies (spec `gateway-request-logging`).
|
||||
- **Create today:** `AdminUserService.create` (mobile-api) saves the user through services-system `/user/save` with `login = N`. It then calls `/user/resetAdminPassword`, which generates a password, stores it and emails it. If the email is not sent, create returns 502 `TEMP_PASSWORD_NOT_SENT`.
|
||||
- **Emailed reset:** `POST /api/admin/users/{id}/resetPassword` uses `loadManaged`, 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-`A` user.
|
||||
- **`/user/save` never 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/firstTimeLogin` checks the new password against the `ADMIN_PWD_FORMAT` rules (`PasswordRuleProperty.validatePasswordRoles`). `/user/validatePasswordFromRulesForMember` does the same check against the member rules.
|
||||
- **Sign-in:** `login = N` makes mobile-api answer every admin call with 403 `PASSWORD_RESET_REQUIRED` until `/api/admin/auth/first-login`. The portal then sends the user to the change-password page.
|
||||
- **Generator:** `ValidateUtil.getRandomPasswordString` uses `java.util.Random`.
|
||||
- **Legacy:** in the Tastefully backoffice, `newUser.html` has `password` and `matchingPassword`. `UserController` creates the account with the typed password and sets `LoginStatus.N`.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:** onboard and unlock staff without email; make every generated temporary password unpredictable.
|
||||
**Goals:**
|
||||
- Onboard and unlock staff without email, the legacy way.
|
||||
- Make every generated temporary password unpredictable.
|
||||
|
||||
**Non-Goals:** admin-chosen passwords; ending the user's existing sessions on reset (the emailed reset does not do this today either); a create-form option.
|
||||
**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
|
||||
|
||||
1. **SecureRandom at the shared generator.** `getRandomPasswordString` draws from one static `SecureRandom` with `nextInt(alphabet.length())`, keeping the same alphabet. This one change covers every caller: the emailed reset, forgot-password, user creation and the new path.
|
||||
2. **services-system endpoint `POST /user/issueAdminTempPassword`** with body `{id}`:
|
||||
- It refuses (returns no password) unless the user exists, is type `A` and is enabled.
|
||||
- It generates 12 characters, stores them bcrypt-encoded with `login = N`, and returns `{"password": "<plain>"}`.
|
||||
- It sends no email.
|
||||
- It sits beside `resetAdminPassword` and is reachable only inside the cluster, through the gateway (`/user/**` route).
|
||||
- Alternative: add a "don't email" flag to `resetAdminPassword`. Rejected: that endpoint also serves the public forgot-password path, and a flag there could be misused.
|
||||
3. **mobile-api `POST /api/admin/users/{id}/temporary-password`** in `AdminUserController` (class-level `BO_USERS`), via `AdminUserService.issueTemporaryPassword(id)`:
|
||||
- It refuses its own account: 400 `SELF_NOT_ALLOWED`.
|
||||
- It uses `loadManaged`: 404 for an unknown user, and 403 for a super admin when the caller is not one.
|
||||
- It refuses a disabled user: 409 `USER_DISABLED`.
|
||||
- On success it returns `{"password": "..."}` with `Cache-Control: no-store`.
|
||||
- It logs only the audit line `temporary password set by <caller> for user <id>`, never the password.
|
||||
4. **Portal:**
|
||||
- A "Set temporary password" button on `/users/[id]`, beside the existing reset button.
|
||||
- It opens a confirmation first, then calls a new proxy route that forwards `Cache-Control: no-store`.
|
||||
- On success it shows a dialog with the password, a copy button, and the note "Shown once. The user must change it at first sign-in".
|
||||
- The password lives only in that dialog's React state and is cleared when the dialog closes. It never goes into the URL, storage or logs.
|
||||
- Refusals show their message on the page.
|
||||
5. **Handover:** `docs/deployment.md` section 10 says staff can be onboarded without email through this action.
|
||||
1. **SecureRandom at the shared generator.** `getRandomPasswordString` draws from one static `SecureRandom`, with the same alphabet.
|
||||
2. **services-system: two internal endpoints next to `resetAdminPassword`.**
|
||||
- `POST /user/validatePasswordFromRulesForAdmin {password}` mirrors the member endpoint with `ADMIN_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-`A` user;
|
||||
- re-checks the admin rules itself;
|
||||
- stores the bcrypt hash with `login = N` through the existing `userService.resetPassword`;
|
||||
- returns rows updated: 0 means refused.
|
||||
- Both endpoints are reachable only inside the cluster, through the gateway `/user/**` route, like the existing ones.
|
||||
- Alternative: let `/user/save` accept a password. Rejected: save copies the stored hash on purpose, and it serves every user update.
|
||||
3. **mobile-api create** (`AdminUserRequest` gains `password` and `confirmPassword`):
|
||||
- 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 500 `SAVE_FAILED`. The user then exists without a usable password, and the admin can fix it with "Set temporary password".
|
||||
- The `resetAdminPassword` call and `TEMP_PASSWORD_NOT_SENT` are removed.
|
||||
4. **mobile-api `POST /api/admin/users/{id}/password`** (`{password, confirmPassword}`) in `AdminUserController`, under the class-level `BO_USERS`:
|
||||
- Own account: 400 `SELF_NOT_ALLOWED`.
|
||||
- `loadManaged` gives 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_MISMATCH` and `PASSWORD_POLICY` checks as create.
|
||||
- On success: 204.
|
||||
- It logs one audit line, `temporary password set by <caller> for user <id>`, and never the password.
|
||||
5. **Portal:**
|
||||
- `/users/new` gets 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."
|
||||
- The refusal codes map to i18n messages.
|
||||
- The password lives only in form state. It never goes into the URL, storage or logs.
|
||||
6. **Handover:** `docs/deployment.md` section 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 temporary password] → It is single-use in practice: the user must change it at first sign-in before any other call works. That is the same exposure as an emailed reset, minus the mailbox.
|
||||
- [Existing sessions of the user survive the reset] → Same as the emailed reset today. Recorded as a follow-up with the existing "refreshed token stays valid" item.
|
||||
- [Clipboard access needs HTTPS] → Production is HTTPS. If the copy fails, the password stays visible and selectable.
|
||||
- **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 `password` now 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; the core-libs change ships inside each service jar. Rollback is the previous images.
|
||||
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.
|
||||
Reference in new issue
Block a user