Example usage for org.apache.http.auth Credentials getPassword

List of usage examples for org.apache.http.auth Credentials getPassword

Introduction

In this page you can find the example usage for org.apache.http.auth Credentials getPassword.

Prototype

String getPassword();

Source Link

Usage

From source file:com.microsoft.alm.plugin.authentication.AuthHelper.java

public static AuthenticationInfo createAuthenticationInfo(final String serverUri,
        final Credentials credentials) {
    return new AuthenticationInfo(credentials.getUserPrincipal().getName(), credentials.getPassword(),
            serverUri, credentials.getUserPrincipal().getName());
}

From source file:at.orz.arangodb.http.CURLLogger.java

public static void log(String url, HttpRequestEntity requestEntity, String userAgent, Credentials credencials) {

    boolean includeBody = (requestEntity.type == RequestType.POST || requestEntity.type == RequestType.PUT
            || requestEntity.type == RequestType.PATCH)
            && (requestEntity.bodyText != null && requestEntity.bodyText.length() != 0);

    StringBuilder buffer = new StringBuilder();

    if (includeBody) {
        buffer.append("\n");
        buffer.append("cat <<-___EOB___ | ");
    }//from ww  w .  j  a va2 s  . c om

    buffer.append("curl -X ").append(requestEntity.type);
    buffer.append(" --dump -");

    // header
    if (requestEntity.headers != null && !requestEntity.headers.isEmpty()) {
        for (Entry<String, Object> header : requestEntity.headers.entrySet()) {
            buffer.append(" -H '").append(header.getKey()).append(":").append(header.getValue()).append("'");
        }
    }

    // basic auth
    if (credencials != null) {
        buffer.append(" -u ").append(credencials.getUserPrincipal().getName()).append(":")
                .append(credencials.getPassword());
    }

    // user-agent
    //buffer.append(" -A '").append(userAgent).append("'");

    if (includeBody) {
        buffer.append(" -d @-");
    }

    buffer.append(" '").append(url).append("'");

    if (includeBody) {
        buffer.append("\n");
        buffer.append(requestEntity.bodyText);
        buffer.append("\n");
        buffer.append("___EOB___");
    }

    logger.debug("[CURL]{}", buffer);

}

From source file:com.arangodb.http.CURLLogger.java

public static void log(String url, HttpRequestEntity requestEntity, String userAgent, Credentials credencials) {

    boolean includeBody = (requestEntity.type == RequestType.POST || requestEntity.type == RequestType.PUT
            || requestEntity.type == RequestType.PATCH)
            && (requestEntity.bodyText != null && requestEntity.bodyText.length() != 0);

    StringBuilder buffer = new StringBuilder();

    if (includeBody) {
        buffer.append("\n");
        buffer.append("cat <<-___EOB___ | ");
    }//w w w .j av  a 2  s.co m

    buffer.append("curl -X ").append(requestEntity.type);
    buffer.append(" --dump -");

    // header
    if (requestEntity.headers != null && !requestEntity.headers.isEmpty()) {
        for (Entry<String, Object> header : requestEntity.headers.entrySet()) {
            buffer.append(" -H '").append(header.getKey()).append(":").append(header.getValue()).append("'");
        }
    }

    // basic auth
    if (credencials != null) {
        buffer.append(" -u ").append(credencials.getUserPrincipal().getName()).append(":")
                .append(credencials.getPassword());
    }

    // user-agent
    // buffer.append(" -A '").append(userAgent).append("'");

    if (includeBody) {
        buffer.append(" -d @-");
    }

    buffer.append(" '").append(url).append("'");

    if (includeBody) {
        buffer.append("\n");
        buffer.append(requestEntity.bodyText);
        buffer.append("\n");
        buffer.append("___EOB___");
    }

    logger.debug("[CURL]{}", buffer);

}

From source file:com.microsoft.alm.plugin.context.ServerContextTest.java

@Test
public void getClientConfig() {
    AuthenticationInfo info = new AuthenticationInfo("user1", "pass", "server1", "4display");
    final ClientConfig config = ServerContext.getClientConfig(ServerContext.Type.TFS, info, false);

    final Map<String, Object> properties = config.getProperties();
    Assert.assertEquals(3, properties.size());

    Assert.assertEquals(false, properties.get(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION));
    Assert.assertEquals(RequestEntityProcessing.BUFFERED,
            properties.get(ClientProperties.REQUEST_ENTITY_PROCESSING));

    final CredentialsProvider cp = (CredentialsProvider) properties
            .get(ApacheClientProperties.CREDENTIALS_PROVIDER);
    final Credentials credentials = cp.getCredentials(AuthScope.ANY);
    Assert.assertEquals(info.getPassword(), credentials.getPassword());
    Assert.assertEquals(info.getUserName(), credentials.getUserPrincipal().getName());

    // Make sure Fiddler properties get set if property is on
    final ClientConfig config2 = ServerContext.getClientConfig(ServerContext.Type.TFS, info, true);
    final Map<String, Object> properties2 = config2.getProperties();
    //proxy setting doesn't automatically mean we need to setup ssl trust store anymore
    Assert.assertEquals(4, properties2.size());
    Assert.assertNotNull(properties2.get(ClientProperties.PROXY_URI));
    Assert.assertNull(properties2.get(ApacheClientProperties.SSL_CONFIG));

    info = new AuthenticationInfo("users1", "pass", "https://tfsonprem.test", "4display");
    final ClientConfig config3 = ServerContext.getClientConfig(ServerContext.Type.TFS, info, false);
    final Map<String, Object> properties3 = config3.getProperties();
    Assert.assertEquals(4, properties3.size());
    Assert.assertNull(properties3.get(ClientProperties.PROXY_URI));
    Assert.assertNotNull(properties3.get(ApacheClientProperties.SSL_CONFIG));
}

From source file:com.cisco.cta.taxii.adapter.httpclient.CredentialsProviderFactoryTest.java

@Test
public void proxyWithBasicAuth() throws MalformedURLException {
    ProxySettings proxySettings = new ProxySettings();
    proxySettings.setAuthenticationType(ProxyAuthenticationType.BASIC);
    proxySettings.setUrl(new URL("http://localhost:8001/"));
    proxySettings.setUsername("tester");
    proxySettings.setPassword("testPass");
    CredentialsProviderFactory factory = new CredentialsProviderFactory(taxiiSettings, proxySettings);
    CredentialsProvider credsProvider = factory.build();
    Credentials creds = credsProvider.getCredentials(new AuthScope("localhost", 8001));
    assertThat(creds.getUserPrincipal().getName(), is("tester"));
    assertThat(creds.getPassword(), is("testPass"));
}

From source file:com.cisco.cta.taxii.adapter.httpclient.CredentialsProviderFactoryTest.java

@Test
public void proxyWithNTLMAuth() throws MalformedURLException {
    ProxySettings proxySettings = new ProxySettings();
    proxySettings.setAuthenticationType(ProxyAuthenticationType.NTLM);
    proxySettings.setUrl(new URL("http://localhost:8001/"));
    proxySettings.setUsername("tester");
    proxySettings.setPassword("testPass");
    CredentialsProviderFactory factory = new CredentialsProviderFactory(taxiiSettings, proxySettings);
    CredentialsProvider credsProvider = factory.build();
    Credentials creds = credsProvider.getCredentials(new AuthScope("localhost", 8001));
    assertThat(creds.getUserPrincipal().getName(), is("tester"));
    assertThat(creds.getPassword(), is("testPass"));
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.model.authentication.RealmTest.java

@Test
public void shouldApplySettingsToHttpClient() {
    when(cryptorFactoryMock.getCryptor("pgp")).thenReturn(cryptorMock);
    AuthenticationRealmConfig config = createRealmConfig();
    when(preferencesMock.getValue("userKey", null)).thenReturn("user1");
    when(preferencesMock.getValue("passKey", null)).thenReturn("pass1");
    when(cryptorMock.decrypt("pass1")).thenReturn("pass2");
    Realm realm = new Realm(config, cryptorFactoryMock);

    DefaultHttpClient httpClient = new DefaultHttpClient();
    realm.applyBasicAuthentication(httpClient);

    Credentials credentials = httpClient.getCredentialsProvider().getCredentials(AuthScope.ANY);
    assertThat(credentials.getUserPrincipal().getName(), is("user1"));
    assertThat(credentials.getPassword(), is("pass2"));
}

From source file:org.janusgraph.diskstorage.es.rest.util.BasicAuthHttpClientConfigCallbackTest.java

@Test
public void testSetDefaultCredentialsProviderWithRealm() throws Exception {

    final CredentialsProvider cp = basicAuthTestBase(HTTP_REALM);

    // expected: will match any host in that specific realm
    final Credentials credentialsForRealm1 = cp.getCredentials(new AuthScope("dummyhost1", 1234, HTTP_REALM));
    assertEquals(HTTP_USER, credentialsForRealm1.getUserPrincipal().getName());
    assertEquals(HTTP_PASSWORD, credentialsForRealm1.getPassword());

    // ...but not in any other realms
    final Credentials credentialsForRealm3 = cp
            .getCredentials(new AuthScope("dummyhost1", 1234, "Not_" + HTTP_REALM));
    assertNull(credentialsForRealm3);//from   w  w w  .j  a v a 2 s.c  o m
}

From source file:io.github.jonestimd.neo4j.client.http.ApacheHttpDriverTest.java

@Test
public void createWithCredentials() throws Exception {
    ApacheHttpDriver driver = new ApacheHttpDriver("user", "password", "host", 9999);

    CloseableHttpClient client = getField(driver, "client");
    CredentialsProvider credentialsProvider = getField(client, "credentialsProvider");
    Credentials credentials = credentialsProvider.getCredentials(new AuthScope("host", 9999));
    assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
    assertThat(credentials.getPassword()).isEqualTo("password");
}

From source file:org.geomajas.layer.common.proxy.LayerHttpServiceTest.java

@Test
public void testAuthentication() throws IOException {
    // TODO: there is something wrong with cache invalidation, using uuid for now !!!
    try {/*from ww  w .j  av a2 s . c om*/
        cachingLayerHttpService.getStream("http://somehost/" + UUID.randomUUID().toString(),
                new MockProxyLayer("layer1"));
    } catch (Exception e) {
        // ok to fail
    }
    // check the authentication
    CredentialsProvider p = cachingLayerHttpService.getClient().getCredentialsProvider();
    Credentials cc = p.getCredentials(new AuthScope("somehost", 80, "realm-layer1"));
    Assert.assertEquals("user-layer1", cc.getUserPrincipal().getName());
    Assert.assertEquals("password-layer1", cc.getPassword());

    // check for layer 2
    try {
        cachingLayerHttpService.getStream("https://somehost/" + UUID.randomUUID().toString(),
                new MockProxyLayer("layer2"));
    } catch (Exception e) {
        // ok to fail
    }

    // check the authentication
    p = cachingLayerHttpService.getClient().getCredentialsProvider();
    cc = p.getCredentials(new AuthScope("somehost", 443, "realm-layer2"));
    Assert.assertEquals("user-layer2", cc.getUserPrincipal().getName());
    Assert.assertEquals("password-layer2", cc.getPassword());

    // TODO: test functioning of interceptors (without setting up connection ?) !!!
    Assert.assertEquals(2, interceptors.getMap().size());
}