chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1622634 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench: ProxyDetector.java model/ClientSession.java
Date Fri, 05 Sep 2014 08:02:47 GMT
Author: fmui
Date: Fri Sep  5 08:02:46 2014
New Revision: 1622634

URL: http://svn.apache.org/r1622634
Log:
Workbench: better proxy authentication support

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ProxyDetector.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ProxyDetector.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ProxyDetector.java?rev=1622634&r1=1622633&r2=1622634&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ProxyDetector.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ProxyDetector.java
Fri Sep  5 08:02:46 2014
@@ -37,8 +37,12 @@ public class ProxyDetector {
 
     public static final String HTTP_PROXY_HOST = "http.proxyHost";
     public static final String HTTP_PROXY_PORT = "http.proxyPort";
+    public static final String HTTP_PROXY_USER = "http.proxyUser";
+    public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword";
     public static final String HTTPS_PROXY_HOST = "https.proxyHost";
     public static final String HTTPS_PROXY_PORT = "https.proxyPort";
+    public static final String HTTPS_PROXY_USER = "https.proxyUser";
+    public static final String HTTPS_PROXY_PASSWORD = "https.proxyPassword";
     public static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
 
     public static final Pattern PROXY_ENV_VAR1 = Pattern.compile("http.?:\\/\\/(.+):(\\d+).*");
@@ -55,8 +59,12 @@ public class ProxyDetector {
 
         settings.setHttpProxyHost(System.getProperty(HTTP_PROXY_HOST));
         settings.setHttpProxyPort(parsePort(System.getProperty(HTTP_PROXY_PORT)));
+        settings.setHttpProxyUser(System.getProperty(HTTP_PROXY_USER));
+        settings.setHttpProxyPassword(System.getProperty(HTTP_PROXY_PASSWORD));
         settings.setHttpsProxyHost(System.getProperty(HTTPS_PROXY_HOST));
         settings.setHttpsProxyPort(parsePort(System.getProperty(HTTPS_PROXY_PORT)));
+        settings.setHttpsProxyUser(System.getProperty(HTTPS_PROXY_USER));
+        settings.setHttpsProxyPassword(System.getProperty(HTTPS_PROXY_PASSWORD));
 
         String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
         if (nonProxyHosts != null) {
@@ -105,11 +113,15 @@ public class ProxyDetector {
                 if (m.matches()) {
                     settings.setHttpProxyHost(parseHost(m.group(1)));
                     settings.setHttpProxyPort(parsePort(m.group(2)));
+                    settings.setHttpProxyUser(parseProxyUser(m.group(1)));
+                    settings.setHttpProxyPassword(parseProxyPassword(m.group(1)));
                 } else {
                     m = PROXY_ENV_VAR2.matcher(e.getValue());
                     if (m.matches()) {
                         settings.setHttpProxyHost(parseHost(m.group(1)));
                         settings.setHttpProxyPort(parsePort(m.group(2)));
+                        settings.setHttpProxyUser(parseProxyUser(m.group(1)));
+                        settings.setHttpProxyPassword(parseProxyPassword(m.group(1)));
                     }
                 }
             } else if ("https_proxy".equals(key)) {
@@ -117,11 +129,15 @@ public class ProxyDetector {
                 if (m.matches()) {
                     settings.setHttpsProxyHost(parseHost(m.group(1)));
                     settings.setHttpsProxyPort(parsePort(m.group(2)));
+                    settings.setHttpsProxyUser(parseProxyUser(m.group(1)));
+                    settings.setHttpsProxyPassword(parseProxyPassword(m.group(1)));
                 } else {
                     m = PROXY_ENV_VAR2.matcher(e.getValue());
                     if (m.matches()) {
                         settings.setHttpProxyHost(parseHost(m.group(1)));
                         settings.setHttpProxyPort(parsePort(m.group(2)));
+                        settings.setHttpsProxyUser(parseProxyUser(m.group(1)));
+                        settings.setHttpsProxyPassword(parseProxyPassword(m.group(1)));
                     }
                 }
             } else if ("no_proxy".equals(key)) {
@@ -257,6 +273,42 @@ public class ProxyDetector {
         }
     }
 
+    private static String parseProxyUser(String host) {
+        if (host == null) {
+            return null;
+        }
+
+        int at = host.lastIndexOf('@');
+        if (at == -1) {
+            return null;
+        }
+
+        int colon = host.indexOf(':');
+        if (colon == -1 || colon > at) {
+            return host.substring(0, at);
+        }
+
+        return host.substring(0, colon);
+    }
+
+    private static String parseProxyPassword(String host) {
+        if (host == null) {
+            return null;
+        }
+
+        int at = host.lastIndexOf('@');
+        if (at == -1) {
+            return null;
+        }
+
+        int colon = host.indexOf(':');
+        if (colon == -1 || colon > at) {
+            return null;
+        }
+
+        return host.substring(colon + 1, at);
+    }
+
     private static boolean isWindows() {
         return System.getProperty("os.name").startsWith("Windows");
     }
@@ -328,9 +380,13 @@ public class ProxyDetector {
     public static class ProxySettings {
         private String httpProxyHost;
         private int httpProxyPort;
+        private String httpProxyUser;
+        private String httpProxyPassword;
 
         private String httpsProxyHost;
         private int httpsProxyPort;
+        private String httpsProxyUser;
+        private String httpsProxyPassword;
 
         private List<String> nonProxyHosts;
 
@@ -353,6 +409,22 @@ public class ProxyDetector {
             this.httpProxyPort = httpProxyPort;
         }
 
+        public String getHttpProxyUser() {
+            return httpProxyUser;
+        }
+
+        public void setHttpProxyUser(String httpProxyUser) {
+            this.httpProxyUser = httpProxyUser;
+        }
+
+        public String getHttpProxyPassword() {
+            return httpProxyPassword;
+        }
+
+        public void setHttpProxyPassword(String httpProxyPassword) {
+            this.httpProxyPassword = httpProxyPassword;
+        }
+
         public String getHttpsProxyHost() {
             return httpsProxyHost;
         }
@@ -369,6 +441,22 @@ public class ProxyDetector {
             this.httpsProxyPort = httpsProxyPort;
         }
 
+        public String getHttpsProxyUser() {
+            return httpsProxyUser;
+        }
+
+        public void setHttpsProxyUser(String httpsProxyUser) {
+            this.httpsProxyUser = httpsProxyUser;
+        }
+
+        public String getHttpsProxyPassword() {
+            return httpsProxyPassword;
+        }
+
+        public void setHttpsProxyPassword(String httpsProxyPassword) {
+            this.httpsProxyPassword = httpsProxyPassword;
+        }
+
         public List<String> getNonProxyHosts() {
             return nonProxyHosts;
         }
@@ -384,6 +472,22 @@ public class ProxyDetector {
                 sb.append("-D" + HTTP_PROXY_HOST + "=" + httpProxyHost + " -D" + HTTP_PROXY_PORT
+ "=" + httpProxyPort);
             }
 
+            if (httpProxyUser != null) {
+                if (sb.length() > 0) {
+                    sb.append(' ');
+                }
+
+                sb.append("-D" + HTTP_PROXY_USER + "=" + httpProxyUser);
+            }
+
+            if (httpProxyPassword != null) {
+                if (sb.length() > 0) {
+                    sb.append(' ');
+                }
+
+                sb.append("-D" + HTTP_PROXY_PASSWORD + "=" + httpProxyPassword);
+            }
+
             if (httpsProxyHost != null) {
                 if (sb.length() > 0) {
                     sb.append(' ');
@@ -393,6 +497,22 @@ public class ProxyDetector {
                         + httpsProxyPort);
             }
 
+            if (httpsProxyUser != null) {
+                if (sb.length() > 0) {
+                    sb.append(' ');
+                }
+
+                sb.append("-D" + HTTPS_PROXY_USER + "=" + httpsProxyUser);
+            }
+
+            if (httpsProxyPassword != null) {
+                if (sb.length() > 0) {
+                    sb.append(' ');
+                }
+
+                sb.append("-D" + HTTPS_PROXY_PASSWORD + "=" + httpsProxyPassword);
+            }
+
             if (nonProxyHosts != null && !nonProxyHosts.isEmpty()) {
                 if (sb.length() > 0) {
                     sb.append(' ');
@@ -431,6 +551,22 @@ public class ProxyDetector {
                 sb.append("HTTP proxy: " + httpProxyHost + ":" + httpProxyPort);
             }
 
+            if (httpProxyUser != null) {
+                if (sb.length() > 0) {
+                    sb.append('\n');
+                }
+
+                sb.append("HTTP proxy user: " + httpProxyUser);
+            }
+
+            if (httpProxyPassword != null) {
+                if (sb.length() > 0) {
+                    sb.append('\n');
+                }
+
+                sb.append("HTTP proxy password: " + httpProxyPassword);
+            }
+
             if (httpsProxyHost != null) {
                 if (sb.length() > 0) {
                     sb.append('\n');
@@ -439,6 +575,22 @@ public class ProxyDetector {
                 sb.append("HTTPS proxy: " + httpsProxyHost + ":" + httpsProxyPort);
             }
 
+            if (httpsProxyUser != null) {
+                if (sb.length() > 0) {
+                    sb.append('\n');
+                }
+
+                sb.append("HTTPS proxy user: " + httpsProxyUser);
+            }
+
+            if (httpsProxyPassword != null) {
+                if (sb.length() > 0) {
+                    sb.append('\n');
+                }
+
+                sb.append("HTTPS proxy password: " + httpsProxyPassword);
+            }
+
             if (nonProxyHosts != null && !nonProxyHosts.isEmpty()) {
                 if (sb.length() > 0) {
                     sb.append('\n');

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java?rev=1622634&r1=1622633&r2=1622634&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java
Fri Sep  5 08:02:46 2014
@@ -23,6 +23,7 @@ import java.security.cert.X509Certificat
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -163,6 +164,25 @@ public class ClientSession {
             }
         }
 
+        // set proxy authentication
+        if (url != null) {
+            String urlLower = url.trim().toLowerCase(Locale.ENGLISH);
+
+            if (urlLower.startsWith("http://")) {
+                String proxyUser = System.getProperty("http.proxyUser");
+                if (proxyUser != null) {
+                    String proxyPassword = System.getProperty("http.proxyPassword");
+                    parameters.setProxyUserAndPassword(proxyUser, proxyPassword);
+                }
+            } else if (urlLower.startsWith("https://")) {
+                String proxyUser = System.getProperty("https.proxyUser");
+                if (proxyUser != null) {
+                    String proxyPassword = System.getProperty("https.proxyPassword");
+                    parameters.setProxyUserAndPassword(proxyUser, proxyPassword);
+                }
+            }
+        }
+
         return parameters;
     }
 



Mime
View raw message