Package org.apache.juneau.petstore.auth
Class StubBearerTokenValidator
java.lang.Object
org.apache.juneau.petstore.auth.StubBearerTokenValidator
- All Implemented Interfaces:
TokenValidator
Stub
TokenValidator for the petstore demo — recognises an in-memory map of opaque bearer tokens.
NOT FOR PRODUCTION USE. This is a sample/demo validator that maps fixed token strings to fixed user
principals. Real deployments should plug in JwtTokenValidator from juneau-rest-server-auth-jwt
(signed JWTs against a JWKS), an opaque-token store backed by a database, or RFC 7662 introspection.
Default token table:
petstore-user→ principal"alice"petstore-admin→ principal"admin"
Other token strings throw AuthenticationException carrying a WWW-Authenticate: Bearer realm="petstore"
challenge — the AuthFilterChain in turn returns 401.
-
Field Summary
FieldsModifier and TypeFieldDescriptionDefault in-memory token table. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor using theDEFAULT_TOKENStable.StubBearerTokenValidator(Map<String, String> tokenToUser) Constructor. -
Method Summary
-
Field Details
-
DEFAULT_TOKENS
Default in-memory token table.
-
-
Constructor Details
-
StubBearerTokenValidator
public StubBearerTokenValidator()Constructor using theDEFAULT_TOKENStable. -
StubBearerTokenValidator
Constructor.- Parameters:
tokenToUser- Map of token string to principal name. Copied defensively.
-
-
Method Details
-
validate
Description copied from interface:TokenValidatorValidates the supplied bearer token and returns the associatedPrincipal.- Specified by:
validatein interfaceTokenValidator- Parameters:
token- The raw token string fromAuthorization: Bearer <token>. Nevernull .- Returns:
- The authenticated principal. Must not be
null on success. - Throws:
AuthenticationException- If the token is invalid, expired, revoked, or otherwise unacceptable.
-