Top Description Inners Fields Constructors Methods
org.eclipse.jetty.client

public Class DigestAuthentication

extends AbstractAuthentication
Class Inheritance
Imports
java.net.URI, java.nio.charset.StandardCharsets, java.security.MessageDigest, .NoSuchAlgorithmException, .SecureRandom, java.util.List, .Locale, .Map, .Objects, .Random, java.util.concurrent.atomic.AtomicInteger, org.eclipse.jetty.http.HttpHeader, org.eclipse.jetty.util.Attributes, .StringUtil

Implementation of the HTTP "Digest" authentication defined in RFC 2617.

Applications should create objects of this class and add them to the AuthenticationStore retrieved from the HttpClient via HttpClient#getAuthenticationStore().

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final String
private final Random
private final String

Constructor Summary

AccessConstructor and Description
public
DigestAuthentication(URI
the URI to match for the authentication
uri
,
String
the realm to match for the authentication
realm
,
String
the user that wants to authenticate
user
,
String
the password of the user
password
)

Construct a DigestAuthentication with a SecureRandom nonce.

public
DigestAuthentication(URI
the URI to match for the authentication
uri
,
String
the realm to match for the authentication
realm
,
String
the user that wants to authenticate
user
,
String
the password of the user
password
,
Random
the Random generator to use for nonces.
random
)

Method Summary

Modifier and TypeMethod and Description
public Authentication.Result
authenticate(Request
the request to execute the authentication mechanism for
request
,
ContentResponse
the 401 response obtained in the previous attempt to request the protected resource
response
,
Authentication.HeaderInfo
the WWW-Authenticate (or Proxy-Authenticate) header chosen for this authentication (among the many that the response may contain)
headerInfo
,
Attributes
the conversation context in case the authentication needs multiple exchanges to be completed and information needs to be stored across exchanges
context
)

Implements org.eclipse.jetty.client.Authentication.authenticate.

Executes the authentication mechanism for the given request, returning a Result that can be used to actually authenticate the request via Authentication.Result#apply(Request).

private MessageDigest
public String
public boolean
matches(String
the Authentication type such as "Basic" or "Digest"
type
,
URI
the request URI
uri
,
String
the authentication realm as provided in the WWW-Authenticate response header
realm
)

Overrides org.eclipse.jetty.client.AbstractAuthentication.matches.

Implements org.eclipse.jetty.client.Authentication.matches.

Matches Authentications based on the given parameters

Inherited from org.eclipse.jetty.client.AbstractAuthentication:
getRealmgetURImatchesURI

Field Detail

passwordback to summary
private final String password
randomback to summary
private final Random random
userback to summary
private final String user

Constructor Detail

DigestAuthenticationback to summary
public DigestAuthentication(URI uri, String realm, String user, String password)

Construct a DigestAuthentication with a SecureRandom nonce.

Parameters
uri:URI

the URI to match for the authentication

realm:String

the realm to match for the authentication

user:String

the user that wants to authenticate

password:String

the password of the user

DigestAuthenticationback to summary
public DigestAuthentication(URI uri, String realm, String user, String password, Random random)
Parameters
uri:URI

the URI to match for the authentication

realm:String

the realm to match for the authentication

user:String

the user that wants to authenticate

password:String

the password of the user

random:Random

the Random generator to use for nonces.

Method Detail

authenticateback to summary
public Authentication.Result authenticate(Request request, ContentResponse response, Authentication.HeaderInfo headerInfo, Attributes context)

Implements org.eclipse.jetty.client.Authentication.authenticate.

Doc from org.eclipse.jetty.client.Authentication.authenticate.

Executes the authentication mechanism for the given request, returning a Result that can be used to actually authenticate the request via Authentication.Result#apply(Request).

If a request for "/secure" returns a Result, then the result may be used for other requests such as "/secure/foo" or "/secure/bar", unless those resources are protected by other realms.

Parameters
request:Request

the request to execute the authentication mechanism for

response:ContentResponse

the 401 response obtained in the previous attempt to request the protected resource

headerInfo:Authentication.HeaderInfo

the WWW-Authenticate (or Proxy-Authenticate) header chosen for this authentication (among the many that the response may contain)

context:Attributes

the conversation context in case the authentication needs multiple exchanges to be completed and information needs to be stored across exchanges

Returns:Authentication.Result

the authentication result, or null if the authentication could not be performed

Annotations
@Override
getMessageDigestback to summary
private MessageDigest getMessageDigest(String algorithm)
getTypeback to summary
public String getType()

Implements abstract org.eclipse.jetty.client.AbstractAuthentication.getType.

Annotations
@Override
matchesback to summary
public boolean matches(String type, URI uri, String realm)

Overrides org.eclipse.jetty.client.AbstractAuthentication.matches.

Implements org.eclipse.jetty.client.Authentication.matches.

Doc from org.eclipse.jetty.client.Authentication.matches.

Matches Authentications based on the given parameters

Parameters
type:String

the Authentication type such as "Basic" or "Digest"

uri:URI

the request URI

realm:String

the authentication realm as provided in the WWW-Authenticate response header

Returns:boolean

true if this authentication matches, false otherwise

Annotations
@Override
org.eclipse.jetty.client back to summary

private Class DigestAuthentication.DigestResult

extends Object
implements Result
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.client.Authentication.Result

Field Summary

Modifier and TypeField and Description
private final String
private final byte[]
private final HttpHeader
private final String
private final AtomicInteger
private final String
private final String
private final String
private final String
private final String

Constructor Summary

AccessConstructor and Description
public
DigestResult(HttpHeader header, byte[] content, String realm, String user, String password, String algorithm, String nonce, String qop, String opaque)

Method Summary

Modifier and TypeMethod and Description
public void
apply(Request
the request to authenticate
request
)

Implements org.eclipse.jetty.client.Authentication.Result.apply.

Applies the authentication result to the given request.

public URI
private String
private String
private String
toHexString(byte[] bytes)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private final String algorithm
contentback to summary
private final byte[] content
headerback to summary
private final HttpHeader header
nonceback to summary
private final String nonce
nonceCountback to summary
private final AtomicInteger nonceCount
opaqueback to summary
private final String opaque
passwordback to summary
private final String password
qopback to summary
private final String qop
realmback to summary
private final String realm
userback to summary
private final String user

Constructor Detail

DigestResultback to summary
public DigestResult(HttpHeader header, byte[] content, String realm, String user, String password, String algorithm, String nonce, String qop, String opaque)

Method Detail

applyback to summary
public void apply(Request request)

Implements org.eclipse.jetty.client.Authentication.Result.apply.

Doc from org.eclipse.jetty.client.Authentication.Result.apply.

Applies the authentication result to the given request. Typically, a Authorization header is added to the request, with the right information to successfully authenticate at the server.

Parameters
request:Request

the request to authenticate

Annotations
@Override
getURIback to summary
public URI getURI()

Implements org.eclipse.jetty.client.Authentication.Result.getURI.

Returns:URI

Doc from org.eclipse.jetty.client.Authentication.Result.getURI.

the URI of the request that has been used to generate this Result

Annotations
@Override
newClientNonceback to summary
private String newClientNonce()
nextNonceCountback to summary
private String nextNonceCount()
toHexStringback to summary
private String toHexString(byte[] bytes)