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.net.URL; |
17 |
import java.util.HashSet; |
18 |
import java.util.Set; |
19 |
|
20 |
import org.eclipse.core.net.proxy.IProxyData; |
21 |
import org.eclipse.ui.internal.net.Activator; |
14 |
|
22 |
|
15 |
public class NetAuthenticator extends Authenticator { |
23 |
public class NetAuthenticator extends Authenticator { |
16 |
|
24 |
|
17 |
/* |
25 |
/* |
|
|
26 |
* This is class storing PasswordAuthentication credentials to enable comparing this data. |
27 |
*/ |
28 |
private class ComparablePasswordAuthentication { |
29 |
private final String userName; |
30 |
private final String password; |
31 |
public ComparablePasswordAuthentication(String userName, String password) { |
32 |
this.userName = userName; |
33 |
this.password = password; |
34 |
} |
35 |
public int hashCode() { |
36 |
final int prime = 31; |
37 |
int result = 1; |
38 |
result = prime * result + getOuterType().hashCode(); |
39 |
result = prime * result |
40 |
+ ((password == null) ? 0 : password.hashCode()); |
41 |
result = prime * result |
42 |
+ ((userName == null) ? 0 : userName.hashCode()); |
43 |
return result; |
44 |
} |
45 |
public boolean equals(Object obj) { |
46 |
if (this == obj) |
47 |
return true; |
48 |
if (obj == null) |
49 |
return false; |
50 |
if (getClass() != obj.getClass()) |
51 |
return false; |
52 |
ComparablePasswordAuthentication other = (ComparablePasswordAuthentication) obj; |
53 |
if (!getOuterType().equals(other.getOuterType())) |
54 |
return false; |
55 |
if (password == null) { |
56 |
if (other.password != null) |
57 |
return false; |
58 |
} else if (!password.equals(other.password)) |
59 |
return false; |
60 |
if (userName == null) { |
61 |
if (other.userName != null) |
62 |
return false; |
63 |
} else if (!userName.equals(other.userName)) |
64 |
return false; |
65 |
return true; |
66 |
} |
67 |
private NetAuthenticator getOuterType() { |
68 |
return NetAuthenticator.this; |
69 |
} |
70 |
|
71 |
} |
72 |
|
73 |
/* |
74 |
* This set stores all used password credentials to avoid blocking by proxy |
75 |
* server as a consequence of to many failed requests to proxy server. |
76 |
* The access to the this set must be synchronized. |
77 |
*/ |
78 |
private Set usedPasswordCredentials = new HashSet(); |
79 |
|
80 |
/* |
18 |
* @see Authenticator#getPasswordAuthentication() |
81 |
* @see Authenticator#getPasswordAuthentication() |
19 |
*/ |
82 |
*/ |
20 |
protected PasswordAuthentication getPasswordAuthentication() { |
83 |
protected PasswordAuthentication getPasswordAuthentication() { |
21 |
// String protocol = getRequestingProtocol(); |
84 |
RequestorType requestorType = getRequestorType(); |
|
|
85 |
if (requestorType == RequestorType.PROXY) { |
86 |
URL url = getRequestingURL(); |
87 |
IProxyData[] proxyDatas = Activator.getDefault().getProxyData(url); |
88 |
if (proxyDatas != null && proxyDatas.length > 0) { |
89 |
for (int i = 0; i < proxyDatas.length; i++) { |
90 |
IProxyData iProxyData = proxyDatas[i]; |
91 |
final String userName = iProxyData.getUserId(); |
92 |
final String password = iProxyData.getPassword(); |
93 |
ComparablePasswordAuthentication passwordAuthentication = |
94 |
new ComparablePasswordAuthentication(userName, password); |
95 |
synchronized (usedPasswordCredentials) { |
96 |
if (!usedPasswordCredentials |
97 |
.contains(passwordAuthentication)) { |
98 |
usedPasswordCredentials.add(passwordAuthentication); |
99 |
return new PasswordAuthentication(userName, |
100 |
password.toCharArray()); |
101 |
} |
102 |
} |
103 |
} |
104 |
} |
105 |
} |
106 |
|
107 |
// String protocol = getRequestingProtocol(); |
22 |
InetAddress address = getRequestingSite(); // can be null; |
108 |
InetAddress address = getRequestingSite(); // can be null; |
23 |
// int port = getRequestingPort(); |
109 |
// int port = getRequestingPort(); |
24 |
String prompt = getRequestingPrompt(); // realm or message, not documented that can be null |
110 |
String prompt = getRequestingPrompt(); // realm or message, not documented that can be null |