Spring Mvc · Medium · Authorization
Two customer accounts use the same project service. An incident report shows another tenant’s projects in a search response and inconsistent totals after pagination. The service authenticates correctly; the regression lies between repository results and the response projection.
Task
Repair tenant isolation and pagination as one consistent pipeline. Preserve existing authentication and error behavior.
Contract
- Request:
GET /projectsreads the supplied project repository. Query parameters are optional. - Query parameters:
q— title text to search for. Default: empty string. Trim whitespace; maximum length: 80 characters.limit— number of rows requested. Default:20; allowed integers:1..50.offset— number of matching rows to skip. Default:0; allowed integers:0..10000. Numeric parameters must contain digits only. For example,1.5,-1andabcare invalid. - Authentication:
Authorization: Bearer fixture-alphaidentifies tenantalpha;fixture-bravoidentifies tenantbravo. The supplied authentication helper resolves the tenant. A query/body field is not an identity source. - Repository records: Each project has
id,title,tenant,archived,seatsandversion. The fixture provides the data. Use its repository; no external database is required.
Acceptance criteria
- Success response: Return HTTP
200with{total, items, nextOffset}.itemscontains only{id, title, seats, version}. Do not expose the internal tenant field. - Which projects appear: Keep only the authenticated tenant’s non-archived projects. Match the title against the trimmed query without regard to letter case. Sort matching projects by ASCII ID before taking the requested page.
- Pagination:
totalis the number of all matching projects before pagination, not the page length. Skipoffsetmatches and return at mostlimititems.nextOffsetisoffset + items.lengthonly when another matching item remains; otherwise it isnull. An exhausted page hasitems: []andnextOffset: null, while keeping the fulltotal. - Errors: Invalid query: HTTP
400with{code: "INVALID_QUERY"}. Missing or unknown bearer token: HTTP401with{code: "UNAUTHORIZED"}.
Constraints
- Java 17. At most 10000 projects, query length at most 80 and 50 rows per page.
- Use the supplied repository without mutating records during a directory read.
- No database or external service is required; Maven dependencies are provisioned before offline execution.
Editable files
src/main/java/dev/acestack/projects/ProjectService.java— Repair the domain operation while preserving immutable DTOs.src/main/java/dev/acestack/projects/ProjectsController.java— Real Spring request mappings and identity boundary.src/main/java/dev/acestack/projects/ApiErrors.java— HTTP exception translation.src/main/java/dev/acestack/projects/Helpers.java— Optional implementation helpers.src/test/java/dev/acestack/projects/CandidateTest.java— Add independent MVC regressions.