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