Class DefaultHTTPAuthenticationProvider
HTTPAuthenticationProvider that delegates to a
Realm for credential verification.
This bridges the SASL/mail-protocol Realm abstraction to
HTTP authentication, allowing the same realm configuration to be
shared across SMTP, IMAP, POP3, FTP, and HTTP services.
The authentication method is chosen automatically based on what the realm supports:
- If the realm supports
SASLMechanism.DIGEST_MD5, HTTP Digest is used (strongest password-based). - If the realm supports
SASLMechanism.OAUTHBEARER, Bearer token authentication is used. - Otherwise, HTTP Basic is used as the fallback.
- Author:
- Chris Burdess
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.bluezoo.gumdrop.http.HTTPAuthenticationProvider
HTTPAuthenticationProvider.AuthenticationResult -
Constructor Summary
ConstructorsConstructorDescriptionCreates a provider backed by the given realm, using"gumdrop"as the default realm name.DefaultHTTPAuthenticationProvider(Realm realm, String realmName) Creates a provider backed by the given realm. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringGets the authentication method configured for this provider.protected StringgetDigestHA1(String realm, String username) Gets the precomputed H(A1) hash for Digest authentication.protected StringGets the realm name for this provider.protected booleanpasswordMatch(String realm, String username, String password) Verifies username and password credentials against the authentication realm.protected booleanChecks if the underlying Realm supports HTTP Digest authentication.protected Realm.TokenValidationResultvalidateBearerToken(String token) Validates a Bearer token for token-based authentication.protected Realm.TokenValidationResultvalidateOAuthToken(String accessToken) Validates an OAuth 2.0 access token.Methods inherited from class org.bluezoo.gumdrop.http.HTTPAuthenticationProvider
authenticate, generateChallenge, getSupportedSchemes, isAuthenticationRequired, supportsScheme
-
Constructor Details
-
DefaultHTTPAuthenticationProvider
Creates a provider backed by the given realm.- Parameters:
realm- the authentication realmrealmName- the realm name to include in HTTP challenges
-
DefaultHTTPAuthenticationProvider
Creates a provider backed by the given realm, using"gumdrop"as the default realm name.- Parameters:
realm- the authentication realm
-
-
Method Details
-
getAuthMethod
Description copied from class:HTTPAuthenticationProviderGets the authentication method configured for this provider.The return value should be one of the standard authentication method constants from
HttpServletRequestorHTTPAuthenticationMethods.- Specified by:
getAuthMethodin classHTTPAuthenticationProvider- Returns:
- the authentication method (e.g., "BASIC", "DIGEST"), or null if none configured
-
getRealmName
Description copied from class:HTTPAuthenticationProviderGets the realm name for this provider.The realm name is included in authentication challenges and is used to partition authentication spaces.
- Specified by:
getRealmNamein classHTTPAuthenticationProvider- Returns:
- the realm name, or null if none configured
-
passwordMatch
Description copied from class:HTTPAuthenticationProviderVerifies username and password credentials against the authentication realm.This method is called for Basic authentication and may also be used by other authentication mechanisms that require password verification.
- Specified by:
passwordMatchin classHTTPAuthenticationProvider- Parameters:
realm- the realm name for credential lookupusername- the username to verifypassword- the password to verify- Returns:
- true if the credentials are valid, false otherwise
-
getDigestHA1
Description copied from class:HTTPAuthenticationProviderGets the precomputed H(A1) hash for Digest authentication.For Digest authentication, H(A1) = MD5(username:realm:password). Implementations may store this precomputed hash for security, avoiding the need to store plaintext passwords.
- Specified by:
getDigestHA1in classHTTPAuthenticationProvider- Parameters:
realm- the realm nameusername- the username- Returns:
- the H(A1) hash as a lowercase hexadecimal string, or null if the user doesn't exist
-
validateBearerToken
Description copied from class:HTTPAuthenticationProviderValidates a Bearer token for token-based authentication.Called for Bearer authentication (RFC 6750). Implementations should verify the token's signature, expiration, and associated claims.
- Specified by:
validateBearerTokenin classHTTPAuthenticationProvider- Parameters:
token- the bearer token to validate- Returns:
- a
Realm.TokenValidationResultwith validation outcome, or null if Bearer authentication is not supported
-
validateOAuthToken
Description copied from class:HTTPAuthenticationProviderValidates an OAuth 2.0 access token.Called for OAuth authentication (RFC 6749). Implementations should verify the token against the authorization server or introspection endpoint.
- Specified by:
validateOAuthTokenin classHTTPAuthenticationProvider- Parameters:
accessToken- the OAuth access token to validate- Returns:
- a
Realm.TokenValidationResultwith validation outcome, or null if OAuth authentication is not supported
-
supportsDigestAuth
protected boolean supportsDigestAuth()Description copied from class:HTTPAuthenticationProviderChecks if the underlying Realm supports HTTP Digest authentication.HTTP Digest authentication requires the Realm to provide the H(A1) hash via
HTTPAuthenticationProvider.getDigestHA1(String, String). Some Realm implementations (e.g., LDAP with hashed passwords) cannot support this.The default implementation returns true, assuming Digest is supported. Subclasses should override this if they can determine whether the Realm actually supports Digest authentication.
- Overrides:
supportsDigestAuthin classHTTPAuthenticationProvider- Returns:
- true if Digest authentication is supported, false otherwise
-