use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-greengrass-nucleus by aws-greengrass.
the class ProxyUtils method getHttpProxyOptions.
/**
* Provides a software.amazon.awssdk.crt.http.HttpProxyOptions object that can be used when building various
* CRT library clients (like mqtt and http)
*
* @param deviceConfiguration contains user specified system proxy values
* @param tlsContext contains TLS options for proxy connection if an HTTPS proxy is used
* @return httpProxyOptions containing user proxy settings, if specified. If not, httpProxyOptions is null.
*/
@Nullable
public static HttpProxyOptions getHttpProxyOptions(DeviceConfiguration deviceConfiguration, @NonNull ClientTlsContext tlsContext) {
String proxyUrl = deviceConfiguration.getProxyUrl();
if (Utils.isEmpty(proxyUrl)) {
return null;
}
HttpProxyOptions httpProxyOptions = new HttpProxyOptions();
httpProxyOptions.setHost(ProxyUtils.getHostFromProxyUrl(proxyUrl));
httpProxyOptions.setPort(ProxyUtils.getPortFromProxyUrl(proxyUrl));
if ("https".equalsIgnoreCase(getSchemeFromProxyUrl(proxyUrl))) {
httpProxyOptions.setTlsContext(tlsContext);
}
String proxyUsername = getProxyUsername(proxyUrl, deviceConfiguration.getProxyUsername());
if (Utils.isNotEmpty(proxyUsername)) {
httpProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic);
httpProxyOptions.setAuthorizationUsername(proxyUsername);
httpProxyOptions.setAuthorizationPassword(getProxyPassword(proxyUrl, deviceConfiguration.getProxyPassword()));
}
return httpProxyOptions;
}
use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-greengrass-nucleus by aws-greengrass.
the class ProxyUtilsTest method testGetHttpProxyOptions.
@Test
void testGetHttpProxyOptions() {
when(deviceConfiguration.getProxyUrl()).thenReturn("https://myproxy:8080");
when(deviceConfiguration.getProxyUsername()).thenReturn("test-user");
when(deviceConfiguration.getProxyPassword()).thenReturn("itsasecret");
HttpProxyOptions httpProxyOptions = ProxyUtils.getHttpProxyOptions(deviceConfiguration, new ClientTlsContext(TlsContextOptions.createDefaultClient()));
assertEquals("myproxy", httpProxyOptions.getHost());
assertEquals(8080, httpProxyOptions.getPort());
assertEquals(HttpProxyOptions.HttpProxyAuthorizationType.Basic, httpProxyOptions.getAuthorizationType());
assertEquals("test-user", httpProxyOptions.getAuthorizationUsername());
assertEquals("itsasecret", httpProxyOptions.getAuthorizationPassword());
}
use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-crt-java by awslabs.
the class ProxyTest method buildDirectMqttConnection.
private MqttClientConnection buildDirectMqttConnection(ProxyTestType testType, ProxyAuthType authType) {
try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
HostResolver resolver = new HostResolver(eventLoopGroup);
ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
TlsContext tlsContext = createX509TlsContext(null);
MqttClient mqttClient = new MqttClient(bootstrap, tlsContext);
MqttConnectionConfig connectionConfig = new MqttConnectionConfig();
TlsContext proxyTlsContext = createProxyTlsContext(testType)) {
HttpProxyOptions proxyOptions = buildProxyOptions(testType, authType, proxyTlsContext);
String clientId = PROXY_TEST_CLIENTID + (UUID.randomUUID()).toString();
connectionConfig.setMqttClient(mqttClient);
connectionConfig.setEndpoint(MQTT_ENDPOINT);
connectionConfig.setHttpProxyOptions(proxyOptions);
connectionConfig.setCleanSession(true);
connectionConfig.setClientId(clientId);
connectionConfig.setPort(MQTT_DIRECT_PORT);
connectionConfig.setProtocolOperationTimeoutMs(60000);
return new MqttClientConnection(connectionConfig);
}
}
use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-crt-java by awslabs.
the class ProxyTest method buildProxiedX509CredentialsProvider.
private CredentialsProvider buildProxiedX509CredentialsProvider(ProxyTestType testType, ProxyAuthType authType) {
try (EventLoopGroup eventLoopGroup = new EventLoopGroup(1);
HostResolver resolver = new HostResolver(eventLoopGroup);
ClientBootstrap bootstrap = new ClientBootstrap(eventLoopGroup, resolver);
TlsContext tlsContext = createX509TlsContext(null);
TlsContext proxyTlsContext = createProxyTlsContext(testType)) {
HttpProxyOptions proxyOptions = buildProxyOptions(testType, authType, proxyTlsContext);
X509CredentialsProvider.X509CredentialsProviderBuilder builder = new X509CredentialsProvider.X509CredentialsProviderBuilder();
builder.withClientBootstrap(bootstrap).withEndpoint(X509_CREDENTIALS_ENDPOINT).withProxyOptions(proxyOptions).withRoleAlias(X509_CREDENTIALS_ROLE_ALIAS).withThingName(X509_CREDENTIALS_THING_NAME).withTlsContext(tlsContext);
return builder.build();
}
}
use of software.amazon.awssdk.crt.http.HttpProxyOptions in project aws-sdk-java-v2 by aws.
the class AwsCrtAsyncHttpClient method buildProxyOptions.
private HttpProxyOptions buildProxyOptions(ProxyConfiguration proxyConfiguration) {
if (proxyConfiguration == null) {
return null;
}
HttpProxyOptions clientProxyOptions = new HttpProxyOptions();
clientProxyOptions.setHost(proxyConfiguration.host());
clientProxyOptions.setPort(proxyConfiguration.port());
if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) {
clientProxyOptions.setTlsContext(tlsContext);
}
if (proxyConfiguration.username() != null && proxyConfiguration.password() != null) {
clientProxyOptions.setAuthorizationUsername(proxyConfiguration.username());
clientProxyOptions.setAuthorizationPassword(proxyConfiguration.password());
clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic);
} else {
clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.None);
}
return clientProxyOptions;
}
Aggregations