Class NextNonceInterceptor
- java.lang.Object
-
- org.apache.hc.client5.http.protocol.NextNonceInterceptor
-
- All Implemented Interfaces:
org.apache.hc.core5.http.HttpResponseInterceptor
@Contract(threading=STATELESS) public class NextNonceInterceptor extends java.lang.Object implements org.apache.hc.core5.http.HttpResponseInterceptorNextNonceInterceptoris an HTTP response interceptor that extracts thenextnonceparameter from theAuthentication-Infoheader of an HTTP response. This parameter is used in HTTP Digest Access Authentication to provide an additional nonce value that the client is expected to use in subsequent authentication requests. By retrieving and storing thisnextnoncevalue, the interceptor facilitates one-time nonce implementations and prevents replay attacks by ensuring that each request/response interaction includes a fresh nonce.If present, the extracted
nextnoncevalue is stored in theHttpContextunder the attributeauth-nextnonce, allowing it to be accessed in subsequent requests. If the header does not contain thenextnonceparameter, no context attribute is set.This implementation adheres to the HTTP/1.1 specification, particularly focusing on the
Digestscheme as defined in HTTP Digest Authentication, and parses header tokens using theTokenizerutility class for robust token parsing.In the context of HTTP Digest Access Authentication, the
nextnonceparameter is a critical part of the security mechanism, designed to mitigate replay attacks and enhance mutual authentication security. It provides the server with the ability to set and enforce single-use or session-bound nonces, prompting the client to use the providednextnoncein its next request. This setup helps secure communication by forcing new cryptographic material in each transaction.This interceptor is stateless and thread-safe, making it suitable for use across multiple threads and HTTP requests. It should be registered with the HTTP client to enable support for advanced authentication mechanisms that require tracking of nonce values.
- Since:
- 5.5
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringAUTHENTICATION_INFO_HEADERstatic org.apache.hc.core5.http.HttpResponseInterceptorINSTANCEprivate static org.apache.hc.core5.util.Tokenizer.DelimiterTOKEN_DELIMSprivate org.apache.hc.core5.util.TokenizertokenParserprivate static org.apache.hc.core5.util.Tokenizer.DelimiterVALUE_DELIMS
-
Constructor Summary
Constructors Constructor Description NextNonceInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringparseNextNonce(java.lang.CharSequence buffer, org.apache.hc.core5.http.message.ParserCursor cursor)Parses theAuthentication-Infoheader content represented by aCharArrayBufferto extract thenextnonceparameter.voidprocess(org.apache.hc.core5.http.HttpResponse response, org.apache.hc.core5.http.EntityDetails entity, org.apache.hc.core5.http.protocol.HttpContext context)Processes the HTTP response and extracts thenextnonceparameter from theAuthentication-Infoheader if available, storing it in the providedcontext.
-
-
-
Field Detail
-
INSTANCE
public static final org.apache.hc.core5.http.HttpResponseInterceptor INSTANCE
-
tokenParser
private final org.apache.hc.core5.util.Tokenizer tokenParser
-
AUTHENTICATION_INFO_HEADER
private static final java.lang.String AUTHENTICATION_INFO_HEADER
- See Also:
- Constant Field Values
-
TOKEN_DELIMS
private static final org.apache.hc.core5.util.Tokenizer.Delimiter TOKEN_DELIMS
-
VALUE_DELIMS
private static final org.apache.hc.core5.util.Tokenizer.Delimiter VALUE_DELIMS
-
-
Method Detail
-
process
public void process(org.apache.hc.core5.http.HttpResponse response, org.apache.hc.core5.http.EntityDetails entity, org.apache.hc.core5.http.protocol.HttpContext context)Processes the HTTP response and extracts thenextnonceparameter from theAuthentication-Infoheader if available, storing it in the providedcontext.- Specified by:
processin interfaceorg.apache.hc.core5.http.HttpResponseInterceptor- Parameters:
response- the HTTP response containing theAuthentication-Infoheaderentity- the response entity, ignored by this interceptorcontext- the HTTP context in which to store thenextnonceparameter- Throws:
java.lang.NullPointerException- if eitherresponseorcontextis null
-
parseNextNonce
private java.lang.String parseNextNonce(java.lang.CharSequence buffer, org.apache.hc.core5.http.message.ParserCursor cursor)Parses theAuthentication-Infoheader content represented by aCharArrayBufferto extract thenextnonceparameter.- Parameters:
buffer- theCharArrayBuffercontaining the value of theAuthentication-Infoheadercursor- theParserCursorused to navigate through the buffer content- Returns:
- the extracted
nextnonceparameter value, ornullif the parameter is not found
-
-