Files
co-lite/openspec/changes/add-admin-auth-users-roles/tasks.md
T
ngqileandClaude Opus 5.5 92c8ad3b25 docs(openspec): close admin self-escalation found in review
A non-super admin cannot change their own roles or the grants of a role they hold,
hidden roles cannot be assigned, and the direct set-password endpoint goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 22:22:49 +08:00

6.7 KiB

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/**

8. Review follow-up: close self-escalation

  • 8.1 In mobile-api: delete POST /api/admin/users/{id}/changePassword and AdminUserService.changePassword; in AdminUserService refuse (403, OWN_ROLES) a non-super caller whose update changes the role set on their own account, and refuse (400, UNKNOWN_ROLE) ROLE_ADMIN or ROLE_MEMBER on create and update; in AdminAclService.updateGrants refuse (403, OWN_ROLE) a non-super caller editing a role they hold, and delete requireNoLockout, which that rule makes unreachable. Tests first for each new scenario. Verify: mvn -T 1C -B -q -pl solvway-mobile-api -am verify exits 0.
    • Scope: solvway-mobile-api/src/**/admin/**, solvway-mobile-api/src/**/service/Admin*
  • 8.2 In the portal: delete the change-password route, ChangePasswordDialog, changeAdminUserPassword and the button on the edit-user page; the emailed reset stays. Verify: npm run lint && npx tsc --noEmit && npx vitest run exit 0.
    • Scope: solvway-admin-portal/**

Workflow follow-up

  • Code review, PR to main, merge, then archive this change.