View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.client;
29  
30  import java.util.Map;
31  
32  import org.apache.http.Header;
33  import org.apache.http.HttpResponse;
34  import org.apache.http.auth.AuthScheme;
35  import org.apache.http.auth.AuthenticationException;
36  import org.apache.http.auth.MalformedChallengeException;
37  import org.apache.http.protocol.HttpContext;
38  
39  /**
40  /**
41   * A handler for determining if an HTTP response represents an authentication
42   * challenge that was sent back to the client as a result of authentication
43   * failure.
44   * <p>
45   * Implementations of this interface must be thread-safe. Access to shared
46   * data must be synchronized as methods of this interface may be executed
47   * from multiple threads.
48   *
49   * @since 4.0
50   *
51   * @deprecated (4.2)  use {@link AuthenticationStrategy}
52   */
53  @Deprecated
54  public interface AuthenticationHandler {
55  
56      /**
57       * Determines if the given HTTP response response represents
58       * an authentication challenge that was sent back as a result
59       * of authentication failure
60       * @param response HTTP response.
61       * @param context HTTP context.
62       * @return {@code true} if user authentication is required,
63       *   {@code false} otherwise.
64       */
65      boolean isAuthenticationRequested(
66              HttpResponse response,
67              HttpContext context);
68  
69      /**
70       * Extracts from the given HTTP response a collection of authentication
71       * challenges, each of which represents an authentication scheme supported
72       * by the authentication host.
73       *
74       * @param response HTTP response.
75       * @param context HTTP context.
76       * @return a collection of challenges keyed by names of corresponding
77       * authentication schemes.
78       * @throws MalformedChallengeException if one of the authentication
79       *  challenges is not valid or malformed.
80       */
81      Map<String, Header> getChallenges(
82              HttpResponse response,
83              HttpContext context) throws MalformedChallengeException;
84  
85      /**
86       * Selects one authentication challenge out of all available and
87       * creates and generates {@link AuthScheme} instance capable of
88       * processing that challenge.
89       * @param challenges collection of challenges.
90       * @param response HTTP response.
91       * @param context HTTP context.
92       * @return authentication scheme to use for authentication.
93       * @throws AuthenticationException if an authentication scheme
94       *  could not be selected.
95       */
96      AuthScheme selectScheme(
97              Map<String, Header> challenges,
98              HttpResponse response,
99              HttpContext context) throws AuthenticationException;
100 
101 }