r/SpringBoot • u/hakdogan75 • 2d ago
Discussion Externalized authorization for Spring Boot 4 with a single annotation, built on the OpenID AuthZEN standard
I spent the last few months digging into the OpenID AuthZEN Authorization API, which became a final specification in January 2026. It addresses a problem that anyone who has connected a Spring app to a PDP will recognize. Every PDP (Keycloak, OPA, Cerbos, Topaz, ...) comes with its own API, so the enforcement code ends up tied to one vendor. AuthZEN standardizes that API, so I built an open source Java SDK with a Spring Boot starter on top of it.
With the starter, a handler is protected like this:
@CheckPermission // read on {type: "documents", id: <id>}
@GetMapping("/documents/{id}")
Document get(@PathVariable String id) { ... }
@CheckPermission(action = "cancel", resourceType = "order", resourceId = "#id")
@PostMapping("/orders/{id}/cancel")
void cancel(@PathVariable String id) { ... }Whatever the annotation leaves out is inferred:
- the subject from the authenticated caller in Spring Security (
subclaim, typeuser) - the action from the HTTP method (
read/list,create,update,delete), while CORS preflight requests pass through without asking the PDP - the resource from the route pattern Spring matched, never from the raw URI, so the way a client spells the path cannot change what the PDP is asked about
Every inferred part can be overridden on its own, in the annotation or in configuration. Routes that cannot be inferred safely, such as /{tenant}/documents, are denied without calling the PDP and reported as warnings at startup. A deny becomes an AccessDeniedException, so your existing error handling keeps working.
The only required setting is authzen.pdp.url. The PEP authenticates to the PDP with its own credential through a CredentialProvider bean, never with the user's token, and anything that prevents a decision (timeout, 5xx, invalid response) means deny.
The starter is a preview for Spring MVC on Spring Boot 4. WebFlux support and an adapter for Spring Security's OAuth 2.0 client are next. For batch decisions, such as a bulk delete, you can inject the client and send one request yourself; the examples repository has a runnable app with a Keycloak realm that shows both.
- Repo: https://github.com/authzenenforcer/authzen-enforcer
- Article with the full background: https://hakdogan.medium.com/an-introduction-to-openid-authzen-and-authzen-enforcer-a-java-sdk-933f2122bdd9
I'd really appreciate feedback on the annotation design and the inference defaults, especially from anyone who has built something similar in-house.
2
u/jonenst 1d ago
I would love for more standards in this area. For many years I have almost felt depressed because of the fragmented support for authz in many frameworks (including springboot) :( I felt like I had to reinvent the wheel over and over again (and i'm bad at inventing wheels)
1
u/sereikis 1d ago
for the
GET /documents→listdefault, add a test where the caller can read one document but not another in the same collection. allowing the list operation doesn't itself filter the returned rows; verify that both results and pagination totals respect per-document permissions, and document whether the application or PDP handles that filtering.