hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject httpcomponents-client git commit: [HTTPASYNC-124] Add doPrivileged blocks to async client and connection manager builders.
Date Fri, 21 Jul 2017 03:52:42 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master 643ea6c3e -> c8b0aa12a


[HTTPASYNC-124] Add doPrivileged blocks to async client and connection
manager builders.

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/c8b0aa12
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/c8b0aa12
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/c8b0aa12

Branch: refs/heads/master
Commit: c8b0aa12a8f183065afa7ce22eee37c82ab0f57d
Parents: 643ea6c
Author: Jay Modi <jay at elastic dot co>
Authored: Thu Jul 20 20:52:39 2017 -0700
Committer: Gary Gregory <ggregory@apache.org>
Committed: Thu Jul 20 20:52:39 2017 -0700

----------------------------------------------------------------------
 .../http/impl/async/HttpAsyncClientBuilder.java | 24 +++++++++++++++++---
 ...lingAsyncClientConnectionManagerBuilder.java | 22 ++++++++++++++----
 2 files changed, 39 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/c8b0aa12/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
index 0a7e02d..099e2c4 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java
@@ -30,6 +30,8 @@ package org.apache.hc.client5.http.impl.async;
 import java.io.Closeable;
 import java.io.IOException;
 import java.net.ProxySelector;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -749,7 +751,12 @@ public class HttpAsyncClientBuilder {
         String userAgentCopy = this.userAgent;
         if (userAgentCopy == null) {
             if (systemProperties) {
-                userAgentCopy = System.getProperty("http.agent");
+                userAgentCopy = AccessController.doPrivileged(new PrivilegedAction<String>()
{
+                    @Override
+                    public String run() {
+                        return System.getProperty("http.agent");
+                    }
+                });
             }
             if (userAgentCopy == null) {
                 userAgentCopy = VersionInfo.getSoftwareInfo("Apache-HttpAsyncClient",
@@ -831,8 +838,14 @@ public class HttpAsyncClientBuilder {
             if (proxy != null) {
                 routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);
             } else if (systemProperties) {
+                final ProxySelector defaultProxySelector = AccessController.doPrivileged(new
PrivilegedAction<ProxySelector>() {
+                    @Override
+                    public ProxySelector run() {
+                        return ProxySelector.getDefault();
+                    }
+                });
                 routePlannerCopy = new SystemDefaultRoutePlanner(
-                        schemePortResolverCopy, ProxySelector.getDefault());
+                        schemePortResolverCopy, defaultProxySelector);
             } else {
                 routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
             }
@@ -874,7 +887,12 @@ public class HttpAsyncClientBuilder {
         ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
         if (reuseStrategyCopy == null) {
             if (systemProperties) {
-                final String s = System.getProperty("http.keepAlive", "true");
+                final String s = AccessController.doPrivileged(new PrivilegedAction<String>()
{
+                    @Override
+                    public String run() {
+                        return System.getProperty("http.keepAlive", "true");
+                    }
+                });
                 if ("true".equalsIgnoreCase(s)) {
                     reuseStrategyCopy = DefaultConnectionReuseStrategy.INSTANCE;
                 } else {

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/c8b0aa12/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
index cce713d..2af512c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java
@@ -37,6 +37,9 @@ import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
 import org.apache.hc.core5.util.TimeValue;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 /**
  * Builder for {@link PoolingAsyncClientConnectionManager} instances.
  * <p>
@@ -176,10 +179,7 @@ public class PoolingAsyncClientConnectionManagerBuilder {
         @SuppressWarnings("resource")
         final PoolingAsyncClientConnectionManager poolingmgr = new PoolingAsyncClientConnectionManager(
                 RegistryBuilder.<TlsStrategy>create()
-                        .register("https", tlsStrategy != null ? tlsStrategy :
-                                (systemProperties ?
-                                        H2TlsStrategy.getSystemDefault() :
-                                        H2TlsStrategy.getDefault()))
+                        .register("https", getTlsStrategy())
                         .build(),
                 schemePortResolver,
                 dnsResolver,
@@ -196,4 +196,18 @@ public class PoolingAsyncClientConnectionManagerBuilder {
         return poolingmgr;
     }
 
+    private TlsStrategy getTlsStrategy() {
+        if (tlsStrategy != null) {
+            return tlsStrategy;
+        } else if (systemProperties) {
+            return AccessController.doPrivileged(new PrivilegedAction<TlsStrategy>()
{
+                @Override
+                public TlsStrategy run() {
+                    return H2TlsStrategy.getSystemDefault();
+                }
+            });
+        } else {
+            return H2TlsStrategy.getDefault();
+        }
+    }
 }


Mime
View raw message