Skip to content

Commit ef1cab8

Browse files
authored
Add Java bindings for no_proxy_hosts setting (#925)
1 parent 7f0e2b8 commit ef1cab8

17 files changed

Lines changed: 190 additions & 15 deletions

src/main/java/software/amazon/awssdk/crt/auth/credentials/CognitoCredentialsProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ private CognitoCredentialsProvider(CognitoCredentialsProviderBuilder builder) {
204204
int proxyAuthorizationType = 0;
205205
String proxyAuthorizationUsername = null;
206206
String proxyAuthorizationPassword = null;
207+
String noProxyHosts = null;
207208
HttpProxyOptions proxyOptions = builder.getHttpProxyOptions();
208209
if (proxyOptions != null) {
209210
proxyConnectionType = proxyOptions.getConnectionType().getValue();
@@ -217,6 +218,9 @@ private CognitoCredentialsProvider(CognitoCredentialsProviderBuilder builder) {
217218
proxyAuthorizationType = proxyOptions.getAuthorizationType().getValue();
218219
proxyAuthorizationUsername = proxyOptions.getAuthorizationUsername();
219220
proxyAuthorizationPassword = proxyOptions.getAuthorizationPassword();
221+
if (proxyOptions.getNoProxyHosts() != null) {
222+
noProxyHosts = proxyOptions.getNoProxyHosts();
223+
}
220224
}
221225

222226
long nativeHandle = cognitoCredentialsProviderNew(
@@ -234,6 +238,7 @@ private CognitoCredentialsProvider(CognitoCredentialsProviderBuilder builder) {
234238
proxyAuthorizationType,
235239
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
236240
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
241+
noProxyHosts != null ? noProxyHosts.getBytes(UTF8) : null,
237242
builder.loginTokenSource);
238243

239244
acquireNativeHandle(nativeHandle);
@@ -305,7 +310,8 @@ private static native long cognitoCredentialsProviderNew(CognitoCredentialsProvi
305310
int proxyAuthorizationType,
306311
byte[] proxyAuthorizationUsername,
307312
byte[] proxyAuthorizationPassword,
308-
CognitoLoginTokenSource loginTokenSource);
313+
byte[] noProxyHosts,
314+
CognitoLoginTokenSource loginTokenSource);
309315

310316
private static native void completeLoginTokenFetch(long invocationHandle, byte[] marshalledLogins, Throwable ex);
311317
}

src/main/java/software/amazon/awssdk/crt/auth/credentials/X509CredentialsProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private X509CredentialsProvider(X509CredentialsProviderBuilder builder) {
155155
int proxyAuthorizationType = 0;
156156
String proxyAuthorizationUsername = null;
157157
String proxyAuthorizationPassword = null;
158+
String noProxyHosts = null;
158159
HttpProxyOptions proxyOptions = builder.getProxyOptions();
159160
if (proxyOptions != null) {
160161
proxyConnectionType = proxyOptions.getConnectionType().getValue();
@@ -168,6 +169,7 @@ private X509CredentialsProvider(X509CredentialsProviderBuilder builder) {
168169
proxyAuthorizationType = proxyOptions.getAuthorizationType().getValue();
169170
proxyAuthorizationUsername = proxyOptions.getAuthorizationUsername();
170171
proxyAuthorizationPassword = proxyOptions.getAuthorizationPassword();
172+
noProxyHosts = proxyOptions.getNoProxyHosts();
171173
}
172174

173175
long nativeHandle = x509CredentialsProviderNew(
@@ -183,7 +185,8 @@ private X509CredentialsProvider(X509CredentialsProviderBuilder builder) {
183185
proxyTlsContextHandle,
184186
proxyAuthorizationType,
185187
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
186-
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null);
188+
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
189+
noProxyHosts != null ? noProxyHosts.getBytes(UTF8) : null);
187190

188191
acquireNativeHandle(nativeHandle);
189192
addReferenceTo(clientBootstrap);
@@ -206,5 +209,6 @@ private static native long x509CredentialsProviderNew(X509CredentialsProvider th
206209
long proxyTlsContext,
207210
int proxyAuthorizationType,
208211
byte[] proxyAuthorizationUsername,
209-
byte[] proxyAuthorizationPassword);
212+
byte[] proxyAuthorizationPassword,
213+
byte[] noProxyHosts);
210214
}

src/main/java/software/amazon/awssdk/crt/http/Http2StreamManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ private Http2StreamManager(Http2StreamManagerOptions options) {
7878
int proxyAuthorizationType = 0;
7979
String proxyAuthorizationUsername = null;
8080
String proxyAuthorizationPassword = null;
81+
String noProxyHosts = null;
8182
HttpProxyOptions proxyOptions = connectionManagerOptions.getProxyOptions();
8283

8384
if (proxyOptions != null) {
@@ -88,6 +89,7 @@ private Http2StreamManager(Http2StreamManagerOptions options) {
8889
proxyAuthorizationType = proxyOptions.getAuthorizationType().getValue();
8990
proxyAuthorizationUsername = proxyOptions.getAuthorizationUsername();
9091
proxyAuthorizationPassword = proxyOptions.getAuthorizationPassword();
92+
noProxyHosts = proxyOptions.getNoProxyHosts();
9193
}
9294

9395
HttpMonitoringOptions monitoringOptions = connectionManagerOptions.getMonitoringOptions();
@@ -113,6 +115,7 @@ private Http2StreamManager(Http2StreamManagerOptions options) {
113115
proxyAuthorizationType,
114116
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
115117
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
118+
noProxyHosts != null ? noProxyHosts.getBytes(UTF8) : null,
116119
connectionManagerOptions.isManualWindowManagement(),
117120
monitoringThroughputThresholdInBytesPerSecond,
118121
monitoringFailureIntervalInSeconds,
@@ -254,6 +257,7 @@ private static native long http2StreamManagerNew(Http2StreamManager thisObj,
254257
int proxyAuthorizationType,
255258
byte[] proxyAuthorizationUsername,
256259
byte[] proxyAuthorizationPassword,
260+
byte[] noProxyHosts,
257261
boolean isManualWindowManagement,
258262
long monitoringThroughputThresholdInBytesPerSecond,
259263
int monitoringFailureIntervalInSeconds,

src/main/java/software/amazon/awssdk/crt/http/HttpClientConnectionManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
7878
int proxyAuthorizationType = 0;
7979
String proxyAuthorizationUsername = null;
8080
String proxyAuthorizationPassword = null;
81+
String noProxyHosts = null;
8182

8283
if (proxyOptions != null) {
8384
proxyConnectionType = proxyOptions.getConnectionType().getValue();
@@ -87,6 +88,7 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
8788
proxyAuthorizationType = proxyOptions.getAuthorizationType().getValue();
8889
proxyAuthorizationUsername = proxyOptions.getAuthorizationUsername();
8990
proxyAuthorizationPassword = proxyOptions.getAuthorizationPassword();
91+
noProxyHosts = proxyOptions.getNoProxyHosts();
9092
}
9193

9294
int environmentVariableProxyConnectionType = 0;
@@ -123,6 +125,7 @@ private HttpClientConnectionManager(HttpClientConnectionManagerOptions options)
123125
proxyAuthorizationType,
124126
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
125127
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
128+
noProxyHosts != null ? noProxyHosts.getBytes(UTF8) : null,
126129
environmentVariableProxyConnectionType,
127130
environmentVariableProxyTlsConnectionOptions != null
128131
? environmentVariableProxyTlsConnectionOptions.getNativeHandle()
@@ -259,6 +262,7 @@ private static native long httpClientConnectionManagerNew(HttpClientConnectionMa
259262
int proxyAuthorizationType,
260263
byte[] proxyAuthorizationUsername,
261264
byte[] proxyAuthorizationPassword,
265+
byte[] noProxyHosts,
262266
int environmentVariableProxyConnectionType,
263267
long environmentVariableProxyTlsConnectionOptions,
264268
int environmentVariableSetting,

src/main/java/software/amazon/awssdk/crt/http/HttpProxyOptions.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class HttpProxyOptions {
1919
private TlsContext tlsContext;
2020
private HttpProxyAuthorizationType authorizationType;
2121
private HttpProxyConnectionType connectionType;
22+
private String noProxyHosts;
2223

2324
/**
2425
* what kind of authentication, if any, to use when connecting to a proxy server
@@ -182,4 +183,24 @@ public void setTlsContext(TlsContext tlsContext) {
182183
*/
183184
public TlsContext getTlsContext() { return tlsContext; }
184185

186+
/**
187+
* @return the nonProxyHosts setting for the proxy connection.
188+
*/
189+
public String getNoProxyHosts() {
190+
return noProxyHosts;
191+
}
192+
193+
/**
194+
* Sets the list of hosts for which not to use a proxy. This should be a comma seperated list
195+
* of domain names, host names, or IP Addresses following the format used by CURL.
196+
* The only wildcard available is a single "*" character, which matches all hosts,
197+
* and effectively disables the proxy.
198+
* IP addresses specified to this option can be provided using CIDR notation: an appended slash and number
199+
* specifies the number of "network bits" out of the address to use in the comparison.
200+
*
201+
* @param noProxyHosts comma seperated list of hosts to skip proxy for.
202+
*/
203+
public void setNoProxyHosts(String noProxyHosts) {
204+
this.noProxyHosts = noProxyHosts;
205+
}
185206
}

src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ private void SetupConfig(MqttConnectionConfig config) throws MqttException {
187187
proxyTlsContext != null ? proxyTlsContext.getNativeHandle() : 0,
188188
options.getAuthorizationType().getValue(),
189189
options.getAuthorizationUsername(),
190-
options.getAuthorizationPassword());
190+
options.getAuthorizationPassword(),
191+
options.getNoProxyHosts());
191192
}
192193

193194
addReferenceTo(config);
@@ -518,7 +519,8 @@ private static native void mqttClientConnectionSetHttpProxyOptions(long connecti
518519
long proxyTlsContext,
519520
int proxyAuthorizationType,
520521
String proxyAuthorizationUsername,
521-
String proxyAuthorizationPassword) throws CrtRuntimeException;
522+
String proxyAuthorizationPassword,
523+
String noProxyHosts) throws CrtRuntimeException;
522524

523525
private static native MqttClientConnectionOperationStatistics mqttClientConnectionGetOperationStatistics(
524526
long connection);

src/main/java/software/amazon/awssdk/crt/s3/S3Client.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public S3Client(S3ClientOptions options) throws CrtRuntimeException {
3838
int proxyAuthorizationType = 0;
3939
String proxyAuthorizationUsername = null;
4040
String proxyAuthorizationPassword = null;
41+
String noProxyHosts = null;
4142
// Handle FileIoOptions from S3ClientOptions
4243
boolean fioOptionsSet = false;
4344
boolean shouldStream = false;
@@ -61,6 +62,7 @@ public S3Client(S3ClientOptions options) throws CrtRuntimeException {
6162
proxyAuthorizationType = proxyOptions.getAuthorizationType().getValue();
6263
proxyAuthorizationUsername = proxyOptions.getAuthorizationUsername();
6364
proxyAuthorizationPassword = proxyOptions.getAuthorizationPassword();
65+
noProxyHosts = proxyOptions.getNoProxyHosts();
6466
}
6567

6668
int environmentVariableProxyConnectionType = 0;
@@ -108,6 +110,7 @@ public S3Client(S3ClientOptions options) throws CrtRuntimeException {
108110
proxyAuthorizationType,
109111
proxyAuthorizationUsername != null ? proxyAuthorizationUsername.getBytes(UTF8) : null,
110112
proxyAuthorizationPassword != null ? proxyAuthorizationPassword.getBytes(UTF8) : null,
113+
noProxyHosts != null ? noProxyHosts.getBytes(UTF8) : null,
111114
environmentVariableProxyConnectionType,
112115
environmentVariableProxyTlsConnectionOptions != null
113116
? environmentVariableProxyTlsConnectionOptions.getNativeHandle()
@@ -267,6 +270,7 @@ private static native long s3ClientNew(S3Client thisObj, byte[] region, long cli
267270
int proxyAuthorizationType,
268271
byte[] proxyAuthorizationUsername,
269272
byte[] proxyAuthorizationPassword,
273+
byte[] noProxyHosts,
270274
int environmentVariableProxyConnectionType,
271275
long environmentVariableProxyTlsConnectionOptions,
272276
int environmentVariableSetting,

src/native/credentials_provider.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ JNIEXPORT jlong JNICALL
429429
jlong jni_proxy_tls_context,
430430
jint jni_proxy_authorization_type,
431431
jbyteArray jni_proxy_authorization_username,
432-
jbyteArray jni_proxy_authorization_password) {
432+
jbyteArray jni_proxy_authorization_password,
433+
jbyteArray jni_no_proxy_hosts) {
433434

434435
(void)jni_class;
435436
(void)env;
@@ -471,6 +472,7 @@ JNIEXPORT jlong JNICALL
471472
jni_proxy_port,
472473
jni_proxy_authorization_username,
473474
jni_proxy_authorization_password,
475+
jni_no_proxy_hosts,
474476
jni_proxy_authorization_type,
475477
(struct aws_tls_ctx *)jni_proxy_tls_context);
476478

@@ -491,7 +493,12 @@ JNIEXPORT jlong JNICALL
491493
aws_jni_byte_cursor_from_jbyteArray_release(env, endpoint, options.endpoint);
492494

493495
aws_http_proxy_options_jni_clean_up(
494-
env, &proxy_options, jni_proxy_host, jni_proxy_authorization_username, jni_proxy_authorization_password);
496+
env,
497+
&proxy_options,
498+
jni_proxy_host,
499+
jni_proxy_authorization_username,
500+
jni_proxy_authorization_password,
501+
jni_no_proxy_hosts);
495502

496503
aws_tls_connection_options_clean_up(&tls_connection_options);
497504

@@ -929,6 +936,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_auth_credentials_CognitoCredential
929936
jint proxy_authorization_type,
930937
jbyteArray proxy_authorization_username,
931938
jbyteArray proxy_authorization_password,
939+
jbyteArray no_proxy_hosts,
932940
jobject login_token_source) {
933941

934942
(void)jni_class;
@@ -1015,6 +1023,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_auth_credentials_CognitoCredential
10151023
proxy_port,
10161024
proxy_authorization_username,
10171025
proxy_authorization_password,
1026+
no_proxy_hosts,
10181027
proxy_authorization_type,
10191028
(struct aws_tls_ctx *)native_proxy_tls_context);
10201029

@@ -1034,7 +1043,7 @@ jlong JNICALL Java_software_amazon_awssdk_crt_auth_credentials_CognitoCredential
10341043
aws_jni_byte_cursor_from_jbyteArray_release(env, marshalled_logins, logins_cursor);
10351044

10361045
aws_http_proxy_options_jni_clean_up(
1037-
env, &proxy_options, proxy_host, proxy_authorization_username, proxy_authorization_password);
1046+
env, &proxy_options, proxy_host, proxy_authorization_username, proxy_authorization_password, no_proxy_hosts);
10381047

10391048
aws_array_list_clean_up(&logins);
10401049

src/native/http2_stream_manager.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_Http2StreamManager_
106106
jint jni_proxy_authorization_type,
107107
jbyteArray jni_proxy_authorization_username,
108108
jbyteArray jni_proxy_authorization_password,
109+
jbyteArray jni_no_proxy_hosts,
109110
jboolean jni_manual_window_management,
110111
jlong jni_monitoring_throughput_threshold_in_bytes_per_second,
111112
jint jni_monitoring_failure_interval_in_seconds,
@@ -233,6 +234,7 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_Http2StreamManager_
233234
jni_proxy_port,
234235
jni_proxy_authorization_username,
235236
jni_proxy_authorization_password,
237+
jni_no_proxy_hosts,
236238
jni_proxy_authorization_type,
237239
(struct aws_tls_ctx *)jni_proxy_tls_context);
238240

@@ -246,7 +248,12 @@ JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_http_Http2StreamManager_
246248
}
247249

248250
aws_http_proxy_options_jni_clean_up(
249-
env, &proxy_options, jni_proxy_host, jni_proxy_authorization_username, jni_proxy_authorization_password);
251+
env,
252+
&proxy_options,
253+
jni_proxy_host,
254+
jni_proxy_authorization_username,
255+
jni_proxy_authorization_password,
256+
jni_no_proxy_hosts);
250257

251258
if (new_tls_conn_opts) {
252259
aws_tls_connection_options_clean_up(&tls_conn_options);

0 commit comments

Comments
 (0)