Search in sources :

Example 6 with ProxyMapping

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"));
}
Also used : ProxyMapping(org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping) Test(org.junit.Test)

Example 7 with ProxyMapping

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;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) ProxyMapping(org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 8 with ProxyMapping

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"));
}
Also used : ProxyMapping(org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping) Test(org.junit.Test)

Example 9 with ProxyMapping

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"));
}
Also used : ProxyMapping(org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping) Test(org.junit.Test)

Example 10 with ProxyMapping

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()));
}
Also used : ProxyMapping(org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping) Test(org.junit.Test)

Aggregations

ProxyMapping (org.keycloak.connections.httpclient.ProxyMappings.ProxyMapping)11 Test (org.junit.Test)10 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1