use of org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping in project keycloak by keycloak.
the class ProxyMappingsTest method shouldReturnProxy1ForConfiguredProxyMappingWithSubDomain.
@Test
public void shouldReturnProxy1ForConfiguredProxyMappingWithSubDomain() {
ProxyMapping proxy = proxyMappings.getProxyFor("awesome.account.google.com");
assertThat(proxy.getProxyHost(), is(notNullValue()));
assertThat(proxy.getProxyHost().getHostName(), is("proxy1"));
}
use of org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping in project keycloak by keycloak.
the class ProxyMappingsAwareRoutePlanner method determineProxy.
@Override
protected HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
String targetHostName = target.getHostName();
ProxyMapping proxyMapping = proxyMappings.getProxyFor(targetHostName);
LOG.debugf("Returning proxyMapping=%s for targetHost=%s", proxyMapping, targetHostName);
UsernamePasswordCredentials proxyCredentials = proxyMapping.getProxyCredentials();
HttpHost proxyHost = proxyMapping.getProxyHost();
if (proxyCredentials != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), proxyCredentials);
context.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider);
}
return proxyHost;
}
use of org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping in project keycloak by keycloak.
the class ProxyMappingsTest method shouldReturnCorrectProxyOrFallback.
@Test
public void shouldReturnCorrectProxyOrFallback() {
ProxyMappings proxyMappingsWithFallback = ProxyMappings.valueOf(MAPPINGS_WITH_FALLBACK);
ProxyMapping forGoogle = proxyMappingsWithFallback.getProxyFor("login.google.com");
assertThat(forGoogle.getProxyHost().getHostName(), is("proxy1"));
ProxyMapping forFacebook = proxyMappingsWithFallback.getProxyFor("login.facebook.com");
assertThat(forFacebook.getProxyHost().getHostName(), is("proxy2"));
ProxyMapping forMicrosoft = proxyMappingsWithFallback.getProxyFor("login.microsoft.com");
assertThat(forMicrosoft.getProxyHost().getHostName(), is("fallback"));
ProxyMapping forSalesForce = proxyMappingsWithFallback.getProxyFor("login.salesforce.com");
assertThat(forSalesForce.getProxyHost().getHostName(), is("fallback"));
}
use of org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping in project keycloak by keycloak.
the class ProxyMappingsTest method shouldReturnProxyAuthentication.
@Test
public void shouldReturnProxyAuthentication() {
ProxyMappings proxyMappingsWithProxyAuthen = ProxyMappings.valueOf(MAPPINGS_WITH_PROXY_AUTHENTICATION);
ProxyMapping forGoogle = proxyMappingsWithProxyAuthen.getProxyFor("login.google.com");
assertThat(forGoogle.getProxyHost().getHostName(), is("proxy1"));
ProxyMapping forFacebook = proxyMappingsWithProxyAuthen.getProxyFor("login.facebook.com");
assertThat(forFacebook.getProxyHost().getHostName(), is("proxy2"));
ProxyMapping forStackOverflow = proxyMappingsWithProxyAuthen.getProxyFor("stackexchange.com");
assertThat(forStackOverflow.getProxyHost().getHostName(), is("proxy3"));
assertThat(forStackOverflow.getProxyHost().getPort(), is(88));
assertThat(forStackOverflow.getProxyCredentials().getUserName(), is("user01"));
assertThat(forStackOverflow.getProxyCredentials().getPassword(), is("pas2w0rd"));
ProxyMapping forAcmeCorp = proxyMappingsWithProxyAuthen.getProxyFor("myapp.acme.corp.com");
assertThat(forAcmeCorp.getProxyHost(), is(nullValue()));
ProxyMapping forMicrosoft = proxyMappingsWithProxyAuthen.getProxyFor("login.microsoft.com");
assertThat(forMicrosoft.getProxyHost().getHostName(), is("fallback"));
ProxyMapping forSalesForce = proxyMappingsWithProxyAuthen.getProxyFor("login.salesforce.com");
assertThat(forSalesForce.getProxyHost().getHostName(), is("fallback"));
}
use of org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping in project keycloak by keycloak.
the class ProxyMappingsTest method shouldReturnNoProxyForUnknownHost.
@Test
public void shouldReturnNoProxyForUnknownHost() {
ProxyMapping proxy = proxyMappings.getProxyFor("login.microsoft.com");
assertThat(proxy.getProxyHost(), is(nullValue()));
}
Aggregations