From f97bf48d9380ed5ab8bcefe57d30c33c57117a7e Mon Sep 17 00:00:00 2001 From: ngqile Date: Thu, 26 Nov 2026 19:17:36 +0800 Subject: [PATCH] docs: propose add-admin-auth-users-roles (change 2) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../add-admin-auth-users-roles/.openspec.yaml | 2 + .../add-admin-auth-users-roles/design.md | 81 ++++++++++++ .../add-admin-auth-users-roles/proposal.md | 37 ++++++ .../specs/admin-access/spec.md | 121 ++++++++++++++++++ .../specs/admin-roles/spec.md | 48 +++++++ .../specs/admin-users/spec.md | 69 ++++++++++ .../add-admin-auth-users-roles/tasks.md | 48 +++++++ 7 files changed, 406 insertions(+) create mode 100644 openspec/changes/add-admin-auth-users-roles/.openspec.yaml create mode 100644 openspec/changes/add-admin-auth-users-roles/design.md create mode 100644 openspec/changes/add-admin-auth-users-roles/proposal.md create mode 100644 openspec/changes/add-admin-auth-users-roles/specs/admin-access/spec.md create mode 100644 openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md create mode 100644 openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md create mode 100644 openspec/changes/add-admin-auth-users-roles/tasks.md diff --git a/openspec/changes/add-admin-auth-users-roles/.openspec.yaml b/openspec/changes/add-admin-auth-users-roles/.openspec.yaml new file mode 100644 index 0000000..7ed429c --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-26 diff --git a/openspec/changes/add-admin-auth-users-roles/design.md b/openspec/changes/add-admin-auth-users-roles/design.md new file mode 100644 index 0000000..6b686b5 --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/design.md @@ -0,0 +1,81 @@ +# Design + +## Context + +- The admin portal in `solvway-admin-portal` is babyboo's full back office. Its kept screens call portal route handlers (`app/api/**`), which call `mobile-api` `/api/admin/**` through `callMobileApi` with the `api-key` header and the JWT as a Bearer token. The session is a sealed cookie (`bb_admin` by default). +- Co-Lite's `mobile-api` has no `/api/admin/**` controllers. `AppAccessAspect` checks the api-key and JWT signature and expiry only, so any valid token (member or admin) passes. +- Babyboo's `mobile-api` already solves this: `AdminAuthController`, `AdminUserController`, `AdminRoleController`, their services, `@AdminModule`, `AdminModuleAccess`, `AdminSessionGuard` and the admin checks in its `AppAccessAspect`, with unit tests. Babyboo and Co-Lite share the Solvway base, and Co-Lite's `services-system` and `services-auth` already expose every downstream endpoint those services call except the module-management and group endpoints we drop. +- `services-auth` `POST /auth/authenticate` issues admin (type A) tokens and answers 200 with an empty body on failure. `/auth/findUserByToken/BO/{token}` returns the admin user with roles and ACL menu, and returns nothing for a token stored as logged out by `/auth/logoutToken/{token}` (Redis). +- `services-system` `/user/resetAdminPassword` takes username and email, checks they match an admin, sets a random 8-character password with login status N (change required), and emails it. +- Tastefully's module rows use area `A`; babyboo's portal reads area `BO` with names like `BO_USERS`. + +## Goals / Non-Goals + +**Goals:** +- Port, not rewrite: take babyboo's admin classes and tests, then cut what depends on dropped features. +- Every rule in the specs is pinned by a test before it is implemented (porting rule in `CLAUDE.md`). + +**Non-Goals:** +- Login throttling or lockout, session-policy timeouts, Google sign-in, user groups, module management, audit log, country scope. +- Changing member (customer-portal) auth. + +## Decisions + +### 1. Port babyboo's admin layer into `mobile-api`, trimmed + +Copy `AdminAuthController`, `AdminUserController`, `AdminRoleController`, their services and DTOs, `AdminModule`, `AdminModuleAccess`, `AdminSessionGuard`, and the admin branch of babyboo's `AppAccessAspect` (`isAdminPath`, `isAdminToken`, revocation, session guard, `requireAdminModule`). Remove country scope, audit annotations, login-security and lockout handling, and anything that calls a dropped endpoint. Port the matching babyboo unit tests and adapt them; a dropped feature's tests go with it. + +Alternative: write admin controllers fresh against Tastefully's backoffice controllers. Rejected: the portal already speaks babyboo's contract, and babyboo's version has the guard and tests we need. + +### 2. Admin token check uses `findUserByToken/BO` + +On an `/api/admin/**` path the aspect loads the user with `/auth/findUserByToken/BO/{token}`. No user, or a non-admin user, means 403 for a valid member token and 401 for a revoked token. The same lookup gives the roles for the module check and the enabled and login-status flags for the session guard (deactivated means 401; pending password change allows only first-login and logout, otherwise 403). This is one downstream call per admin request. + +`ponytail:` no cache on this lookup; add a short-TTL cache keyed by token if admin latency matters. + +Alternative: a JWT claim for user type. Rejected: needs a `services-auth` change and still needs the lookup for revocation and deactivation. + +### 3. Wrong password becomes 401 in `mobile-api` + +`AdminAuthController.login` maps an empty token from `/auth/authenticate` to 401. `services-auth` stays as is, so other callers (customer portal) are unaffected. + +### 4. Forgot password reuses `/user/resetAdminPassword` + +New public endpoint `POST /api/admin/auth/forgot-password` (`@AppAuth(skipValidate=true)`) with `{username, email}`. It calls `/user/resetAdminPassword` and always answers 200 with no body detail. The admin-triggered reset (`POST /api/admin/users/{id}/resetPassword`) looks up the user and calls the same endpoint with that user's username and email. The portal gets a `/forgot-password` page (added to `PUBLIC_PATHS`) linked from the login page. + +The emailed password is plain text in the email body. That is Tastefully's existing behaviour, accepted for phase 1 because the user must change it at next login. + +### 5. Company + +`service-system` gets `company (id, name, created_at)` and `user.company_id BIGINT NULL` (nullable because member rows share the table). `services-system` `User` gains `companyId`. `AdminUserService.create` sets `companyId` from the logged-in admin, ignoring any value in the request. The seed sets company 1 on the dev admin. + +### 6. Co-Lite back-office modules + +Area `BO`, babyboo's id scheme: `40000000 BO_ROOT` (type R), `40700000 BO_USERS` (`/users`), `40800000 BO_ROLES` (`/roles`). Tastefully's area-`A` rows stay in the table and never show, because the portal reads area `BO`. The portal's `FIXED_PROTECTED_MODULE_NAMES` and `routeModules` are cut to the names that exist. + +### 7. Roles shown + +The role list hides `ROLE_MEMBER`. The local seed drops Tastefully's business roles (KYC, merchant, staff and the rest) and keeps `ROLE_SUPER_ADMIN` (1), `ROLE_ADMIN` (2) and `ROLE_MEMBER` (3). + +### 8. Portal cut-down + +Delete by directory: every `app/` route, `app/api/` family, `app/components/` folder and test not used by the kept screens (list in proposal). Then remove `package.json` dependencies with no remaining import. Rename the cookie default to `colite_admin` and replace babyboo branding strings. The kept-screen tests and the shell and middleware tests must stay green; i18n keys for removed screens go with them. + +### 9. Smoke check + +`local/smoke.sh` logs in through `POST :8080/api/admin/auth/login` and then calls `GET :8080/api/admin/me` and `GET :8080/api/admin/users`, replacing the gateway login. The service-counter read and the public call stay. + +## Risks / Trade-offs + +- [Anyone who knows a username and its email can reset that password, locking the user out until they read the email] → Accepted for phase 1 (staff-only, small team). The response never reveals a match. Throttling comes back with babyboo's login-security later. +- [The ported aspect is security code copied across codebases] → Each guard rule has a ported or new test, and the reviewer reads the whole aspect diff. +- [Deleting most of the portal breaks shared imports in ways tests miss] → `npm run build` and `npm run lint` must pass, not only `vitest`. +- [Plain-text temporary password in email] → Forced change at next login; revisit with real SMTP in change 5. + +## Migration Plan + +Additive SQL in `sql/` of this change, run against `service-system`: +1. `01-company.sql`: create `company`, add `user.company_id`, insert company 1. +2. `02-bo-modules.sql`: insert the three BO module rows. + +Nothing is deployed, so there is no live data. The same statements are mirrored into `local/seed/`. Rollback: drop the column, the table and the rows (`sql/99-rollback.sql`). diff --git a/openspec/changes/add-admin-auth-users-roles/proposal.md b/openspec/changes/add-admin-auth-users-roles/proposal.md new file mode 100644 index 0000000..91d7d28 --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/proposal.md @@ -0,0 +1,37 @@ +# Proposal + +## Why + +Lead capture (change 4) needs staff to log in to the admin portal and needs Sales users to exist. Today the copied admin portal is babyboo's full back office, and `mobile-api` has no `/api/admin/**` endpoints, so nobody can log in. This change gives Co-Lite a working staff login, user management and role permissions: the base every later admin screen builds on. See `docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md` (Admin portal, Access, Company id). + +## What Changes + +- **Admin portal cut down** to: login, first-login password change, forgot password, Users (list, create, edit, deactivate, assign roles, reset password), Roles (list, create, edit, edit permissions), the app shell with role-based menus, and the not-authorised page. Every other babyboo screen, API route, component and test is removed, along with dependencies only they used. +- **New forgot-password page** in the portal. It uses Tastefully's existing reset: username plus email, a temporary password is emailed, and the user must change it at next login. +- **`mobile-api` gains `/api/admin/**`**: auth (login, first-login, forgot password, logout, refresh), `me`, users, roles and role permissions. Ported from babyboo's AdminAuth, AdminUser and AdminRole controllers onto Co-Lite's existing `services-auth` and `services-system` endpoints. +- **Admin access enforcement** in `mobile-api`: on `/api/admin/**`, a non-admin token is rejected, a logged-out token is rejected, a pending first-login reset confines the token to the first-login endpoint, and each handler declares the modules it needs (`@AdminModule`), checked against the caller's roles. Super admin passes every module check. +- **Wrong-password login returns 401** at `/api/admin/auth/login` (today `services-auth` answers 200 with an empty body). +- **Company**: a `company` table and a `company_id` column on the admin `user` in `service-system`. New users get the creating admin's company. +- **Back-office modules**: Co-Lite's own BO module rows (root, Users, Roles) in `service-system`.`module`. SQL lives in this change folder and is mirrored in `local/seed/`. + +Not in this change: login lockout, session-policy and login-security screens, the module-management screen, user groups, audit log, Google sign-in (all babyboo features Co-Lite drops in phase 1). + +## Capabilities + +### New Capabilities +- `admin-access`: staff login, first-login password change, forgot password, logout, session, menus, and the rules that guard every `/api/admin/**` endpoint and admin portal page. +- `admin-users`: managing staff users (list, search, create, edit, deactivate, assign roles, reset password) and the company they belong to. +- `admin-roles`: managing roles and the back-office modules each role grants. + +### Modified Capabilities +None. + +## Impact + +- `solvway-admin-portal`: most of the tree is deleted; kept screens are adapted to Co-Lite (cookie name, module names, branding text). +- `solvway-mobile-api`: new admin controllers, services, `@AdminModule`, and admin checks in `AppAccessAspect`. +- `solvway-services-system`: `Company` entity, `User.companyId`, user save sets company. No new endpoints expected (the needed ones exist); any gap found is added in the task that needs it. +- `solvway-services-auth`: unchanged unless the admin token check needs it (see design). +- Database `service-system`: new table `company`, new column `user.company_id`, new `module` and `modules_roles` rows. Additive only. +- `local/seed/`: mirrors the SQL; `03-colite.sql` keeps creating the dev admin. +- `local/smoke.sh`: the admin login call moves to `/api/admin/auth/login` on mobile-api. diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-access/spec.md b/openspec/changes/add-admin-auth-users-roles/specs/admin-access/spec.md new file mode 100644 index 0000000..e46c8d3 --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/specs/admin-access/spec.md @@ -0,0 +1,121 @@ +# Spec Delta + +## Purpose + +Staff log in to the Co-Lite admin portal, and every admin page and `/api/admin/**` endpoint admits only active staff holding the module it needs. + +## ADDED Requirements + +### Requirement: Staff login + +The system SHALL let an active admin user log in with username and password through the admin portal, and SHALL return the user's name, roles, menu and whether a password change is required. + +#### Scenario: Correct credentials + +- **GIVEN** an active admin user `admin` with password `colite-dev-admin` +- **WHEN** they submit those credentials on the login page +- **THEN** they are signed in and land on the portal home +- **AND** the sidebar shows only the menu entries their roles grant + +#### Scenario: Wrong password + +- **WHEN** a user submits a wrong password +- **THEN** `/api/admin/auth/login` responds 401 +- **AND** the login page shows an invalid-credentials message without saying whether the username exists + +#### Scenario: Deactivated user + +- **GIVEN** an admin user whose account is deactivated +- **WHEN** they submit their correct password +- **THEN** login is refused with a 401 and the page shows the same invalid-credentials message + +#### Scenario: Member account + +- **WHEN** a member (non-admin) account submits its correct credentials to the admin login +- **THEN** login is refused with a 401 + +### Requirement: First-login password change + +The system SHALL require a user whose password is temporary (new user or reset) to set a new password before using any other admin page or endpoint. + +#### Scenario: Pending change confines the session + +- **GIVEN** a user logged in with a temporary password +- **WHEN** they open any portal page other than the password-change page +- **THEN** they are sent to the password-change page +- **AND** any `/api/admin/**` call other than first-login and logout responds 403 + +#### Scenario: Password changed + +- **GIVEN** a user on the password-change page +- **WHEN** they submit a new password that meets the password rules +- **THEN** the password is saved, the temporary flag clears, and they can use the portal + +### Requirement: Forgot password + +The system SHALL let a user request a temporary password by entering their username and email on a public forgot-password page. The response SHALL be the same whether or not the username and email match an active admin user. + +#### Scenario: Matching username and email + +- **GIVEN** an active admin user with username `sales1` and email `sales1@example.com` +- **WHEN** someone submits `sales1` and `sales1@example.com` +- **THEN** a temporary password is emailed to `sales1@example.com` +- **AND** the user must change it at next login +- **AND** the page shows "If the details match an account, we have emailed a temporary password." + +#### Scenario: Non-matching details + +- **WHEN** someone submits a username and email that do not match an active admin user +- **THEN** no password changes and no email is sent +- **AND** the page shows the same message as for a match + +### Requirement: Logout + +The system SHALL end the session on logout, and SHALL reject the logged-out token on every later `/api/admin/**` call even before it expires. + +#### Scenario: Token used after logout + +- **GIVEN** a user who logged out +- **WHEN** a request reuses their old token on `/api/admin/me` +- **THEN** it responds 401 + +### Requirement: Admin endpoint guard + +Every `/api/admin/**` endpoint except login and forgot password SHALL require a valid admin token, and SHALL require at least one of the back-office modules the endpoint declares, granted to one of the caller's roles. A user with the super admin role SHALL pass every module check. An endpoint that declares no module SHALL be denied to everyone except super admin. + +#### Scenario: No token + +- **WHEN** `/api/admin/users` is called without a token +- **THEN** it responds 401 + +#### Scenario: Member token on an admin path + +- **WHEN** a valid member token calls `/api/admin/me` +- **THEN** it responds 403 + +#### Scenario: Missing module + +- **GIVEN** an admin user whose roles do not grant `BO_USERS` +- **WHEN** they call `GET /api/admin/users` +- **THEN** it responds 403 + +#### Scenario: Granted module + +- **GIVEN** an admin user whose role grants `BO_USERS` +- **WHEN** they call `GET /api/admin/users` +- **THEN** it responds 200 + +### Requirement: Page guard + +The admin portal SHALL show a not-authorised page when a signed-in user opens a page whose module their roles do not grant, and SHALL send a signed-out visitor to the login page for every page except login and forgot password. + +#### Scenario: Signed-out visitor + +- **WHEN** a signed-out visitor opens `/users` +- **THEN** they are sent to the login page and return to `/users` after logging in + +#### Scenario: Page without the module + +- **GIVEN** a signed-in user without `BO_ROLES` +- **WHEN** they open `/roles` +- **THEN** the not-authorised page is shown and no role data is loaded diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md b/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md new file mode 100644 index 0000000..8ac436c --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md @@ -0,0 +1,48 @@ +# Spec Delta + +## Purpose + +Admins with the Roles module define roles and choose which back-office modules each role grants, which controls the menus and endpoints its users reach. + +## ADDED Requirements + +### Requirement: Role list and edit + +The system SHALL let an admin with `BO_ROLES` list, create and rename admin roles. Role names SHALL be unique. The member role SHALL NOT appear in the list. + +#### Scenario: Create role + +- **WHEN** an admin with `BO_ROLES` creates role `ROLE_SALES` +- **THEN** it appears in the role list and can be assigned to users + +#### Scenario: Duplicate name + +- **GIVEN** role `ROLE_SALES` exists +- **WHEN** an admin creates another role named `ROLE_SALES` +- **THEN** the save is refused with a message + +### Requirement: Role permissions + +The system SHALL let an admin with `BO_ROLES` choose, for a role, which back-office modules it grants, shown as the module tree. Saving SHALL replace the role's module grants with the chosen set. The super admin role's grants SHALL NOT be editable. + +#### Scenario: Grant Users module + +- **GIVEN** role `ROLE_SALES` without `BO_USERS` +- **WHEN** an admin grants `BO_USERS` to `ROLE_SALES` and saves +- **THEN** users with `ROLE_SALES` see Users in the sidebar after their next login or session refresh +- **AND** `GET /api/admin/users` responds 200 for them + +#### Scenario: Self lock-out + +- **GIVEN** the admin's only role that grants `BO_ROLES` is the role being edited +- **WHEN** they remove `BO_ROLES` from it and save +- **THEN** the save is refused with a message, so no admin loses access to role management by mistake + +### Requirement: Back-office module set + +The system SHALL hold Co-Lite's back-office modules in the module table, with a root entry and one entry per admin screen. This change SHALL add `BO_USERS` (Users) and `BO_ROLES` (Roles). Later changes add their own modules. + +#### Scenario: Seeded modules + +- **WHEN** the local stack starts from an empty database +- **THEN** the super admin's sidebar shows Users and Roles and no Tastefully back-office entries diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md b/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md new file mode 100644 index 0000000..e7556db --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md @@ -0,0 +1,69 @@ +# Spec Delta + +## Purpose + +Admins with the Users module manage staff accounts: who can log in, which roles they hold, and which company they belong to. + +## ADDED Requirements + +### Requirement: User list + +The system SHALL list admin users only (never members), paginated on the server, searchable by name, username or email, filterable by active state, and sortable by column. + +#### Scenario: Search + +- **GIVEN** admin users `sales1` and `sales2` and a member `m100` +- **WHEN** an admin with `BO_USERS` searches for `sales` +- **THEN** the list shows `sales1` and `sales2` and not `m100` + +### Requirement: Create user + +The system SHALL let an admin with `BO_USERS` create an admin user with name, username, email and one or more roles. Username and email SHALL be unique. The new user SHALL receive a temporary password by email and SHALL belong to the creating admin's company. + +#### Scenario: New user + +- **WHEN** an admin creates user `sales1` with email `sales1@example.com` and role Sales +- **THEN** the user is saved as active with a pending password change +- **AND** a temporary password is emailed to `sales1@example.com` +- **AND** the user's company is the creating admin's company + +#### Scenario: Duplicate username + +- **GIVEN** a user `sales1` exists +- **WHEN** an admin creates another user with username `sales1` +- **THEN** the save is refused and the form shows that the username is taken + +### Requirement: Edit and deactivate user + +The system SHALL let an admin with `BO_USERS` change a user's name, email, roles and active state. A deactivated user SHALL NOT be able to log in, and a session they already hold SHALL be refused on its next `/api/admin/**` call. An admin SHALL NOT be able to deactivate their own account. + +#### Scenario: Deactivate + +- **GIVEN** user `sales1` is signed in +- **WHEN** an admin deactivates `sales1` +- **THEN** `sales1`'s next `/api/admin/**` call responds 401 +- **AND** `sales1` can no longer log in + +#### Scenario: Self-deactivation + +- **WHEN** an admin tries to deactivate their own account +- **THEN** the save is refused with a message + +### Requirement: Admin-triggered password reset + +The system SHALL let an admin with `BO_USERS` reset another user's password, which emails the user a temporary password and requires a change at next login. + +#### Scenario: Reset + +- **WHEN** an admin resets `sales1`'s password +- **THEN** `sales1`'s old password stops working +- **AND** a temporary password is emailed to `sales1`'s email address + +### Requirement: Company membership + +Every admin user SHALL belong to exactly one company. The company SHALL be set by the system from the creating admin, never from the request. + +#### Scenario: Company in the request is ignored + +- **WHEN** a create-user request carries a company id different from the admin's own +- **THEN** the new user gets the admin's company diff --git a/openspec/changes/add-admin-auth-users-roles/tasks.md b/openspec/changes/add-admin-auth-users-roles/tasks.md new file mode 100644 index 0000000..7b4e0b7 --- /dev/null +++ b/openspec/changes/add-admin-auth-users-roles/tasks.md @@ -0,0 +1,48 @@ +# Tasks + +Babyboo source: `~/Projects/babyboo` (read only). All tasks run serially; most touch shared security code or build files. + +## 1. Database + +- [ ] 1.1 Write `sql/01-company.sql` (create `company`, add nullable `user.company_id`, insert company 1 'Co-Lite'), `sql/02-bo-modules.sql` (`40000000 BO_ROOT` R, `40700000 BO_USERS` `/users`, `40800000 BO_ROLES` `/roles`, area `BO`) and `sql/99-rollback.sql` in this change folder. Mirror them into `local/seed/` (`03-colite.sql` sets `company_id = 1` on the dev admin; `02-reference.sql` keeps only roles 1, 2, 3 and their `modules_roles` rows). Verify: `docker compose -f local/docker-compose.yml down -v && local/up.sh` exits 0, and a read-only SELECT shows the admin with company 1, the three BO modules and three roles. + - Scope: `openspec/changes/add-admin-auth-users-roles/sql/**`, `local/seed/**` + +## 2. services-system + +- [ ] 2.1 Add `companyId` to `services-system` `User` (column `company_id`) and make `/user/save` keep it. Test first: saving a user with `companyId` 1 and reading it back returns 1; saving an existing user without `companyId` does not clear it. Verify: `mvn -T 1C -pl solvway-services-system -am verify`. + - Scope: `solvway-services-system/src/**` + +## 3. mobile-api admin guard + +- [ ] 3.1 Port `AdminModule`, `AdminModuleAccess`, `AdminSessionGuard` and the admin branch of babyboo's `AppAccessAspect` (admin-path detection, admin-token check via `/auth/findUserByToken/BO/{token}`, revocation, deactivated and pending-reset handling, `requireAdminModule` with super-admin bypass, fail closed) into Co-Lite's `AppAccessAspect`, without country scope or audit. Port babyboo's tests for these classes and add tests for every `admin-access` "Admin endpoint guard" and "Logout" scenario plus: deactivated token gives 401, pending reset gives 403 except first-login and logout, undeclared handler denied to non-super admin. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. + - Scope: `solvway-mobile-api/src/main/java/**/useraccess/**`, `solvway-mobile-api/src/test/java/**/useraccess/**`, `solvway-mobile-api/src/main/resources/application*.yml` + +## 4. mobile-api admin auth + +- [ ] 4.1 Port babyboo's `AdminAuthController` and `AdminAuthenticationService` (login, first-login, logout, refresh, me) onto Co-Lite endpoints, and add `POST /api/admin/auth/forgot-password` calling `/user/resetAdminPassword`. Login answers 401 for an empty token, a deactivated user or a non-admin account; forgot-password always answers 200. Port babyboo's tests for these classes and add one per `admin-access` login, first-login and forgot-password scenario. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. + - Scope: `solvway-mobile-api/src/**/controller/admin/**`, `solvway-mobile-api/src/**/service/admin/**`, `solvway-mobile-api/src/**/dto/admin/**` (or babyboo's equivalent packages) + +## 5. mobile-api users and roles + +- [ ] 5.1 Port `AdminUserController` and `AdminUserService`: admin-only list with search, filter and sort; create with temporary password, email and company from the logged-in admin; edit; deactivate with self-deactivation refused; admin-triggered reset via `/user/resetAdminPassword`. Tests first for each `admin-users` scenario. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. + - Scope: as 4.1 +- [ ] 5.2 Port `AdminRoleController`, `AdminRoleService` and `AdminAclService` (role list hiding `ROLE_MEMBER`, create and rename with unique names, `GET/PUT /roles/{id}/modules` replacing grants, self lock-out refused, super admin grants not editable). Tests first for each `admin-roles` scenario. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. + - Scope: as 4.1 + +## 6. Admin portal + +- [ ] 6.1 Cut the portal down to login, reset-password (first login), users, roles, roles access, not-authorised and the app shell: delete every other `app/` route, `app/api/` family, component folder, lib file and test, then remove `package.json` dependencies with no remaining import and their i18n keys. Cut `routeModules` and `FIXED_PROTECTED_MODULE_NAMES` to `BO_ROOT`, `BO_USERS`, `BO_ROLES`; default cookie `colite_admin`; replace babyboo branding text. Verify: in `solvway-admin-portal`, `npm ci && npm run lint && npm run build && npm test` all exit 0. + - Scope: `solvway-admin-portal/**` +- [ ] 6.2 Add the `/forgot-password` page (public, linked from login) and its route handler calling `/api/admin/auth/forgot-password`, showing the fixed message for any outcome; make the users form refuse self-deactivation and show duplicate-username and lock-out errors from the API. Tests first (vitest) for each portal-visible scenario in the specs. Verify: `npm run lint && npm run build && npm test` exit 0. + - Scope: `solvway-admin-portal/**` + +## 7. Local stack and end-to-end check + +- [ ] 7.1 Update `local/smoke.sh` to log in via `POST :8080/api/admin/auth/login` and call `/api/admin/me` and `/api/admin/users` (keep the counter read and the public call); add the portal to the README run steps (`npm run dev` with `MOBILE_API_BASE_URL=http://localhost:8080` and the app key). Verify: fresh `local/up.sh` then `local/smoke.sh` prints `smoke: OK`. + - Scope: `local/smoke.sh`, `local/README.md`, `local/.env.example` +- [ ] 7.2 Drive the portal in a browser with Playwright against the local stack: login (correct and wrong password), first-login change for a new user, users list/create/edit/deactivate, roles create and grant `BO_USERS`, not-authorised page for a user without `BO_ROLES`, forgot-password message. Screenshots in the change folder's `verification/`. Only local dev data is created. Verify: each scenario observed as specified. + - Scope: `openspec/changes/add-admin-auth-users-roles/verification/**` + +## Workflow follow-up + +- Code review, PR to `main`, merge, then archive this change.