-
Notifications
You must be signed in to change notification settings - Fork 974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NextNonceInterceptor for nextnonce extraction from Authentication-Info headers #596
Conversation
Args.notNull(response, "HTTP response"); | ||
Args.notNull(context, "HTTP context"); | ||
|
||
final Header header = response.getFirstHeader(AUTHENTICATION_INFO_HEADER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg This can be made more efficient by checking if the header is FormattedHeader
and re-using its internal attributes and eliminating an extra intermediate String.
if (header instanceof FormattedHeader) {
final CharArrayBuffer buf = ((FormattedHeader) header).getBuffer();
final ParserCursor cursor = new ParserCursor(0, buf.length());
cursor.updatePos(((FormattedHeader) header).getValuePos());
parseNextNonce(buf, cursor;
} else {
final String value = header.getValue();
final ParserCursor cursor = new ParserCursor(0, value.length());
parseNextNonce(buf, cursor;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
if (context != null) { | ||
final HttpClientContext clientContext = HttpClientContext.cast(context); | ||
final String nextNonce = clientContext.getAttribute("auth-nextnonce", String.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Maybe this deserves being an attribute in the context. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c that is a good idea. I made all the necessary change.
8bd6a6b
to
99a1404
Compare
* @param cursor the {@link ParserCursor} used to navigate through the buffer content | ||
* @return the extracted {@code nextnonce} parameter value, or {@code null} if the parameter is not found | ||
*/ | ||
private String parseNextNonce(final CharArrayBuffer buffer, final ParserCursor cursor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Please use CharSequence
instead of CharArrayBuffer
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} else { | ||
final String headerValue = header.getValue(); | ||
final ParserCursor cursor = new ParserCursor(0, headerValue.length()); | ||
final CharArrayBuffer buf = new CharArrayBuffer(headerValue.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg This intermediate buffer will become unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
…in HTTP Digest Access Authentication, extracting the `nextnonce` parameter when present and storing it in `HttpClientContext`. This supports compliance with RFC 7616, enhancing client authentication continuity.
1d91748
to
e1fbf1a
Compare
This PR introduces the
NextNonceInterceptor
to process HTTP responses with Authentication-Info headers by extracting thenextnonce
parameter, as specified in RFC 7616. The interceptor checks for the presence of this header, retrieves thenextnonce
value if available, and stores it within theHttpContext
under the attributeauth-nextnonce.
This mechanism supports secure client authentication workflows by allowing continuity in nonce-based authentication challenges.