mobile-api now records the browser user agent the portal forwards as X-Client-User-Agent instead of the portal server's own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
7.1 KiB
7.1 KiB
Tasks
Design: design.md. All tasks run serially: each builds on the one before.
1. Data
- 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: insertADMIN_LOGIN_MAX_ATTEMPT= 5, status Y, typeADMIN_LOGIN_BLOCK. SetADMIN_LOGIN_BLOCK_PERIODto 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:
selectshows the table, both settings and the module row.
- Files:
2. services-system
-
2.1
LoginAuditentity and repository,LoginSecurityServiceandLoginSecurityController(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
isLockedandrecord, and note the finding in the task report. - Tests first:
- locked at
maxfailures inside the period; - not locked when older failures fall outside it;
- a
LOGIN_SUCCESS,UNLOCK_RESETorPASSWORD_CHANGEDresets the count; - lockout off means never locked;
- settings are read from
system_property, with S, M, H and D handled; lockedUntilis computed as the design says;- the locked list includes only locked usernames;
- unlock writes
UNLOCK_RESETwith who unlocked; recordcuts long values and fillscompany_idfor a known username, NULL otherwise;auditfilters by username, event and dates, returns newest first, and caps the size at 100;configrejects a max or period below 1 and an unknown unit;passwordRulesupdates onlyADMIN_PWD_FORMATrows and refuses other ids.
- locked at
- 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
- Before coding: check how mobile-api reaches services-system before a user has a token (the forgot-password path). Match that for
-
2.2
/user/changeAdminPassword(design decision 4).- Tests first, one for each result:
OKsaves the bcrypt hash and keepslogin = Y;NOT_FOUNDfor 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
- Tests first, one for each result:
3. mobile-api
-
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, recordsLOGIN_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-IpandX-Client-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
- Tests first:
-
3.2
POST /api/admin/auth/change-password(design decision 7).- Tests first:
- each 400 code;
CURRENT_PASSWORD_WRONGrecordsLOGIN_FAIL;- locked is refused before the services-system call;
- success records
PASSWORD_CHANGEDand 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
- Tests first:
-
3.3
AdminLoginSecurityControllerand service (design decision 8).- Tests first:
- class-level
@AdminModule("BO_LOGIN_SECURITY"); - each endpoint maps its parameters;
- unlock passes the admin's username as
byand 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.
- class-level
- 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.
- Tests first:
4. Portal
-
4.1 Sign-in pieces (design decisions 6 and 9).
- The login and logout routes forward
X-Client-IpandX-Client-User-Agent. - The login page shows the locked message on
ACCOUNT_LOCKED. - Header "Change password" item opens
ChangePasswordDialog, using the/api/auth/change-passwordroute. - 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
- The login and logout routes forward
-
4.2
/login-securitypage 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;
RequireModulegates 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
- Tests first:
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.mdsection 3 lists the new SQL files. - Scope:
docs/deployment.md - Verify: screenshots, and the steps above observed.
- Playwright on the local stack, with made-up local users:
Workflow follow-up
- Whole-branch review, push, PR to main and merge, then archive on its own branch.