Example usage for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider

List of usage examples for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient getCredentialsProvider.

Prototype

public synchronized final CredentialsProvider getCredentialsProvider() 

Source Link

Usage

From source file:com.couchbase.capi.CAPITestCase.java

protected HttpClient getClient() {
    DefaultHttpClient result = new DefaultHttpClient();

    result.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null),
            new UsernamePasswordCredentials("Administrator", "password"));

    return result;
}

From source file:org.apache.olingo.client.core.http.BasicAuthHttpClientFactory.java

@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
    final DefaultHttpClient httpclient = super.create(method, uri);

    httpclient.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
            new UsernamePasswordCredentials(username, password));

    return httpclient;
}

From source file:com.marklogic.client.test.util.TestServerBootstrapper.java

private void deleteRestServer() throws ClientProtocolException, IOException {

    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
            new UsernamePasswordCredentials(username, password));

    HttpDelete delete = new HttpDelete(
            "http://" + host + ":8002/v1/rest-apis/java-unittest?include=modules&include=content");

    client.execute(delete);/*from   ww  w. j a va2 s . c  o  m*/
}

From source file:com.marklogic.client.test.util.TestServerBootstrapper.java

private void invokeBootstrapExtension() throws ClientProtocolException, IOException {

    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", port),
            new UsernamePasswordCredentials(username, password));

    HttpPost post = new HttpPost("http://" + host + ":" + port + "/v1/resources/bootstrap");

    HttpResponse response = client.execute(post);
    @SuppressWarnings("unused")
    HttpEntity entity = response.getEntity();
    System.out.println("Invoked bootstrap extension.  Response is " + response.toString());
}

From source file:org.overlord.security.eval.webapp1.services.JaxrsService.java

/**
 * @return//from   ww  w .ja  va2  s .  co  m
 */
private ClientExecutor getBasicAuthExecutor() {
    String password = PASS + "||" + this.context.getRemoteUser();
    Credentials credentials = new UsernamePasswordCredentials(USER, password);
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
    ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);
    return clientExecutor;
}

From source file:com.marklogic.client.test.util.TestServerBootstrapper.java

private void installBootstrapExtension() throws IOException {

    DefaultHttpClient client = new DefaultHttpClient();

    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", port),
            new UsernamePasswordCredentials(username, password));

    HttpPut put = new HttpPut("http://" + host + ":" + port + "/v1/config/resources/bootstrap?method=POST");

    put.setEntity(new FileEntity(new File("src/test/resources/bootstrap.xqy"), "application/xquery"));
    HttpResponse response = client.execute(put);
    @SuppressWarnings("unused")
    HttpEntity entity = response.getEntity();
    System.out.println("Installed bootstrap extension.  Response is " + response.toString());

}

From source file:org.overlord.security.eval.webapp3.services.JaxrsService.java

/**
 * @return//from w  ww.ja  va2 s.c o m
 */
private ClientExecutor getBasicAuthExecutor() {
    String currentUser = this.context.getRemoteUser();
    String password = getCurrentUserAuthToken();
    Credentials credentials = new UsernamePasswordCredentials(currentUser, password);
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
    ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);
    return clientExecutor;
}

From source file:com.msopentech.odatajclient.engine.client.http.AbstractBasicAuthHttpClientFactory.java

@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
    final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri);

    httpclient.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
            new UsernamePasswordCredentials(getUsername(), getPassword()));

    return httpclient;
}

From source file:org.jasig.ssp.security.BasicAuthenticationRestTemplate.java

private HttpClient addAuthentication(DefaultHttpClient clientd, String username, String password) {
    clientd.getCredentialsProvider().setCredentials(new AuthScope(null, -1),
            new UsernamePasswordCredentials(username, password));
    return clientd;
}

From source file:com.github.restdriver.clientdriver.integration.BasicAuthTest.java

@Test
public void basicAuthWorks() throws Exception {

    clientDriver.addExpectation(onRequestTo("/").withBasicAuth("Aladdin", "open sesame"),
            giveEmptyResponse().withStatus(418)).anyTimes();

    DefaultHttpClient client = new DefaultHttpClient();
    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT),
            new UsernamePasswordCredentials("Aladdin", "open sesame"));

    HttpHost host = new HttpHost("localhost", 12345);

    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(host, basicAuth);/* w w w. j ava 2s  . c  om*/

    BasicHttpContext context = new BasicHttpContext();
    context.setAttribute(ClientContext.AUTH_CACHE, authCache);

    List<String> authPrefs = new ArrayList<String>();
    authPrefs.add(AuthPolicy.BASIC);
    client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authPrefs);

    HttpGet get = new HttpGet(clientDriver.getBaseUrl() + "/");

    HttpResponse response = client.execute(host, get, context);

    assertThat(response.getStatusLine().getStatusCode(), is(418));

}