diff --git a/app/src/cc/arduino/view/preferences/Preferences.form b/app/src/cc/arduino/view/preferences/Preferences.form
index 5a685f31b..32b80cbd0 100644
--- a/app/src/cc/arduino/view/preferences/Preferences.form
+++ b/app/src/cc/arduino/view/preferences/Preferences.form
@@ -483,25 +483,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
@@ -518,15 +532,15 @@
-
-
+
+
-
+
@@ -546,6 +560,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -572,7 +596,7 @@
-
+
@@ -587,7 +611,7 @@
-
+
@@ -600,7 +624,7 @@
-
+
@@ -616,7 +640,7 @@
-
+
@@ -642,7 +666,7 @@
-
+
@@ -653,7 +677,7 @@
-
+
@@ -696,6 +720,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/cc/arduino/view/preferences/Preferences.java b/app/src/cc/arduino/view/preferences/Preferences.java
index a9a18747e..0b2227711 100644
--- a/app/src/cc/arduino/view/preferences/Preferences.java
+++ b/app/src/cc/arduino/view/preferences/Preferences.java
@@ -252,6 +252,10 @@ public class Preferences extends javax.swing.JDialog {
manualProxyUsername = new javax.swing.JTextField();
manualProxyPasswordLabel = new javax.swing.JLabel();
manualProxyPassword = new javax.swing.JPasswordField();
+ autoProxyUsernameLabel = new javax.swing.JLabel();
+ autoProxyUsername = new javax.swing.JTextField();
+ autoProxyPassword = new javax.swing.JPasswordField();
+ autoProxyPasswordLabel = new javax.swing.JLabel();
javax.swing.JPanel jPanel3 = new javax.swing.JPanel();
javax.swing.JButton okButton = new javax.swing.JButton();
javax.swing.JButton cancelButton = new javax.swing.JButton();
@@ -492,6 +496,12 @@ public class Preferences extends javax.swing.JDialog {
manualProxyPassword.setToolTipText("");
+ autoProxyUsernameLabel.setText(tr("Username:"));
+
+ autoProxyPassword.setToolTipText("");
+
+ autoProxyPasswordLabel.setText(tr("Password:"));
+
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
@@ -499,20 +509,30 @@ public class Preferences extends javax.swing.JDialog {
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel4Layout.createSequentialGroup()
+ .addGap(12, 12, 12)
+ .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(autoProxyUsePAC)
+ .addGroup(jPanel4Layout.createSequentialGroup()
+ .addGap(12, 12, 12)
+ .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(autoProxyUsernameLabel)
+ .addComponent(autoProxyPasswordLabel))))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(autoProxyPACURL)
+ .addGroup(jPanel4Layout.createSequentialGroup()
+ .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(autoProxyUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(autoProxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(0, 0, Short.MAX_VALUE))))
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(noProxy)
.addComponent(autoProxy)
- .addComponent(manualProxy))
- .addGap(0, 0, Short.MAX_VALUE))
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel4Layout.createSequentialGroup()
- .addComponent(autoProxyUsePAC)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(autoProxyPACURL))
+ .addComponent(manualProxy)
.addGroup(jPanel4Layout.createSequentialGroup()
+ .addGap(12, 12, 12)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(manualProxyHTTP)
@@ -529,9 +549,9 @@ public class Preferences extends javax.swing.JDialog {
.addComponent(manualProxyHostName, javax.swing.GroupLayout.PREFERRED_SIZE, 541, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(manualProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(manualProxyPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
- .addComponent(manualProxyUsername, javax.swing.GroupLayout.Alignment.LEADING)))))
- .addGap(0, 0, Short.MAX_VALUE)))))
+ .addComponent(manualProxyPassword, javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(manualProxyUsername, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
+ .addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
@@ -546,6 +566,14 @@ public class Preferences extends javax.swing.JDialog {
.addComponent(autoProxyUsePAC)
.addComponent(autoProxyPACURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(autoProxyUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(autoProxyUsernameLabel))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(autoProxyPasswordLabel)
+ .addComponent(autoProxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(manualProxy)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@@ -567,7 +595,7 @@ public class Preferences extends javax.swing.JDialog {
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(manualProxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(manualProxyPasswordLabel))
- .addContainerGap(225, Short.MAX_VALUE))
+ .addContainerGap(163, Short.MAX_VALUE))
);
jTabbedPane1.addTab(tr("Network"), jPanel4);
@@ -690,14 +718,18 @@ public class Preferences extends javax.swing.JDialog {
}//GEN-LAST:event_manualProxyItemStateChanged
private void autoProxyUsePACItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_autoProxyUsePACItemStateChanged
- autoProxyPACURL.setEnabled(autoProxyUsePAC.isSelected());
+ autoProxyPACFieldsSetEnabled(autoProxyUsePAC.isSelected());
}//GEN-LAST:event_autoProxyUsePACItemStateChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField additionalBoardsManagerField;
private javax.swing.JRadioButton autoProxy;
private javax.swing.JTextField autoProxyPACURL;
+ private javax.swing.JPasswordField autoProxyPassword;
+ private javax.swing.JLabel autoProxyPasswordLabel;
private javax.swing.JCheckBox autoProxyUsePAC;
+ private javax.swing.JTextField autoProxyUsername;
+ private javax.swing.JLabel autoProxyUsernameLabel;
private javax.swing.JCheckBox checkUpdatesBox;
private javax.swing.JComboBox comboLanguage;
private javax.swing.JComboBox comboWarnings;
@@ -797,6 +829,8 @@ public class Preferences extends javax.swing.JDialog {
PreferencesData.set(Constants.PREF_PROXY_MANUAL_PORT, manualProxyPort.getText());
PreferencesData.set(Constants.PREF_PROXY_MANUAL_USERNAME, manualProxyUsername.getText());
PreferencesData.set(Constants.PREF_PROXY_MANUAL_PASSWORD, String.valueOf(manualProxyPassword.getPassword()));
+ PreferencesData.set(Constants.PREF_PROXY_AUTO_USERNAME, autoProxyUsername.getText());
+ PreferencesData.set(Constants.PREF_PROXY_AUTO_PASSWORD, String.valueOf(autoProxyPassword.getPassword()));
}
private void showPrerefencesData() {
@@ -849,6 +883,8 @@ public class Preferences extends javax.swing.JDialog {
if (!PreferencesData.get(Constants.PREF_PROXY_PAC_URL, "").isEmpty()) {
autoProxyUsePAC.setSelected(true);
autoProxyPACURL.setText(PreferencesData.get(Constants.PREF_PROXY_PAC_URL));
+ autoProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_AUTO_USERNAME));
+ autoProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_AUTO_PASSWORD));
}
} else {
manualProxy.setSelected(true);
@@ -879,7 +915,15 @@ public class Preferences extends javax.swing.JDialog {
private void autoProxyFieldsSetEnabled(boolean enabled) {
autoProxyUsePAC.setEnabled(enabled);
- autoProxyPACURL.setEnabled(enabled && autoProxyUsePAC.isSelected());
+ autoProxyPACFieldsSetEnabled(enabled && autoProxyUsePAC.isSelected());
+ }
+
+ private void autoProxyPACFieldsSetEnabled(boolean enabled) {
+ autoProxyPACURL.setEnabled(enabled);
+ autoProxyUsername.setEnabled(enabled);
+ autoProxyUsernameLabel.setEnabled(enabled);
+ autoProxyPassword.setEnabled(enabled);
+ autoProxyPasswordLabel.setEnabled(enabled);
}
private void disableAllProxyFields() {
diff --git a/app/test/cc/arduino/net/CustomProxySelectorTest.java b/app/test/cc/arduino/net/CustomProxySelectorTest.java
index 4da042673..1783471c5 100644
--- a/app/test/cc/arduino/net/CustomProxySelectorTest.java
+++ b/app/test/cc/arduino/net/CustomProxySelectorTest.java
@@ -50,6 +50,22 @@ public class CustomProxySelectorTest {
assertEquals(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080)), proxy);
}
+ @Test
+ public void testProxyPACHTTPWithLogin() throws Exception {
+ preferences.put(Constants.PREF_PROXY_TYPE, Constants.PROXY_TYPE_AUTO);
+ preferences.put(Constants.PREF_PROXY_PAC_URL, CustomProxySelectorTest.class.getResource("proxy_http.pac").toExternalForm());
+ preferences.put(Constants.PREF_PROXY_AUTO_USERNAME, "auto");
+ preferences.put(Constants.PREF_PROXY_AUTO_PASSWORD, "autopassword");
+ CustomProxySelector proxySelector = new CustomProxySelector(preferences);
+ Proxy proxy = proxySelector.getProxyFor(uri);
+
+ assertEquals(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.example.com", 8080)), proxy);
+
+ PasswordAuthentication authentication = Authenticator.requestPasswordAuthentication(null, 8080, uri.toURL().getProtocol(), "ciao", "");
+ assertEquals(authentication.getUserName(), "auto");
+ assertEquals(String.valueOf(authentication.getPassword()), "autopassword");
+ }
+
@Test
public void testProxyPACSOCKS() throws Exception {
preferences.put(Constants.PREF_PROXY_TYPE, Constants.PROXY_TYPE_AUTO);
diff --git a/arduino-core/src/cc/arduino/Constants.java b/arduino-core/src/cc/arduino/Constants.java
index 09770e6fd..d6bfe48d9 100644
--- a/arduino-core/src/cc/arduino/Constants.java
+++ b/arduino-core/src/cc/arduino/Constants.java
@@ -58,6 +58,8 @@ public class Constants {
public static final String PREF_PROXY_MANUAL_PORT = "proxy.manual.port";
public static final String PREF_PROXY_MANUAL_USERNAME = "proxy.manual.username";
public static final String PREF_PROXY_MANUAL_PASSWORD = "proxy.manual.password";
+ public static final String PREF_PROXY_AUTO_USERNAME = "proxy.manual.username";
+ public static final String PREF_PROXY_AUTO_PASSWORD = "proxy.manual.password";
public static final String PACKAGE_INDEX_URL;
public static final String LIBRARY_INDEX_URL;
diff --git a/arduino-core/src/cc/arduino/net/CustomProxySelector.java b/arduino-core/src/cc/arduino/net/CustomProxySelector.java
index f503e2453..1dffb5173 100644
--- a/arduino-core/src/cc/arduino/net/CustomProxySelector.java
+++ b/arduino-core/src/cc/arduino/net/CustomProxySelector.java
@@ -43,6 +43,8 @@ public class CustomProxySelector {
}
private Proxy pacProxy(String pac, URI uri) throws IOException, ScriptException, NoSuchMethodException {
+ setAuthenticator(preferences.get(Constants.PREF_PROXY_AUTO_USERNAME), preferences.get(Constants.PREF_PROXY_AUTO_PASSWORD));
+
URLConnection urlConnection = new URL(pac).openConnection();
urlConnection.connect();
if (urlConnection instanceof HttpURLConnection) {
@@ -90,7 +92,7 @@ public class CustomProxySelector {
}
private Proxy manualProxy() {
- setAuthenticator();
+ setAuthenticator(preferences.get(Constants.PREF_PROXY_MANUAL_USERNAME), preferences.get(Constants.PREF_PROXY_MANUAL_PASSWORD));
Proxy.Type type = Proxy.Type.valueOf(preferences.get(Constants.PREF_PROXY_MANUAL_TYPE));
return new Proxy(type, new InetSocketAddress(preferences.get(Constants.PREF_PROXY_MANUAL_HOSTNAME), Integer.valueOf(preferences.get(Constants.PREF_PROXY_MANUAL_PORT))));
}
@@ -99,12 +101,20 @@ public class CustomProxySelector {
Authenticator.setDefault(null);
}
- private void setAuthenticator() {
+ private void setAuthenticator(String username, String password) {
+ if (username == null || username.isEmpty()) {
+ return;
+ }
+ String actualPassword;
+ if (password == null) {
+ actualPassword = "";
+ } else {
+ actualPassword = password;
+ }
Authenticator.setDefault(
new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(
- preferences.get(Constants.PREF_PROXY_MANUAL_USERNAME), preferences.get(Constants.PREF_PROXY_MANUAL_PASSWORD).toCharArray());
+ return new PasswordAuthentication(username, actualPassword.toCharArray());
}
}
);