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

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

Introduction

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

Prototype

public synchronized final CredentialsProvider getCredentialsProvider() 

Source Link

Usage

From source file:com.hortonworks.registries.auth.client.AuthenticatorTestCase.java

private SystemDefaultHttpClient getHttpClient() {
    final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
    httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
    Credentials use_jaas_creds = new Credentials() {
        public String getPassword() {
            return null;
        }/*  w w w  .j av  a  2  s  .co m*/

        public Principal getUserPrincipal() {
            return null;
        }
    };

    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, use_jaas_creds);
    return httpClient;
}

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

public InputStream getStream(final String baseUrl, final LayerAuthentication authentication,
        final String layerId) throws IOException {
    // Create a HTTP client object, which will initiate the connection:
    final HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT);
    SystemDefaultHttpClient client = new SystemDefaultHttpClient(httpParams);

    String url = addCredentialsToUrl(baseUrl, authentication);

    // -- add basic authentication
    if (null != authentication
            && (LayerAuthenticationMethod.BASIC.equals(authentication.getAuthenticationMethod())
                    || LayerAuthenticationMethod.DIGEST.equals(authentication.getAuthenticationMethod()))) {
        // Set up the credentials:
        Credentials creds = new UsernamePasswordCredentials(authentication.getUser(),
                authentication.getPassword());
        AuthScope scope = new AuthScope(parseDomain(url), parsePort(url), authentication.getRealm());
        client.getCredentialsProvider().setCredentials(scope, creds);
    }//  w  w w .ja v  a  2s  .c o m

    // -- add interceptors if any --
    addInterceptors(client, baseUrl, layerId);

    // Create the GET method with the correct URL:
    HttpGet get = new HttpGet(url);

    // Execute the GET:
    HttpResponse response = client.execute(get);
    log.debug("Response: {} - {}", response.getStatusLine().getStatusCode(),
            response.getStatusLine().getReasonPhrase());

    return new LayerHttpServiceStream(response, client);
}