Skip to content

Commit a32fd58

Browse files
authored
Merge pull request #586 from splitio/FME-7183-update-proxy-config
Added new proxy config params
2 parents 2113b7c + bdad865 commit a32fd58

File tree

18 files changed

+286
-252
lines changed

18 files changed

+286
-252
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ jobs:
5959
if: matrix.jdk == '8' && github.event_name == 'pull_request' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/development'
6060
run: mvn checkstyle::check
6161

62-
- name: Deploy
63-
if: matrix.jdk == '8' && github.event_name == 'push' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/development'
64-
run: mvn --batch-mode deploy -P test
62+
# - name: Deploy
63+
# if: matrix.jdk == '8' && github.event_name == 'push' && github.ref != 'refs/heads/master' && github.ref != 'refs/heads/development'
64+
# run: mvn --batch-mode deploy -P test
6565

6666
- name: SonarQube Scan (Push)
6767
if: matrix.jdk == '11' && github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/development')

client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.17.0-rc2</version>
8+
<version>4.17.0-rc3</version>
99
</parent>
10-
<version>4.17.0-rc2</version>
10+
<version>4.17.0-rc3</version>
1111
<artifactId>java-client</artifactId>
1212
<packaging>jar</packaging>
1313
<name>Java Client</name>

client/src/main/java/io/split/client/HttpClientDynamicCredentials.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package io.split.client;
22

3+
import io.split.client.dtos.BearerCredentialsProvider;
34
import org.apache.hc.client5.http.auth.AuthScope;
45
import org.apache.hc.client5.http.auth.BearerToken;
56
import org.apache.hc.client5.http.auth.Credentials;
67
import org.apache.hc.core5.http.protocol.HttpContext;
78

89
class HttpClientDynamicCredentials implements org.apache.hc.client5.http.auth.CredentialsProvider {
910

10-
private final ProxyCredentialsProvider _proxyCredentialsProvider;
11+
private final BearerCredentialsProvider _bearerCredentialsProvider;
1112

12-
public HttpClientDynamicCredentials (ProxyCredentialsProvider proxyCredentialsProvider) {
13-
_proxyCredentialsProvider = proxyCredentialsProvider;
13+
public HttpClientDynamicCredentials (BearerCredentialsProvider bearerCredentialsProvider) {
14+
_bearerCredentialsProvider = bearerCredentialsProvider;
1415
}
1516

1617
@Override
1718
public Credentials getCredentials(AuthScope authScope, HttpContext context) {
1819

1920
// This Provider is invoked every time a request is made.
2021
// This should invoke a user-custom provider responsible for:
21-
return new BearerToken(_proxyCredentialsProvider.getJwtToken());
22+
return new BearerToken(_bearerCredentialsProvider.getToken());
2223
}
2324

2425
}

client/src/main/java/io/split/client/ProxyCredentialsProvider.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.split.client;
22

3-
import io.split.client.dtos.ProxyMTLSAuth;
3+
import io.split.client.dtos.ProxyConfiguration;
44
import io.split.client.impressions.ImpressionListener;
55
import io.split.client.impressions.ImpressionsManager;
66
import io.split.client.utils.FileTypeEnum;
@@ -91,11 +91,10 @@ private HttpScheme() {
9191
private final ThreadFactory _threadFactory;
9292

9393
// Proxy configs
94+
private final ProxyConfiguration _proxyConfiguration;
9495
private final HttpHost _proxy;
9596
private final String _proxyUsername;
9697
private final String _proxyPassword;
97-
private final ProxyCredentialsProvider _proxyCredentialsProvider;
98-
private final ProxyMTLSAuth _proxyMtlsAuth;
9998

10099
// To be set during startup
101100
public static String splitSdkVersion;
@@ -129,8 +128,7 @@ private SplitClientConfig(String endpoint,
129128
HttpHost proxy,
130129
String proxyUsername,
131130
String proxyPassword,
132-
ProxyCredentialsProvider proxyCredentialsProvider,
133-
ProxyMTLSAuth proxyMtlsAuth,
131+
ProxyConfiguration proxyConfiguration,
134132
int eventsQueueSize,
135133
long eventSendIntervalInMillis,
136134
int maxStringLength,
@@ -184,8 +182,7 @@ private SplitClientConfig(String endpoint,
184182
_proxy = proxy;
185183
_proxyUsername = proxyUsername;
186184
_proxyPassword = proxyPassword;
187-
_proxyCredentialsProvider = proxyCredentialsProvider;
188-
_proxyMtlsAuth = proxyMtlsAuth;
185+
_proxyConfiguration = proxyConfiguration;
189186
_eventsQueueSize = eventsQueueSize;
190187
_eventSendIntervalInMillis = eventSendIntervalInMillis;
191188
_maxStringLength = maxStringLength;
@@ -317,12 +314,8 @@ public String proxyPassword() {
317314
return _proxyPassword;
318315
}
319316

320-
public ProxyCredentialsProvider proxyCredentialsProvider() {
321-
return _proxyCredentialsProvider;
322-
}
323-
324-
public ProxyMTLSAuth proxyMTLSAuth() {
325-
return _proxyMtlsAuth;
317+
public ProxyConfiguration proxyConfiguration() {
318+
return _proxyConfiguration;
326319
}
327320

328321
public long eventSendIntervalInMillis() {
@@ -463,11 +456,9 @@ public static final class Builder {
463456
private int _waitBeforeShutdown = 5000;
464457
private String _proxyHost = "localhost";
465458
private int _proxyPort = -1;
466-
private String _proxyScheme = HttpScheme.HTTP;
467459
private String _proxyUsername;
468460
private String _proxyPassword;
469-
private ProxyCredentialsProvider _proxyCredentialsProvider;
470-
private ProxyMTLSAuth _proxyMtlsAuth;
461+
private ProxyConfiguration _proxyConfiguration;
471462
private int _eventsQueueSize = 500;
472463
private long _eventSendIntervalInMillis = 30 * (long)1000;
473464
private int _maxStringLength = 250;
@@ -760,43 +751,44 @@ public Builder waitBeforeShutdown(int waitTime) {
760751

761752
/**
762753
* The host location of the proxy. Default is localhost.
754+
* @deprecated
755+
* This method is deprecated.
756+
* <p> Use {@link ProxyConfiguration)} instead.
763757
*
764758
* @param proxyHost location of the proxy
765759
* @return this builder
766760
*/
761+
@Deprecated
767762
public Builder proxyHost(String proxyHost) {
768763
_proxyHost = proxyHost;
769764
return this;
770765
}
771766

772767
/**
773768
* The port of the proxy. Default is -1.
769+
* @deprecated
770+
* This method is deprecated.
771+
* <p> Use {@link ProxyConfiguration)} instead.
774772
*
775773
* @param proxyPort port for the proxy
776774
* @return this builder
777775
*/
776+
@Deprecated
778777
public Builder proxyPort(int proxyPort) {
779778
_proxyPort = proxyPort;
780779
return this;
781780
}
782781

783-
/**
784-
* The http scheme of the proxy. Default is http.
785-
*
786-
* @param proxyScheme protocol for the proxy
787-
* @return this builder
788-
*/
789-
public Builder proxyScheme(String proxyScheme) {
790-
_proxyScheme = proxyScheme;
791-
return this;
792-
}
793-
794782
/**
795783
* Set the username for authentication against the proxy (if proxy settings are enabled). (Optional).
784+
* @deprecated
785+
* This method is deprecated.
786+
* <p> Use {@link ProxyConfiguration)} instead.
796787
*
797788
* @param proxyUsername
798789
* @return this builder
799790
*/
791+
@Deprecated
800792
public Builder proxyUsername(String proxyUsername) {
801793
_proxyUsername = proxyUsername;
802794
return this;
@@ -813,25 +805,14 @@ public Builder proxyPassword(String proxyPassword) {
813805
return this;
814806
}
815807

816-
/**
817-
* Set the token for authentication against the proxy (if proxy settings are enabled). (Optional).
818-
*
819-
* @param proxyCredentialsProvider
820-
* @return this builder
821-
*/
822-
public Builder proxyCredentialsProvider(ProxyCredentialsProvider proxyCredentialsProvider) {
823-
_proxyCredentialsProvider = proxyCredentialsProvider;
824-
return this;
825-
}
826-
827808
/**
828809
* Set the mtls authentication against the proxy (if proxy settings are enabled). (Optional).
829810
*
830-
* @param proxyMtlsAuth
811+
* @param proxyConfiguration
831812
* @return this builder
832813
*/
833-
public Builder proxyMtlsAuth(ProxyMTLSAuth proxyMtlsAuth) {
834-
_proxyMtlsAuth = proxyMtlsAuth;
814+
public Builder proxyConfiguration(ProxyConfiguration proxyConfiguration) {
815+
_proxyConfiguration = proxyConfiguration;
835816
return this;
836817
}
837818

@@ -847,7 +828,7 @@ public Builder disableDestroyOnShutDown() {
847828

848829
HttpHost proxy() {
849830
if (_proxyPort != -1) {
850-
return new HttpHost(_proxyScheme, _proxyHost, _proxyPort);
831+
return new HttpHost(_proxyHost, _proxyPort);
851832
}
852833
// Default is no proxy.
853834
return null;
@@ -986,7 +967,7 @@ public Builder operationMode(OperationMode mode) {
986967

987968
/**
988969
*
989-
* @param storage mode
970+
* @param mode
990971
* @return this builder
991972
*/
992973
public Builder storageMode(StorageMode mode) {
@@ -1156,31 +1137,16 @@ private void verifyAlternativeClient() {
11561137
}
11571138

11581139
private void verifyProxy() {
1159-
if (_proxyPort == -1) {
1140+
if (_proxyConfiguration == null)
11601141
return;
1161-
}
11621142

1163-
if (!(_proxyScheme.equals(HttpScheme.HTTP) || _proxyScheme.equals(HttpScheme.HTTPS))) {
1143+
if (!(_proxyConfiguration.getHost().getSchemeName().equals(HttpScheme.HTTP) ||
1144+
_proxyConfiguration.getHost().getSchemeName().equals(HttpScheme.HTTPS))) {
11641145
throw new IllegalArgumentException("Proxy scheme must be either http or https.");
11651146
}
11661147

1167-
if (_proxyUsername == null && _proxyCredentialsProvider == null && _proxyMtlsAuth == null) {
1168-
return;
1169-
}
1170-
1171-
if (_proxyUsername != null && _proxyCredentialsProvider != null) {
1172-
throw new IllegalArgumentException("Proxy user and Proxy token params are updated, set only one param.");
1173-
}
1174-
1175-
if (_proxyUsername != null && _proxyMtlsAuth != null) {
1176-
throw new IllegalArgumentException("Proxy user and Proxy mTLS params are updated, set only one param.");
1177-
}
1178-
1179-
if (_proxyCredentialsProvider != null && _proxyMtlsAuth != null) {
1180-
throw new IllegalArgumentException("Proxy token and Proxy mTLS params are updated, set only one param.");
1181-
}
1182-
1183-
if (_proxyMtlsAuth != null && (_proxyMtlsAuth.getP12File() == null || _proxyMtlsAuth.getP12FilePassKey() == null)) {
1148+
if ((_proxyConfiguration.getP12File() != null && _proxyConfiguration.getPassKey() == null) ||
1149+
(_proxyConfiguration.getP12File() == null && _proxyConfiguration.getPassKey() != null)) {
11841150
throw new IllegalArgumentException("Proxy mTLS must have p12 file path and name, and pass phrase.");
11851151
}
11861152
}
@@ -1224,8 +1190,7 @@ public SplitClientConfig build() {
12241190
proxy(),
12251191
_proxyUsername,
12261192
_proxyPassword,
1227-
_proxyCredentialsProvider,
1228-
_proxyMtlsAuth,
1193+
_proxyConfiguration,
12291194
_eventsQueueSize,
12301195
_eventSendIntervalInMillis,
12311196
_maxStringLength,

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.split.client;
22

33
import com.google.common.io.Files;
4+
import io.split.client.dtos.BearerCredentialsProvider;
45
import io.split.client.dtos.Metadata;
56
import io.split.client.events.EventsSender;
67
import io.split.client.events.EventsStorage;
@@ -105,6 +106,7 @@
105106
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
106107
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
107108
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
109+
import org.apache.hc.core5.http.HttpHost;
108110
import org.apache.hc.core5.http.io.SocketConfig;
109111
import org.apache.hc.core5.http.ssl.TLS;
110112
import org.apache.hc.core5.ssl.SSLContexts;
@@ -551,7 +553,7 @@ protected static SplitHttpClient buildSplitHttpClient(String apiToken, SplitClie
551553
.addResponseInterceptorLast((new GzipDecoderResponseInterceptor()));
552554

553555
// Set up proxy is it exists
554-
if (config.proxy() != null) {
556+
if (config.proxy() != null || config.proxyConfiguration() != null) {
555557
httpClientbuilder = setupProxy(httpClientbuilder, config);
556558
}
557559

@@ -590,7 +592,7 @@ private static CloseableHttpClient buildSSEdHttpClient(String apiToken, SplitCli
590592
.addRequestInterceptorLast(ClientKeyInterceptorFilter.instance(apiToken));
591593

592594
// Set up proxy is it exists
593-
if (config.proxy() != null) {
595+
if (config.proxy() != null || config.proxyConfiguration() != null) {
594596
httpClientbuilder = setupProxy(httpClientbuilder, config);
595597
}
596598

@@ -599,15 +601,15 @@ private static CloseableHttpClient buildSSEdHttpClient(String apiToken, SplitCli
599601

600602
private static SSLContext buildSSLContext(SplitClientConfig config) throws IOException, NullPointerException {
601603
SSLContext sslContext;
602-
if (config.proxyMTLSAuth() != null) {
604+
if (config.proxyConfiguration() != null && config.proxyConfiguration().getP12File() != null) {
603605
_log.debug("Proxy setup using mTLS");
604606
InputStream keystoreStream = null;
605607
try {
606608
KeyStore keyStore = KeyStore.getInstance("PKCS12");
607-
keystoreStream = java.nio.file.Files.newInputStream(Paths.get(config.proxyMTLSAuth().getP12File()));
608-
keyStore.load(keystoreStream, config.proxyMTLSAuth().getP12FilePassKey().toCharArray());
609+
keystoreStream = java.nio.file.Files.newInputStream(Paths.get(config.proxyConfiguration().getP12File()));
610+
keyStore.load(keystoreStream, config.proxyConfiguration().getPassKey().toCharArray());
609611
sslContext = SSLContexts.custom()
610-
.loadKeyMaterial(keyStore, config.proxyMTLSAuth().getP12FilePassKey().toCharArray())
612+
.loadKeyMaterial(keyStore, config.proxyConfiguration().getPassKey().toCharArray())
611613
.build();
612614
} catch (Exception e) {
613615
_log.error("Exception caught while processing p12 file for Proxy mTLS auth: ", e);
@@ -626,22 +628,46 @@ private static SSLContext buildSSLContext(SplitClientConfig config) throws IOExc
626628

627629
private static HttpClientBuilder setupProxy(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
628630
_log.info("Initializing Split SDK with proxy settings");
629-
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(config.proxy());
631+
HttpHost proxyHost;
632+
if (config.proxyConfiguration() != null && config.proxyConfiguration().getHost() != null) {
633+
proxyHost = config.proxyConfiguration().getHost();
634+
} else {
635+
_log.warn("`proxyHost`, `proxyPort` configuration methods are deprecated. Please use `ProxyConfiguration` builder instead.");
636+
proxyHost = config.proxy();
637+
}
638+
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
630639
httpClientbuilder.setRoutePlanner(routePlanner);
631640

632-
if (config.proxyUsername() != null && config.proxyPassword() != null) {
641+
if ((config.proxyUsername() != null && config.proxyPassword() != null) ||
642+
(config.proxyConfiguration() != null && config.proxyConfiguration().getProxyCredentialsProvider() != null &&
643+
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider)) {
633644
_log.debug("Proxy setup using credentials");
645+
String userName;
646+
String password;
647+
if (config.proxyUsername() == null && config.proxyPassword() == null) {
648+
io.split.client.dtos.BasicCredentialsProvider basicAuth =
649+
(io.split.client.dtos.BasicCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider();
650+
userName = basicAuth.getUsername();
651+
password = basicAuth.getPassword();
652+
} else {
653+
_log.warn("`proxyUsername` and `proxyPassword` configuration methods are deprecated. " +
654+
"Please use `ProxyConfiguration` builder instead.");
655+
userName = config.proxyUsername();
656+
password = config.proxyPassword();
657+
}
634658
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
635-
AuthScope siteScope = new AuthScope(config.proxy().getHostName(), config.proxy().getPort());
636-
Credentials siteCreds = new UsernamePasswordCredentials(config.proxyUsername(),
637-
config.proxyPassword().toCharArray());
659+
AuthScope siteScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
660+
Credentials siteCreds = new UsernamePasswordCredentials(userName,
661+
password.toCharArray());
638662
credsProvider.setCredentials(siteScope, siteCreds);
639663
httpClientbuilder.setDefaultCredentialsProvider(credsProvider);
640664
}
641665

642-
if (config.proxyCredentialsProvider() != null) {
643-
_log.debug("Proxy setup using token");
644-
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(config.proxyCredentialsProvider()));
666+
if (config.proxyConfiguration() != null &&
667+
config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BearerCredentialsProvider) {
668+
_log.debug("Proxy setup using Bearer token");
669+
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
670+
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
645671
}
646672

647673
return httpClientbuilder;

0 commit comments

Comments
 (0)