
Authentication is one of the areas where home-grown solutions cost dearly. In our Spring Boot projects we rely on standards: Spring Security, OAuth2 and JWT.
The model
- Authorization Server (e.g. Keycloak, Azure AD/Entra ID or another identity provider): issues tokens.
- Resource Server: our API, which validates the tokens.
- Client: a web app, mobile app or another system.
The API never sees user passwords. It only checks that the token is valid and what permissions it carries.
Resource Server configuration
With spring-boot-starter-oauth2-resource-server and the issuer URL, Spring automatically fetches the keys (JWKS) and validates signature, expiry and issuer. All that remains is mapping claims to roles.
Roles and access rules
Per-endpoint rules in the SecurityFilterChain and @PreAuthorize for finer-grained checks, for example “only the owner of the document or an administrator”.
Common mistakes
- Tokens with very long lifetimes.
- Accepting tokens without checking the audience.
- Sensitive data inside the JWT, which is encoded but not encrypted.
- Storing tokens in localStorage in web applications.
- CORS open to all origins.
Service-to-service
For communication between systems we use the client credentials flow or mutual TLS, as is often required for integrations with public bodies.
Need an authentication review or design for your application? Get in touch.




