Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
131 lines
7.0 KiB
Markdown
131 lines
7.0 KiB
Markdown
# Tasks
|
|
|
|
Design: `design.md`. All tasks run serially: each builds on the one before.
|
|
|
|
## 1. Data
|
|
|
|
- [x] 1.1 SQL for the table, settings and module (design decisions 1, 2 and 10).
|
|
- Files:
|
|
- `sql/01-login-audit.sql`: `CREATE TABLE IF NOT EXISTS login_audit`.
|
|
- `sql/02-lockout-settings.sql`: insert `ADMIN_LOGIN_MAX_ATTEMPT` = 5, status Y, type `ADMIN_LOGIN_BLOCK`. Set `ADMIN_LOGIN_BLOCK_PERIOD` to 15.
|
|
- `sql/03-login-security-module.sql`: the module row.
|
|
- `sql/99-rollback.sql`: drops the table, deletes both rows, and sets the period back to 1.
|
|
- Mirror 01 to 03 in `local/seed/03-colite.sql`.
|
|
- Apply them to the running local database. This is a local-only, additive change.
|
|
- Scope: `local/seed/03-colite.sql`, `openspec/changes/add-admin-login-security/sql/**`
|
|
- Verify: `select` shows the table, both settings and the module row.
|
|
|
|
## 2. services-system
|
|
|
|
- [x] 2.1 `LoginAudit` entity and repository, `LoginSecurityService` and `LoginSecurityController` (design decisions 2 and 3), plus the gateway route `/loginSecurity/**` to services-system.
|
|
- Before coding: check how mobile-api reaches services-system before a user has a token (the forgot-password path). Match that for `isLocked` and `record`, and note the finding in the task report.
|
|
- **Tests first:**
|
|
- locked at `max` failures inside the period;
|
|
- not locked when older failures fall outside it;
|
|
- a `LOGIN_SUCCESS`, `UNLOCK_RESET` or `PASSWORD_CHANGED` resets the count;
|
|
- lockout off means never locked;
|
|
- settings are read from `system_property`, with S, M, H and D handled;
|
|
- `lockedUntil` is computed as the design says;
|
|
- the locked list includes only locked usernames;
|
|
- unlock writes `UNLOCK_RESET` with who unlocked;
|
|
- `record` cuts long values and fills `company_id` for a known username, NULL otherwise;
|
|
- `audit` filters by username, event and dates, returns newest first, and caps the size at 100;
|
|
- `config` rejects a max or period below 1 and an unknown unit;
|
|
- `passwordRules` updates only `ADMIN_PWD_FORMAT` rows and refuses other ids.
|
|
- Scope: `solvway-services-system/src/**` (new login-security files, tests), `solvway-api-gateway/src/main/resources/application.yml`
|
|
- Verify: `mvn -T 1C -B -q -pl solvway-services-system,solvway-api-gateway -am verify`
|
|
|
|
- [x] 2.2 `/user/changeAdminPassword` (design decision 4).
|
|
- **Tests first,** one for each result:
|
|
- `OK` saves the bcrypt hash and keeps `login = Y`;
|
|
- `NOT_FOUND` for a non-type-A or disabled user;
|
|
- `CURRENT_PASSWORD_WRONG`;
|
|
- `PASSWORD_SAME`;
|
|
- `PASSWORD_POLICY`.
|
|
- Scope: `solvway-services-system/src/main/java/**/controller/UserController.java`, its tests
|
|
- Verify: `mvn -T 1C -B -q -pl solvway-services-system -am verify`
|
|
|
|
## 3. mobile-api
|
|
|
|
- [x] 3.1 Sign-in and sign-out enforcement and recording (design decisions 5 and 6).
|
|
- **Tests first:**
|
|
- blank fields record nothing;
|
|
- locked returns 401 `ACCOUNT_LOCKED`, records `LOGIN_LOCKED`, and never calls services-auth;
|
|
- a lock-check error continues to the password check;
|
|
- a wrong password, an unknown user or a disabled user records `LOGIN_FAIL`;
|
|
- a success records `LOGIN_SUCCESS`;
|
|
- a record failure does not change the answer;
|
|
- logout records `LOGOUT`;
|
|
- the IP and user agent are taken from `X-Client-IP` and `User-Agent`.
|
|
- Scope: `solvway-mobile-api/src/**` (`AdminAuthController`, a new login-audit client, constants, tests)
|
|
- Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify`
|
|
|
|
- [x] 3.2 `POST /api/admin/auth/change-password` (design decision 7).
|
|
- **Tests first:**
|
|
- each 400 code;
|
|
- `CURRENT_PASSWORD_WRONG` records `LOGIN_FAIL`;
|
|
- locked is refused before the services-system call;
|
|
- success records `PASSWORD_CHANGED` and returns 204;
|
|
- a pending first-login user gets 403 `PASSWORD_RESET_REQUIRED`.
|
|
- Scope: `solvway-mobile-api/src/**` (`AdminAuthController`, `AdminAuthenticationService`, request record, tests)
|
|
- Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify`
|
|
|
|
- [x] 3.3 `AdminLoginSecurityController` and service (design decision 8).
|
|
- **Tests first:**
|
|
- class-level `@AdminModule("BO_LOGIN_SECURITY")`;
|
|
- each endpoint maps its parameters;
|
|
- unlock passes the admin's username as `by` and returns 204;
|
|
- a services-system 400 on config or rules passes through as 400 with its message;
|
|
- unlock and settings changes write the log line.
|
|
- Scope: `solvway-mobile-api/src/**` (new login-security files, tests)
|
|
- Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify`
|
|
- Live check through the stack, as the dev admin and made-up local users:
|
|
- fail 5 times and see the lock;
|
|
- unlock and sign in;
|
|
- change a password;
|
|
- edit and restore the settings.
|
|
|
|
## 4. Portal
|
|
|
|
- [ ] 4.1 Sign-in pieces (design decisions 6 and 9).
|
|
- The login and logout routes forward `X-Client-IP` and `User-Agent`.
|
|
- The login page shows the locked message on `ACCOUNT_LOCKED`.
|
|
- Header "Change password" item opens `ChangePasswordDialog`, using the `/api/auth/change-password` route.
|
|
- **Tests first:**
|
|
- header forwarding;
|
|
- the locked message;
|
|
- the dialog: validation, the server code shown through `t()`, close on 204;
|
|
- the route passes refusals through with their code.
|
|
- Scope: `solvway-admin-portal/app/api/auth/**`, `solvway-admin-portal/app/login/**`, `solvway-admin-portal/app/components/app/**`, `solvway-admin-portal/app/components/users/**`, `solvway-admin-portal/app/lib/**`
|
|
- Verify: `cd solvway-admin-portal && npx vitest run && npx tsc --noEmit && npm run lint && npm run build`
|
|
|
|
- [ ] 4.2 `/login-security` page with History, Locked and Settings tabs, the proxy route, a service and i18n keys (design decision 9).
|
|
- **Tests first:**
|
|
- History rows and filters go into the query;
|
|
- Locked rows, with Unlock behind a confirm, refreshing the list;
|
|
- Settings loads, saves, and shows a server validation error;
|
|
- the rules table saves status and value;
|
|
- `RequireModule` gates the page;
|
|
- the proxy refuses dot segments.
|
|
- Scope: `solvway-admin-portal/app/login-security/**`, `solvway-admin-portal/app/api/login-security/**`, `solvway-admin-portal/app/lib/**`
|
|
- Verify: `cd solvway-admin-portal && npx vitest run && npx tsc --noEmit && npm run lint && npm run build`
|
|
|
|
## 5. Check and docs
|
|
|
|
- [ ] 5.1 Browser check and handover.
|
|
- **Playwright on the local stack, with made-up local users:**
|
|
- fail sign-in until locked and see the locked message;
|
|
- as admin, see the user under Locked, unlock them, and they sign in;
|
|
- History shows the events;
|
|
- change own password from the header, with a wrong current password first, then success;
|
|
- edit Settings and see a validation error, then restore;
|
|
- as `noevents`, see no Login security menu entry, and Not authorized at `/login-security`;
|
|
- check the pages at 360px.
|
|
- **Docs:** `docs/deployment.md` section 3 lists the new SQL files.
|
|
- Scope: `docs/deployment.md`
|
|
- Verify: screenshots, and the steps above observed.
|
|
|
|
## Workflow follow-up
|
|
|
|
- Whole-branch review, push, PR to main and merge, then archive on its own branch.
|