-
Notifications
You must be signed in to change notification settings - Fork 0
Authentication and JWT
The API uses stateless JWT bearer authentication (Spring Security resource server). There is no registration — login is the only entry point, and accounts are seeded by Flyway.
POST /api/auth/login with { username, password }:
-
AuthServiceloads the user (AppUserDetailsService/AppUserRepository). - The password is verified with BCrypt, run off the event loop (
Dispatchers.Default) so the reactive threads aren't blocked. - On success,
JwtServicemints an HS256 JWT.
Response: { accessToken, tokenType: "Bearer", expiresIn, username, role }. Bad credentials return 401 (Invalid username or password) — the same response whether or not the user exists, to avoid user enumeration.
Claims: sub (username), roles (e.g. ["ADMIN"]), iss (customermanagement), iat, exp (1 hour). Signed with HS256 using JWT_SECRET (must be ≥ 32 bytes, or the app fails fast at startup).
Send Authorization: Bearer <token>. The resource server's NimbusReactiveJwtDecoder:
- verifies the signature (HS256),
- enforces expiry and the issuer (
customermanagement), - maps the
rolesclaim to Spring authoritiesROLE_USER/ROLE_ADMIN(viaJwtGrantedAuthoritiesConverter).
Missing/invalid token → 401; valid token but insufficient role → 403.
Per-endpoint roles are enforced with method security (@PreAuthorize + @EnableReactiveMethodSecurity):
-
ADMIN — create / update / delete customers,
/api/admin/**. -
USER + ADMIN — read customers,
/api/me.
POST /api/auth/change-password with { currentPassword, newPassword } — any authenticated user, for their own account (the username comes from the token, never the body). Verifies the current password, requires the new one to differ and be 8–100 chars, updates with a targeted UPDATE, returns 204. 400 for wrong-current / reused / too-short.
| Username | Password | Role |
|---|---|---|
admin |
admin123 |
ADMIN |
user |
user123 |
USER |
See Architecture for the end-to-end auth sequence diagram, and Rate Limiting for the strict limit on the login endpoint.
Getting started
How it works
Operations
Reference