Search in sources :

Example 1 with BasicHttpAuthConfig

use of com.nextdoor.bender.auth.BasicHttpAuthConfig in project bender by Nextdoor.

the class HttpTransportFactoryTest method testBasicAuthHeaders.

@Test
public void testBasicAuthHeaders() {
    HttpTransportConfig config = new HttpTransportConfig();
    config.addHttpHeader("foo", "bar");
    BasicHttpAuthConfig auth = new BasicHttpAuthConfig();
    auth.setUsername("foo");
    auth.setPassword(new StringValueConfig("bar"));
    config.setBasicHttpAuth(auth);
    HttpTransportFactory factory = spy(new HttpTransportFactory());
    factory.setConf(config);
    ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
    verify(factory, times(1)).getClient(anyBoolean(), anyString(), captor.capture(), anyInt());
    Map<String, String> expected = new HashMap<String, String>();
    expected.put("foo", "bar");
    expected.put("Authorization", "Basic Zm9vOmJhcg==");
    assertEquals(expected, captor.getValue());
}
Also used : HashMap(java.util.HashMap) StringValueConfig(com.nextdoor.bender.config.value.StringValueConfig) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) BasicHttpAuthConfig(com.nextdoor.bender.auth.BasicHttpAuthConfig) Test(org.junit.Test)

Example 2 with BasicHttpAuthConfig

use of com.nextdoor.bender.auth.BasicHttpAuthConfig in project bender by Nextdoor.

the class HttpTransportFactory method setConf.

@Override
public void setConf(AbstractConfig config) {
    HttpTransportConfig httpConfig = (HttpTransportConfig) config;
    BasicHttpAuthConfig auth = (BasicHttpAuthConfig) httpConfig.getBasicHttpAuth();
    if (auth != null) {
        byte[] encodedAuth = Base64.encodeBase64((auth.getUsername() + ":" + auth.getPassword()).getBytes());
        httpConfig.addHttpHeader(HttpHeaders.AUTHORIZATION, "Basic " + new String(encodedAuth));
    }
    super.setConf(config);
}
Also used : BasicHttpAuthConfig(com.nextdoor.bender.auth.BasicHttpAuthConfig)

Example 3 with BasicHttpAuthConfig

use of com.nextdoor.bender.auth.BasicHttpAuthConfig in project bender by Nextdoor.

the class ElasticSearchTransportFactory method getClient.

@Override
protected CloseableHttpClient getClient(boolean useSSL, String url, Map<String, String> stringHeaders, int socketTimeout) {
    HttpClientBuilder cb = super.getClientBuilder(useSSL, url, stringHeaders, socketTimeout);
    ElasticSearchTransportConfig config = (ElasticSearchTransportConfig) super.config;
    if (config.getAuthConfig() != null) {
        if (config.getAuthConfig() instanceof BasicHttpAuthConfig) {
            cb = addUserPassAuth(cb, (BasicHttpAuthConfig) config.getAuthConfig());
        } else if (config.getAuthConfig() instanceof UrlSigningAuthConfig) {
            cb = addSigningAuth(cb, (UrlSigningAuthConfig) config.getAuthConfig());
        }
    }
    RequestConfig rc = RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(config.getTimeout()).build();
    cb.setDefaultRequestConfig(rc);
    return cb.build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) UrlSigningAuthConfig(com.nextdoor.bender.auth.aws.UrlSigningAuthConfig) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) BasicHttpAuthConfig(com.nextdoor.bender.auth.BasicHttpAuthConfig)

Aggregations

BasicHttpAuthConfig (com.nextdoor.bender.auth.BasicHttpAuthConfig)3 UrlSigningAuthConfig (com.nextdoor.bender.auth.aws.UrlSigningAuthConfig)1 StringValueConfig (com.nextdoor.bender.config.value.StringValueConfig)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1