Package org.apache.juneau.rest.server.auth
juneau-rest-server.
Guard-level authentication (RestGuard)
BearerTokenGuard and ApiKeyGuard are
framework-level guard implementations that run inside the Juneau request pipeline (after servlet routing).
They stash the resolved Principal on the request under
"juneau.principal" so downstream handlers can read it via
@Auth Principal or
req.getAttributes().get(PRINCIPAL_ATTR).
Servlet-layer authentication (AuthFilter)
This package also ships a two-layer pluggable servlet-filter authentication framework that runs at the servlet container layer — before Juneau's request routing:
Layer 1 — Standalone filters: each concrete AuthFilter
subclass (BearerTokenAuthFilter,
ApiKeyAuthFilter) is also a jakarta.servlet.Filter and can be
registered directly with a servlet container or Spring Boot's FilterRegistrationBean.
Layer 2 — AuthFilterChain orchestrator: composes multiple
AuthFilter instances with first-success principal resolution, role aggregation across all successful
filters, and all-failure aggregation into a single 401 response.
Optional<AuthResult> three-state contract
authenticate(HttpServletRequest) returns:
Optional.empty()— filter does not apply (no recognizable credentials).- throw
AuthenticationException— credentials present but invalid. Optional.of(AuthResult)— authentication succeeded.
Principal and role surface
On success the chain wraps the request in AuthenticatedRequestWrapper,
which overrides HttpServletRequest.getUserPrincipal(),
HttpServletRequest.isUserInRole(String),
HttpServletRequest.getRemoteUser(), and
ServletRequest.getAttribute(String) for the
"juneau.principal" key.
This makes RoleBasedRestGuard and @Auth Principal arg injection work
with zero changes.
SPIs
TokenValidator and ApiKeyStore are the
backing SPIs for both the guard-level and filter-level authentication classes.
No third-party crypto / JOSE dependency is pulled in by this package — users who want JWT verification add the
optional juneau-rest-server-auth-jwt sub-module (which plugs into the
TokenValidator SPI from this package).
See Also:
- Since:
- 10.0.0
-
ClassDescription
AuthFilterthat authenticates requests via a raw API-key string.Builder class.Source of the API-key string.AuthNRestGuardthat authenticates requests via a raw API-key string.Builder class.Source of the API-key string.SPI for resolving a raw API key string to its associatedPrincipal.Marks a@RestOp-method parameter as the authenticatedPrincipalfor the current request.Resolves@RestOp-method parameters that represent the authenticatedPrincipal.AnHttpServletRequestWrapperthat surfaces the filter-resolvedPrincipaland aggregated roles via the standard servlet API surface.Specialization ofUnauthorizedthrown byBearerTokenGuard,ApiKeyGuard, and user-suppliedTokenValidator/ApiKeyStoreimplementations to signal AuthN failure.Lowest-level authentication contract shared by the servlet-filter layer (AuthFilter,AuthFilterChain) and the resource layer (RestAuthenticator).Abstract base class for Juneau authentication servlet filters.Orchestrates multipleAuthFilterinstances with first-success principal resolution, role aggregation, and all-failure aggregation semantics.Builder class.Immutable value type returned byAuthenticator.authenticate(jakarta.servlet.http.HttpServletRequest)on success.Controls how anAuthResultmerges with results accumulated earlier in an authenticator chain.Mutable helper that folds a sequence ofAuthResults into a single result, honoringAuthResult.MergeMode.AuthFilterthat authenticates requests via the RFC 6750 Bearer Token scheme.Builder class.AuthNRestGuardthat authenticates requests via the RFC 6750 Bearer Token scheme.Builder class.APrincipalthat exposes typed read-only access to a map of claims.Resource-level authentication SPI for@Restresources.Sentinel "unset" type for@Rest(authenticator=...); never authenticates.SPI for verifying an opaque bearer token and producing the associatedPrincipal.