1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.impl.client;
29
30 import java.util.List;
31 import java.util.Map;
32
33 import org.apache.http.annotation.Immutable;
34
35 import org.apache.http.Header;
36 import org.apache.http.HttpResponse;
37 import org.apache.http.HttpStatus;
38 import org.apache.http.auth.AUTH;
39 import org.apache.http.auth.MalformedChallengeException;
40 import org.apache.http.auth.params.AuthPNames;
41 import org.apache.http.client.AuthenticationHandler;
42 import org.apache.http.protocol.HttpContext;
43
44
45
46
47
48
49
50
51
52 @Deprecated
53 @Immutable
54 public class DefaultTargetAuthenticationHandler extends AbstractAuthenticationHandler {
55
56 public DefaultTargetAuthenticationHandler() {
57 super();
58 }
59
60 public boolean isAuthenticationRequested(
61 final HttpResponse response,
62 final HttpContext context) {
63 if (response == null) {
64 throw new IllegalArgumentException("HTTP response may not be null");
65 }
66 int status = response.getStatusLine().getStatusCode();
67 return status == HttpStatus.SC_UNAUTHORIZED;
68 }
69
70 public Map<String, Header> getChallenges(
71 final HttpResponse response,
72 final HttpContext context) throws MalformedChallengeException {
73 if (response == null) {
74 throw new IllegalArgumentException("HTTP response may not be null");
75 }
76 Header[] headers = response.getHeaders(AUTH.WWW_AUTH);
77 return parseChallenges(headers);
78 }
79
80 @Override
81 protected List<String> getAuthPreferences(
82 final HttpResponse response,
83 final HttpContext context) {
84 @SuppressWarnings("unchecked")
85 List<String> authpref = (List<String>) response.getParams().getParameter(
86 AuthPNames.TARGET_AUTH_PREF);
87 if (authpref != null) {
88 return authpref;
89 } else {
90 return super.getAuthPreferences(response, context);
91 }
92 }
93
94 }
95