Skip to content

Release: Phase 17 — Admin API + JWT roles + pagination (#60) - #76

Merged
Poojithvsc merged 4 commits into
mainfrom
dev
Jun 5, 2026
Merged

Release: Phase 17 — Admin API + JWT roles + pagination (#60)#76
Poojithvsc merged 4 commits into
mainfrom
dev

Conversation

@Poojithvsc

Copy link
Copy Markdown
Owner

Phase 17: authorization (roles), an operator-only product API, and pagination on the public product list. No change to the shopper-facing read/checkout flows.

What shipped

  • JWT roles — access token carries a roles claim (default ["USER"]); the auth filter maps each to a ROLE_* authority; @EnableMethodSecurity enables @PreAuthorize. Users gain a denormalised comma-separated roles column (Flyway V14), which also seeds one admin (admin@shopsphere.local, USER,ADMIN; dev-only password, documented for rotation).
  • Admin APIPOST/PUT/DELETE /api/v1/admin/products in a dedicated AdminProductController, class-level @PreAuthorize("hasRole('ADMIN')"). Authenticated non-admin → 403, anonymous → 401, seeded admin → success.
  • PaginationGET /api/v1/products?page=&size=; no params → first 20 by name; oversized size clamped to 100; response is a stable PagedResponse envelope (content + page metadata), not Spring's PageImpl.
  • ADR-0017 (code + vault mirror), article stub.

Acceptance criteria (#60)

  • Flyway migration seeds one admin (USER,ADMIN) — V14 (issue said V11; global Flyway timeline was at V13)
  • JWT roles: String[] claim for all users; default ["USER"]
  • POST/PUT/DELETE /api/v1/admin/products guarded by hasRole('ADMIN')
  • Non-admin → 403 (anonymous → 401); admin → success — AdminProductIT
  • GET /products?page=0&size=N returns ≤ N with page metadata
  • GET /products?size=200 clamped to 100 (documented in ADR-0017)
  • No-params GET /products returns the default first page (backward-compatible default; body is now a paged envelope — see ADR-0017)
  • mvn verify green (105 tests)
  • ADR-0017 written (roles model; pagination shape; revocation deferred), books cited; article stub
  • [~] Deferred with Phase 16: POST /api/v1/admin/products/{id}/image guard — that endpoint isn't built yet (ADR-0017)

Closes #60.

🤖 Generated with Claude Code

Poojithvsc and others added 4 commits June 5, 2026 19:29
…hase 17)

Access tokens now carry a `roles` claim (default ["USER"]); the auth filter
maps each role to a ROLE_* GrantedAuthority so method security can gate on it.
@EnableMethodSecurity turns on @PreAuthorize. Users gain a denormalised
comma-separated `roles` column (Flyway V14), which also seeds one admin
(admin@shopsphere.local, roles USER,ADMIN) — dev-only password, documented for
rotation. Absent/empty roles normalise to ["USER"] so pre-existing tokens still
authenticate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
POST/PUT/DELETE /api/v1/admin/products, class-level
@PreAuthorize("hasRole('ADMIN')"). Authenticated non-admin → 403, anonymous →
401 (security chain), seeded admin → create/edit/delete. AdminProductIT covers
all four.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
GET /api/v1/products takes optional Pageable; no params → first page of 20
sorted by name (backward-compatible default). Oversized ?size= is clamped to
100 via spring.data.web.pageable.max-page-size, not rejected. Response is a
stable PagedResponse envelope (content + page metadata) defined explicitly
rather than serialising Spring's PageImpl. ProductsEndpointIT updated to the
envelope + page-size/clamp cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…e 17)

Records the roles model (token claim + ROLE_* authorities; denormalised
comma-separated column over a join table, YAGNI), the guarded /admin product
controller (403 vs 401), and the pagination envelope (stable DTO over PageImpl;
oversize clamped not rejected). Honest limits: token-carried roles → up to
15-min revocation lag; seeded admin password is dev-only. Image-upload guard
deferred with Phase 16. Cites DDD/PoEAA/APoSD/XP/PragProg.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Poojithvsc
Poojithvsc merged commit 0bb4ceb into main Jun 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 17: Admin API + JWT roles + pagination

1 participant