Permalink
Browse files

Make sure that the proxy selector supports proxies requiring authenti…

…cation as well
  • Loading branch information...
1 parent 2aeb2cb commit 89dc6548e8ad1b26e5c459a304d923ee64fe6a3f Ivan Ivanov committed with lincolnthree Feb 28, 2012
Showing with 11 additions and 1 deletion.
  1. +11 −1 shell/src/main/java/org/jboss/forge/shell/util/ForgeProxySelector.java
@@ -1,7 +1,9 @@
package org.jboss.forge.shell.util;
import java.io.IOException;
+import java.net.Authenticator;
import java.net.InetSocketAddress;
+import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.ProxySelector;
@@ -33,7 +35,15 @@ public ForgeProxySelector(ProxySelector defaultProxySelector, ProxySettings prox
if ("http".equalsIgnoreCase(protocol) || "https".equalsIgnoreCase(protocol)) {
ArrayList<Proxy> result = new ArrayList<Proxy>();
result.add(new Proxy(Type.HTTP, new InetSocketAddress(proxySettings.getProxyHost(),
- proxySettings.getProxyPort())));
+ proxySettings.getProxyPort())));
+ if (proxySettings.isAuthenticationSupported()) {
+ Authenticator.setDefault(new Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(proxySettings.getProxyUserName(),
+ proxySettings.getProxyPassword().toCharArray());
+ }
+ });
+ }
return result;
}
if (defaultProxySelector != null) {

0 comments on commit 89dc654

Please sign in to comment.