77import io .clientcore .core .http .models .Response ;
88import io .clientcore .core .models .binarydata .BinaryData ;
99
10+ import java .net .URI ;
1011import java .util .Arrays ;
12+ import java .util .List ;
13+ import java .util .Map ;
1114
1215/**
1316 * Class representing a challenge handler for authentication.
@@ -19,19 +22,63 @@ public interface ChallengeHandler {
1922 * @param request The HTTP request to be updated with authentication info.
2023 * @param response The HTTP response containing the authentication challenge.
2124 * @param isProxy Indicates if the challenge is for a proxy.
25+ * @throws NullPointerException If {@code request} or {@code response} is null.
2226 */
2327 void handleChallenge (HttpRequest request , Response <BinaryData > response , boolean isProxy );
2428
2529 /**
26- * Validate if this ChallengeHandler can handle the provided challenge
27- * by inspecting the 'Proxy-Authenticate' or 'WWW-Authenticate' headers.
30+ * Validate if this ChallengeHandler can handle the provided challenge by inspecting the {@code Proxy-Authenticate}
31+ * or {@code WWW-Authenticate} headers.
32+ * <p>
33+ * Use of {@code Proxy-Authenticate} or {@code WWW-Authenticate} is based on {@code isProxy}.
34+ * <p>
35+ * This method will return true if at least one of the authenticate challenges in the response header can be handled
36+ * by this ChallengeHandler. Meaning, if {@link #of(ChallengeHandler...)} is used ordering of the provided
37+ * ChallengeHandlers is important, where if more secure handling is needed positioning
38+ * {@link DigestChallengeHandler}, or a custom ChallengeHandler for more secure auth mechanisms, before
39+ * {@link BasicChallengeHandler} is necessary.
2840 *
2941 * @param response The HTTP response containing the authentication challenge.
3042 * @param isProxy boolean indicating if it is a proxy challenge handler.
31- * @return boolean indicating if the challenge can be handled.
43+ * @return Whether a challenge within the {@link Response#getHeaders()} {@code Proxy-Authenticate} or
44+ * {@code WWW-Authenticate} can be handled.
45+ * @throws NullPointerException If {@code response} is null.
3246 */
3347 boolean canHandle (Response <BinaryData > response , boolean isProxy );
3448
49+ /**
50+ * Creates a {@code Proxy-Authorization} or {@code WWW-Authorization} compliant header from the given
51+ * {@link AuthenticateChallenge}s.
52+ * <p>
53+ * It is left to the ChallengeHandler implementation to decide which of the {@link AuthenticateChallenge}s it
54+ * {@link #canHandle(List)} to use when creating the header.
55+ * <p>
56+ * If none of the {@link AuthenticateChallenge}s can be handled null will be returned.
57+ *
58+ * @param method The HTTP method used in the request being authorized.
59+ * @param uri The URI for the HTTP request being authorized.
60+ * @param challenges The HTTP authenticate challenges, either from {@code Proxy-Authenticate} or
61+ * {@code WWW-Authenticate} headers.
62+ * @return A {@link Map.Entry} where the key is the {@code Proxy-Authorization} or {@code WWW-Authorization}
63+ * compliant header and value is the {@link AuthenticateChallenge} used to generate the header, or null if none of
64+ * the challenges can be handled.
65+ */
66+ Map .Entry <String , AuthenticateChallenge > handleChallenge (String method , URI uri ,
67+ List <AuthenticateChallenge > challenges );
68+
69+ /**
70+ * Validate if this ChallengeHandler can handle any of the provided {@link AuthenticateChallenge}s.
71+ * <p>
72+ * This method is meant for scenarios where authenticate headers are processed into {@link AuthenticateChallenge}s
73+ * externally, normally using {@link AuthUtils#parseAuthenticateHeader(String)}.
74+ *
75+ * @param challenges The HTTP authenticate challenges, either from {@code Proxy-Authenticate} or
76+ * {@code WWW-Authenticate} headers.
77+ * @return Whether any {@link AuthenticateChallenge} can be handled.
78+ * @throws NullPointerException If {@code challenges} is null.
79+ */
80+ boolean canHandle (List <AuthenticateChallenge > challenges );
81+
3582 /**
3683 * Factory method for creating composite handlers.
3784 *
0 commit comments