Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 10-24
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.ui.internal.net.auth; |
11 |
package org.eclipse.ui.internal.net.auth; |
12 |
|
12 |
|
13 |
import java.net.*; |
13 |
import java.net.Authenticator; |
|
|
14 |
import java.net.InetAddress; |
15 |
import java.net.PasswordAuthentication; |
16 |
import java.util.HashSet; |
17 |
import java.util.Set; |
18 |
|
19 |
import org.eclipse.core.net.proxy.IProxyData; |
20 |
import org.eclipse.ui.internal.net.Activator; |
14 |
|
21 |
|
15 |
public class NetAuthenticator extends Authenticator { |
22 |
public class NetAuthenticator extends Authenticator { |
|
|
23 |
|
24 |
/* |
25 |
* This set stores all used proxy hosts. Hosts are stored to avoid |
26 |
* repeatable attempts to server if proxy credentials for the server are |
27 |
* invalid. |
28 |
* The access to the this set must be synchronized. |
29 |
*/ |
30 |
private Set usedProxyHosts = new HashSet(); |
16 |
|
31 |
|
17 |
/* |
32 |
/* |
18 |
* @see Authenticator#getPasswordAuthentication() |
33 |
* @see Authenticator#getPasswordAuthentication() |
19 |
*/ |
34 |
*/ |
20 |
protected PasswordAuthentication getPasswordAuthentication() { |
35 |
protected PasswordAuthentication getPasswordAuthentication() { |
21 |
// String protocol = getRequestingProtocol(); |
36 |
IProxyData[] proxyDatas = Activator.getDefault().getProxyData(); |
|
|
37 |
if (proxyDatas != null && proxyDatas.length > 0) { |
38 |
for (int i = 0; i < proxyDatas.length; i++) { |
39 |
final IProxyData iProxyData = proxyDatas[i]; |
40 |
final String proxyHost = iProxyData.getHost(); |
41 |
int proxyPort = iProxyData.getPort(); |
42 |
|
43 |
// Assuming that if proxy host and port from proxy data is the |
44 |
// same as requesting host/port it is request for proxy |
45 |
// authentication. |
46 |
if (proxyHost != null && proxyHost.equals(getRequestingHost()) |
47 |
&& proxyPort == getRequestingPort()) { |
48 |
synchronized (usedProxyHosts) { |
49 |
if (!usedProxyHosts.contains(proxyHost)) { |
50 |
usedProxyHosts.add(proxyHost); |
51 |
return new PasswordAuthentication( |
52 |
iProxyData.getUserId(), |
53 |
iProxyData.getPassword().toCharArray()); |
54 |
} |
55 |
} |
56 |
} |
57 |
} |
58 |
} |
59 |
|
60 |
// String protocol = getRequestingProtocol(); |
22 |
InetAddress address = getRequestingSite(); // can be null; |
61 |
InetAddress address = getRequestingSite(); // can be null; |
23 |
// int port = getRequestingPort(); |
62 |
// int port = getRequestingPort(); |
24 |
String prompt = getRequestingPrompt(); // realm or message, not documented that can be null |
63 |
String prompt = getRequestingPrompt(); // realm or message, not documented that can be null |