Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.split.storages.enums.OperationMode;
import io.split.storages.enums.StorageMode;
import org.apache.hc.core5.http.HttpHost;
import org.slf4j.LoggerFactory;
import pluggable.CustomStorageWrapper;

import java.io.IOException;
Expand All @@ -28,6 +29,7 @@
*/
public class SplitClientConfig {

private static final org.slf4j.Logger _log = LoggerFactory.getLogger(SplitClientConfig.class);
public static final String LOCALHOST_DEFAULT_FILE = "split.yaml";
public static final String SDK_ENDPOINT = "https://sdk.split.io";
public static final String EVENTS_ENDPOINT = "https://events.split.io";
Expand Down Expand Up @@ -1140,6 +1142,11 @@ private void verifyProxy() {
if (_proxyConfiguration == null)
return;

if (!_proxyHost.equals("localhost")) {
_log.warn("Both the deprecated proxy configuration methods (`proxyHost`, `proxyPort`, `proxyUsername`, or `proxyPassword`) " +
"and the new `ProxyConfiguration` builder are being used. `ProxyConfiguration` will take precedence.");
}

if (!(_proxyConfiguration.getHost().getSchemeName().equals(HttpScheme.HTTP) ||
_proxyConfiguration.getHost().getSchemeName().equals(HttpScheme.HTTPS))) {
throw new IllegalArgumentException("Proxy scheme must be either http or https.");
Expand Down
63 changes: 36 additions & 27 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,48 +628,57 @@ private static SSLContext buildSSLContext(SplitClientConfig config) throws IOExc

private static HttpClientBuilder setupProxy(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
_log.info("Initializing Split SDK with proxy settings");
HttpHost proxyHost;
if (config.proxyConfiguration() != null && config.proxyConfiguration().getHost() != null) {
proxyHost = config.proxyConfiguration().getHost();
if (config.proxyConfiguration() != null) {
return useProxyConfiguration(httpClientbuilder, config);
} else {
_log.warn("`proxyHost`, `proxyPort` configuration methods are deprecated. Please use `ProxyConfiguration` builder instead.");
proxyHost = config.proxy();
return useLegacyProxyConfiguration(httpClientbuilder, config);
}
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
httpClientbuilder.setRoutePlanner(routePlanner);
}

if ((config.proxyUsername() != null && config.proxyPassword() != null) ||
(config.proxyConfiguration() != null && config.proxyConfiguration().getProxyCredentialsProvider() != null &&
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider)) {
_log.debug("Proxy setup using credentials");
String userName;
String password;
if (config.proxyUsername() == null && config.proxyPassword() == null) {
private static HttpClientBuilder useLegacyProxyConfiguration(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
HttpHost proxyHost;
String userName = null;
String password = null;
proxyHost = config.proxy();
if (config.proxyUsername() != null && config.proxyPassword() != null) {
userName = config.proxyUsername();
password = config.proxyPassword();
}
return addProxyParams(httpClientbuilder, proxyHost, userName, password);
}

private static HttpClientBuilder useProxyConfiguration(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
HttpHost proxyHost;
String userName = null;
String password = null;
proxyHost = config.proxyConfiguration().getHost();
if (config.proxyConfiguration().getProxyCredentialsProvider() != null) {
if (config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider) {
io.split.client.dtos.BasicCredentialsProvider basicAuth =
(io.split.client.dtos.BasicCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider();
userName = basicAuth.getUsername();
password = basicAuth.getPassword();
} else {
_log.warn("`proxyUsername` and `proxyPassword` configuration methods are deprecated. " +
"Please use `ProxyConfiguration` builder instead.");
userName = config.proxyUsername();
password = config.proxyPassword();
} else if (config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BearerCredentialsProvider) {
_log.debug("Proxy setup using Bearer token");
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
}
}
return addProxyParams(httpClientbuilder, proxyHost, userName, password);
}

private static HttpClientBuilder addProxyParams(HttpClientBuilder httpClientbuilder, HttpHost proxyHost, String userName, String password) {
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
httpClientbuilder.setRoutePlanner(routePlanner);
if (userName != null && password != null) {
_log.debug("Proxy setup using Basic authentication");
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
AuthScope siteScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
Credentials siteCreds = new UsernamePasswordCredentials(userName,
password.toCharArray());
credsProvider.setCredentials(siteScope, siteCreds);
httpClientbuilder.setDefaultCredentialsProvider(credsProvider);
}

if (config.proxyConfiguration() != null &&
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BearerCredentialsProvider) {
_log.debug("Proxy setup using Bearer token");
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
}

return httpClientbuilder;
}

Expand Down