1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.http;
20
21 import org.apache.http.HttpHost;
22 import org.apache.http.auth.AuthScope;
23 import org.apache.http.auth.Credentials;
24 import org.apache.http.client.CredentialsProvider;
25
26
27
28
29
30
31
32 final class DemuxCredentialsProvider implements CredentialsProvider {
33
34 private final CredentialsProvider serverCredentialsProvider;
35
36 private final CredentialsProvider proxyCredentialsProvider;
37
38 private final HttpHost proxy;
39
40 DemuxCredentialsProvider(
41 CredentialsProvider serverCredentialsProvider,
42 CredentialsProvider proxyCredentialsProvider,
43 HttpHost proxy) {
44 this.serverCredentialsProvider = serverCredentialsProvider;
45 this.proxyCredentialsProvider = proxyCredentialsProvider;
46 this.proxy = proxy;
47 }
48
49 private CredentialsProvider getDelegate(AuthScope authScope) {
50 if (proxy.getPort() == authScope.getPort() && proxy.getHostName().equalsIgnoreCase(authScope.getHost())) {
51 return proxyCredentialsProvider;
52 }
53 return serverCredentialsProvider;
54 }
55
56 @Override
57 public Credentials getCredentials(AuthScope authScope) {
58 return getDelegate(authScope).getCredentials(authScope);
59 }
60
61 @Override
62 public void setCredentials(AuthScope authScope, Credentials credentials) {
63 getDelegate(authScope).setCredentials(authScope, credentials);
64 }
65
66 @Override
67 public void clear() {
68 serverCredentialsProvider.clear();
69 proxyCredentialsProvider.clear();
70 }
71 }