Skip to content

Commit

Permalink
[RESTEASY-2642] Add doPrivs to sys prop checks (#2467)
Browse files Browse the repository at this point in the history
* [RESTEASY-2642] Add doPrivs to sys prop checks

Signed-off-by: Andy McCright <j.andrew.mccright@gmail.com>

* Review comment: only use doPriv if SecMgr is used

Signed-off-by: Andy McCright <j.andrew.mccright@gmail.com>
  • Loading branch information
andymc12 authored and asoldano committed Sep 18, 2020
1 parent 7b1920d commit 9c641fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
import java.security.KeyStore;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -193,8 +195,8 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
ClassLoader classLoader = aClass.getClassLoader();

List<String> noProxyHosts = Arrays.asList(
System.getProperty("http.nonProxyHosts", "localhost|127.*|[::1]").split("\\|"));
String envProxyHost = System.getProperty("http.proxyHost");
getSystemProperty("http.nonProxyHosts", "localhost|127.*|[::1]").split("\\|"));
String envProxyHost = getSystemProperty("http.proxyHost", null);

T actualClient;
ResteasyClient client;
Expand All @@ -204,7 +206,7 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
// Use proxy, if defined in the env variables
resteasyClientBuilder = builderDelegate.defaultProxy(
envProxyHost,
Integer.parseInt(System.getProperty("http.proxyPort", "80")));
Integer.parseInt(getSystemProperty("http.proxyPort", "80")));
} else {
// Search for proxy settings passed in the client builder, if passed and use them if found
String userProxyHost = Optional.ofNullable(getConfiguration().getProperty(PROPERTY_PROXY_HOST))
Expand Down Expand Up @@ -288,7 +290,7 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
*/
private boolean useURLConnection() {
if (useURLConnection == null) {
String defaultToURLConnection = System.getProperty("org.jboss.resteasy.microprofile.defaultToURLConnectionHttpClient", "false");
String defaultToURLConnection = getSystemProperty("org.jboss.resteasy.microprofile.defaultToURLConnectionHttpClient", "false");
useURLConnection = defaultToURLConnection.toLowerCase().equals("true");
}
return useURLConnection;
Expand Down Expand Up @@ -608,6 +610,13 @@ ResteasyClientBuilder getBuilderDelegate() {
return builderDelegate;
}

private String getSystemProperty(String key, String def) {
if (System.getSecurityManager() == null) {
return System.getProperty(key, def);
}
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(key, def));
}

private final MpClientBuilderImpl builderDelegate;

private final ConfigurationWrapper configurationWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.RuntimeDelegate;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -20,8 +22,10 @@ public class MediaTypeHeaderDelegate implements RuntimeDelegate.HeaderDelegate

private static Map<String, MediaType> map = new ConcurrentHashMap<String, MediaType>();
private static Map<MediaType, String> reverseMap = new ConcurrentHashMap<MediaType, String>();
private static final int MAX_MT_CACHE_SIZE =
Integer.getInteger("org.jboss.resteasy.max_mediatype_cache_size", 200);
private static final int MAX_MT_CACHE_SIZE = System.getSecurityManager() == null
? Integer.getInteger("org.jboss.resteasy.max_mediatype_cache_size", 200)
: AccessController.doPrivileged((PrivilegedAction<Integer>) () ->
Integer.getInteger("org.jboss.resteasy.max_mediatype_cache_size", 200));

public Object fromString(String type) throws IllegalArgumentException
{
Expand Down

0 comments on commit 9c641fd

Please sign in to comment.