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:nl.esciencecenter.octopus.webservice.mac.MacScheme.java

/**
 * Generates normalized request string and encrypt is using a secret key
 *
 * @return MAC Authentication header/*from  w  ww. j  av a 2 s.  com*/
 * @throws AuthenticationException when signature generation fails
 */
public Header authenticate(Credentials credentials, HttpRequest request, HttpContext context)
        throws AuthenticationException {
    String id = credentials.getUserPrincipal().getName();
    String key = credentials.getPassword();
    Long timestamp = getTimestamp();
    String nonce = getNonce();
    String data = getNormalizedRequestString((HttpUriRequest) request, nonce, timestamp);

    String request_mac = calculateRFC2104HMAC(data, key, getAlgorithm(credentials));

    return new BasicHeader(AUTH.WWW_AUTH_RESP, headerValue(id, timestamp, nonce, request_mac));
}

From source file:com.google.code.maven.plugin.http.client.ProxyTest.java

@Test
public void testPrepare() {
    proxy.setHost("localhost");
    proxy.setPort(8080);//from  w w w .j a v  a2  s . c o  m
    DefaultHttpClient client = new DefaultHttpClient();
    proxy.prepare(client);
    HttpHost httpHost = (HttpHost) client.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY);
    Assert.assertNotNull(httpHost);
    Assert.assertEquals(httpHost.getHostName(), proxy.getHost());
    Assert.assertEquals(httpHost.getPort(), proxy.getPort());
    Assert.assertEquals(httpHost.getSchemeName(), HttpHost.DEFAULT_SCHEME_NAME);

    Credentials credentials = new Credentials();
    credentials.setLogin("login");
    credentials.setPassword("password");
    proxy.setCredentials(credentials);
    client = new DefaultHttpClient();
    proxy.prepare(client);
    httpHost = (HttpHost) client.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY);
    Assert.assertNotNull(httpHost);
    Assert.assertEquals(httpHost.getHostName(), proxy.getHost());
    Assert.assertEquals(httpHost.getPort(), proxy.getPort());
    Assert.assertEquals(httpHost.getSchemeName(), HttpHost.DEFAULT_SCHEME_NAME);
    org.apache.http.auth.Credentials credentials2 = client.getCredentialsProvider()
            .getCredentials(new AuthScope("localhost", 8080));
    Assert.assertNotNull(credentials2);
    Assert.assertEquals("login", credentials2.getUserPrincipal().getName());
    Assert.assertEquals("password", credentials2.getPassword());
}

From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItemAsyncTest.java

@Test
public void testProxySettingsProxyWithAuthentication() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(PROXY_HOST_PROPERTY, "hostname")
                    .put(PROXY_PORT_PROPERTY, 123).put(PROXY_USER_PROPERTY, "proxyuser")
                    .put(PROXY_PASSWORD_PROPERTY, "proxypassword").build());

    HttpClientItem item = new HttpClientItem(config);
    HttpAsyncClient client = item.getHttpAsyncClient();

    HttpHost host = HttpClientTestUtils.getProxyHost(client);
    assertNotNull(host);//  w w  w .j  a va 2s .c  om
    assertEquals("hostname", host.getHostName());
    assertEquals(123, host.getPort());

    Credentials credentials = HttpClientTestUtils.getCredentialsProvider(client)
            .getCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()));
    assertNotNull(credentials);
    assertEquals("proxyuser", credentials.getUserPrincipal().getName());
    assertEquals("proxypassword", credentials.getPassword());
    item.close();
}

From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpClientItemAsyncTest.java

@Test
public void testProxySettingsProxyWithAuthentication() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(PROXY_HOST_PROPERTY, "hostname")
                    .put(PROXY_PORT_PROPERTY, 123).put(PROXY_USER_PROPERTY, "proxyuser")
                    .put(PROXY_PASSWORD_PROPERTY, "proxypassword").build());

    HttpAsyncClientItem item = new HttpAsyncClientItem(config);
    HttpAsyncClient client = item.getHttpAsyncClient();

    HttpHost host = HttpClientTestUtils.getProxyHost(client);
    assertNotNull(host);/*from   w ww. j a va 2 s . co m*/
    assertEquals("hostname", host.getHostName());
    assertEquals(123, host.getPort());

    Credentials credentials = HttpClientTestUtils.getCredentialsProvider(client)
            .getCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()));
    assertNotNull(credentials);
    assertEquals("proxyuser", credentials.getUserPrincipal().getName());
    assertEquals("proxypassword", credentials.getPassword());
    item.close();
}

From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItemTest.java

@Test
public void testHttpAuthentication() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(HTTP_USER_PROPERTY, HTTP_USER_PROPERTY)
                    .put(HTTP_PASSWORD_PROPERTY, "httpPasswd").build());

    HttpClientItem item = new HttpClientItem(config);
    HttpClient client = item.getHttpClient();

    Credentials credentials = HttpClientTestUtils.getCredentialsProvider(client).getCredentials(AuthScope.ANY);
    assertNotNull(credentials);/*from w ww .  j av  a 2 s.c  o  m*/
    assertEquals(HTTP_USER_PROPERTY, credentials.getUserPrincipal().getName());
    assertEquals("httpPasswd", credentials.getPassword());
    item.close();
}

From source file:bad.robot.http.apache.matchers.CredentialsMatcher.java

@Override
protected boolean matchesSafely(HttpClient actual, Description mismatch) {
    AbstractHttpClient client = (AbstractHttpClient) actual;
    Credentials credentials = client.getCredentialsProvider().getCredentials(scope);
    if (credentials == null) {
        mismatch.appendText("No credentials found for ").appendValue(scope);
        return false;
    }/*w  w w  .ja v a 2  s .  co m*/
    if (!username.equals(credentials.getUserPrincipal().getName())) {
        mismatch.appendText("found username ").appendValue(credentials.getUserPrincipal().getName());
        return false;
    }
    if (!password.equals(credentials.getPassword())) {
        mismatch.appendText("found password ").appendValue(credentials.getPassword());
        return false;
    }
    return true;
}

From source file:org.hawk.http.HTTPManager.java

@Override
public void run() throws Exception {
    try {//from  w  ww .j av  a2s .co  m
        final ICredentialsStore credStore = indexer.getCredentialsStore();
        if (username != null) {
            // The credentials were provided by a previous setCredentials
            // call: retry the change to the credentials store.
            setCredentials(username, password, credStore);
        } else {
            final Credentials credentials = credStore.get(repositoryURL.toString());
            if (credentials != null) {
                this.username = credentials.getUsername();
                this.password = credentials.getPassword();
            } else {
                /*
                 * If we use null for the default username/password, SVNKit
                 * will try to use the GNOME keyring in Linux, and that will
                 * lock up our Eclipse instance in some cases.
                 */
                console.printerrln("No username/password recorded for the repository " + repositoryURL);
                this.username = "";
                this.password = "";
            }
        }

        isActive = true;
    } catch (Exception e) {
        console.printerrln("exception in svnmanager run():");
        console.printerrln(e);
    }
}

From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItemTest.java

@Test
public void testProxySettingsProxyWithAuthentication() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(PROXY_HOST_PROPERTY, "hostname")
                    .put(PROXY_PORT_PROPERTY, 123).put(PROXY_USER_PROPERTY, "proxyuser")
                    .put(PROXY_PASSWORD_PROPERTY, "proxypassword").build());

    HttpClientItem item = new HttpClientItem(config);
    HttpClient client = item.getHttpClient();

    HttpHost host = HttpClientTestUtils.getProxyHost(client);
    assertNotNull(host);// w w  w . jav  a 2  s .  c o m
    assertEquals("hostname", host.getHostName());
    assertEquals(123, host.getPort());

    Credentials credentials = HttpClientTestUtils.getCredentialsProvider(client)
            .getCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()));
    assertNotNull(credentials);
    assertEquals("proxyuser", credentials.getUserPrincipal().getName());
    assertEquals("proxypassword", credentials.getPassword());
    item.close();
}

From source file:org.opentravel.schemacompiler.repository.impl.NTLMSystemCredentialsProvider.java

private NTCredentials traslateToNTLMCredentials(Credentials credentials) {
    String fullUserName = credentials.getUserPrincipal().getName();
    String[] tokens = fullUserName.split("\\\\", 2);
    String userName = "";
    String domain = null;/*from   w ww  . j a  va2 s .c  om*/
    if (tokens.length == 2) {
        if (tokens[0] != null && !tokens[0].isEmpty()) {
            domain = tokens[0];
        }
        userName = tokens[1];
    } else {
        userName = tokens[0];
    }
    String workstation = null; // how to support workstation ???
    return new NTCredentials(userName, credentials.getPassword(), workstation, domain);
}

From source file:org.apache.cloudstack.cloudian.client.CloudianClient.java

private void checkAuthFailure(final HttpResponse response) {
    if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
        final Credentials credentials = httpContext.getCredentialsProvider().getCredentials(AuthScope.ANY);
        LOG.error(/*from   w  ww  .  j  av a 2s  . c  o m*/
                "Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal="
                        + credentials.getUserPrincipal() + ", password=" + credentials.getPassword()
                        + ", API url=" + adminApiUrl);
        throw new ServerApiException(ApiErrorCode.UNAUTHORIZED,
                "Cloudian backend API call unauthorized, please ask your administrator to fix integration issues.");
    }
}