@Contract(threading=UNSAFE) @Experimental public final class ScramScheme extends Object implements AuthScheme
SCRAM-SHA-256 per RFC 7804
with SCRAM core per RFC 5802/7677.
HTTP SCRAM uses no channel binding (GS2 header "n,,"; c=biws).
Experimental: This API is work in progress and may change without notice in a future release.
| Constructor and Description |
|---|
ScramScheme()
Default policy: warn if
i < 4096, no hard enforcement; SHA-256 only. |
ScramScheme(int warnMinIterations,
int minIterationsRequired,
SecureRandom rnd)
Constructor with custom iteration policy.
|
| Modifier and Type | Method and Description |
|---|---|
String |
generateAuthResponse(HttpHost host,
HttpRequest request,
HttpContext context)
Generates an authorization response based on the current state.
|
String |
getName()
Returns textual designation of the scheme.
|
Principal |
getPrincipal()
Returns
Principal whose credentials are used. |
String |
getRealm()
Returns authentication realm.
|
boolean |
isChallengeComplete()
Authentication process may involve a series of challenge-response exchanges.
|
boolean |
isChallengeExpected()
SCRAM must inspect final responses to verify
v= in Authentication-Info. |
boolean |
isConnectionBased()
SCRAM is per-request (no connection binding).
|
boolean |
isResponseReady(HttpHost host,
CredentialsProvider credentialsProvider,
HttpContext context)
Allow response when:
- INIT (preemptive client-first) — only if creds have been prepared
- ANNOUNCED (401 without data)
- SERVER_FIRST_RCVD (ready to send client-final)
|
void |
processChallenge(AuthChallenge authChallenge,
HttpContext context)
Legacy entry point: wraps
AuthenticationException as MalformedChallengeException. |
void |
processChallenge(HttpHost host,
boolean challenged,
AuthChallenge authChallenge,
HttpContext context)
Handles 401 challenges (with/without
data) and final responses carrying
Authentication-Info (any status code). |
public ScramScheme()
i < 4096, no hard enforcement; SHA-256 only.public ScramScheme(int warnMinIterations,
int minIterationsRequired,
SecureRandom rnd)
warnMinIterations - warn if iteration count is lower than this (0 disables warnings)minIterationsRequired - fail if iteration count is lower than this (0 disables enforcement)rnd - optional secure random source (null uses system default)public String getName()
getName in interface AuthSchemepublic boolean isConnectionBased()
isConnectionBased in interface AuthSchemetrue if the scheme is connection based, false
if the scheme is request based.public boolean isChallengeExpected()
v= in Authentication-Info.isChallengeExpected in interface AuthSchemepublic void processChallenge(AuthChallenge authChallenge, HttpContext context) throws MalformedChallengeException
AuthenticationException as MalformedChallengeException.processChallenge in interface AuthSchemeauthChallenge - the auth challengecontext - HTTP contextMalformedChallengeException - in case the auth challenge is incomplete,
malformed or otherwise invalid.AuthScheme.processChallenge(HttpHost, boolean, AuthChallenge, HttpContext)public void processChallenge(HttpHost host, boolean challenged, AuthChallenge authChallenge, HttpContext context) throws MalformedChallengeException, AuthenticationException
data) and final responses carrying
Authentication-Info (any status code).processChallenge in interface AuthSchemehost - HTTP hostchallenged - true if the response was unauthorised (401/407)authChallenge - the auth challenge or null if no challenge was receivedcontext - HTTP contextMalformedChallengeException - in case the auth challenge is incomplete,AuthenticationException - in case the authentication process is unsuccessful.public boolean isChallengeComplete()
AuthScheme
Please note if the scheme returns true from this method in response
to a challenge, it effectively implies a failure to respond to this challenge
and termination of the authentication process.
isChallengeComplete in interface AuthSchemetrue if the authentication process has been completed,
false otherwise.public String getRealm()
AuthSchemenull.getRealm in interface AuthSchemepublic boolean isResponseReady(HttpHost host, CredentialsProvider credentialsProvider, HttpContext context) throws AuthenticationException
isResponseReady in interface AuthSchemecredentialsProvider - The credentials to be used for authenticationcontext - HTTP contexttrue if an authorization response can be generated and
the authentication handshake can proceed, false otherwise.AuthenticationException - if authorization string cannot
be generated due to an authentication failurepublic String generateAuthResponse(HttpHost host, HttpRequest request, HttpContext context) throws AuthenticationException
AuthSchemeCredentialsProvider prior to this method call.generateAuthResponse in interface AuthSchemerequest - The request being authenticatedcontext - HTTP contextAuthenticationException - if authorization string cannot
be generated due to an authentication failureAuthScheme.isResponseReady(HttpHost, CredentialsProvider, HttpContext)public Principal getPrincipal()
Principal whose credentials are used.getPrincipal in interface AuthSchemeAuthScheme.isConnectionBased()Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.