Example usage for org.apache.http.client.params AuthPolicy BASIC

List of usage examples for org.apache.http.client.params AuthPolicy BASIC

Introduction

In this page you can find the example usage for org.apache.http.client.params AuthPolicy BASIC.

Prototype

String BASIC

To view the source code for org.apache.http.client.params AuthPolicy BASIC.

Click Source Link

Document

Basic authentication scheme as defined in RFC2617 (considered inherently insecure, but most widely supported)

Usage

From source file:org.datacleaner.cluster.http.SimpleMainAppForManualTesting.java

public static void main(String[] args) throws Throwable {

    // create a HTTP BASIC enabled HTTP client
    final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
    final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    authpref.add(AuthPolicy.DIGEST);/* ww  w .  j ava  2  s.  c  o  m*/
    httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
    credentialsProvider.setCredentials(new AuthScope("localhost", 8080), credentials);
    credentialsProvider.setCredentials(new AuthScope("localhost", 9090), credentials);

    // register endpoints
    final List<String> slaveEndpoints = new ArrayList<String>();
    slaveEndpoints.add("http://localhost:8080/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");
    slaveEndpoints.add("http://localhost:9090/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");

    final HttpClusterManager clusterManager = new HttpClusterManager(httpClient, slaveEndpoints);

    final DataCleanerConfiguration configuration = ClusterTestHelper.createConfiguration("manual_test", false);

    // build a job that concats names and inserts the concatenated names
    // into a file
    final AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(configuration);
    jobBuilder.setDatastore("orderdb");
    jobBuilder.addSourceColumns("CUSTOMERS.CUSTOMERNUMBER", "CUSTOMERS.CUSTOMERNAME",
            "CUSTOMERS.CONTACTFIRSTNAME", "CUSTOMERS.CONTACTLASTNAME");

    AnalyzerComponentBuilder<CompletenessAnalyzer> completeness = jobBuilder
            .addAnalyzer(CompletenessAnalyzer.class);
    completeness.addInputColumns(jobBuilder.getSourceColumns());
    completeness.setConfiguredProperty("Conditions",
            new CompletenessAnalyzer.Condition[] { CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL });

    AnalysisJob job = jobBuilder.toAnalysisJob();
    jobBuilder.close();

    AnalysisResultFuture result = new DistributedAnalysisRunner(configuration, clusterManager).run(job);

    if (result.isErrornous()) {
        throw result.getErrors().get(0);
    }

    final List<AnalyzerResult> results = result.getResults();
    for (AnalyzerResult analyzerResult : results) {
        System.out.println("result:" + analyzerResult);
        if (analyzerResult instanceof CompletenessAnalyzerResult) {
            int invalidRowCount = ((CompletenessAnalyzerResult) analyzerResult).getInvalidRowCount();
            System.out.println("invalid records found: " + invalidRowCount);
        } else {
            System.out.println("class: " + analyzerResult.getClass().getName());
        }
    }
}

From source file:org.eobjects.analyzer.cluster.http.SimpleMainAppForManualTesting.java

public static void main(String[] args) throws Throwable {

    // create a HTTP BASIC enabled HTTP client
    final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
    final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();
    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    authpref.add(AuthPolicy.DIGEST);//from ww  w  . j a v a2  s . co  m
    httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
    credentialsProvider.setCredentials(new AuthScope("localhost", 8080), credentials);
    credentialsProvider.setCredentials(new AuthScope("localhost", 9090), credentials);

    // register endpoints
    final List<String> slaveEndpoints = new ArrayList<String>();
    slaveEndpoints.add("http://localhost:8080/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");
    slaveEndpoints.add("http://localhost:9090/DataCleaner-monitor/repository/DC/cluster_slave_endpoint");

    final HttpClusterManager clusterManager = new HttpClusterManager(httpClient, slaveEndpoints);

    final AnalyzerBeansConfiguration configuration = ClusterTestHelper.createConfiguration("manual_test",
            false);

    // build a job that concats names and inserts the concatenated names
    // into a file
    final AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(configuration);
    jobBuilder.setDatastore("orderdb");
    jobBuilder.addSourceColumns("CUSTOMERS.CUSTOMERNUMBER", "CUSTOMERS.CUSTOMERNAME",
            "CUSTOMERS.CONTACTFIRSTNAME", "CUSTOMERS.CONTACTLASTNAME");

    AnalyzerJobBuilder<CompletenessAnalyzer> completeness = jobBuilder.addAnalyzer(CompletenessAnalyzer.class);
    completeness.addInputColumns(jobBuilder.getSourceColumns());
    completeness.setConfiguredProperty("Conditions",
            new CompletenessAnalyzer.Condition[] { CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL,
                    CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL });

    AnalysisJob job = jobBuilder.toAnalysisJob();
    jobBuilder.close();

    AnalysisResultFuture result = new DistributedAnalysisRunner(configuration, clusterManager).run(job);

    if (result.isErrornous()) {
        throw result.getErrors().get(0);
    }

    final List<AnalyzerResult> results = result.getResults();
    for (AnalyzerResult analyzerResult : results) {
        System.out.println("result:" + analyzerResult);
        if (analyzerResult instanceof CompletenessAnalyzerResult) {
            int invalidRowCount = ((CompletenessAnalyzerResult) analyzerResult).getInvalidRowCount();
            System.out.println("invalid records found: " + invalidRowCount);
        } else {
            System.out.println("class: " + analyzerResult.getClass().getName());
        }
    }
}

From source file:org.eclipse.aether.transport.http.AuthSchemePool.java

public synchronized AuthScheme get() {
    AuthScheme authScheme = null;/*w w w . j a  va 2s .  com*/
    if (!authSchemes.isEmpty()) {
        authScheme = authSchemes.removeLast();
    } else if (AuthPolicy.BASIC.equalsIgnoreCase(schemeName)) {
        authScheme = new BasicScheme();
    }
    return authScheme;
}

From source file:org.odk.collect.android.utilities.EnhancedHttpClient.java

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new EnhancedDigestSchemeFactory());
    return registry;
}

From source file:org.datacleaner.util.http.HttpBasicMonitorHttpClient.java

public HttpBasicMonitorHttpClient(HttpClient httpClient, String hostname, int port, String username,
        String password) {//from www. jav  a  2 s  . com
    _httpClient = (DefaultHttpClient) httpClient;

    final CredentialsProvider credentialsProvider = _httpClient.getCredentialsProvider();

    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);

    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);
    authpref.add(AuthPolicy.DIGEST);
    _httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);

    credentialsProvider.setCredentials(new AuthScope(hostname, port), credentials);
}

From source file:org.datacleaner.monitor.cluster.HttpClusterManagerFactory.java

@Override
public ClusterManager getClusterManager(TenantIdentifier tenant) {
    final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
    if (username != null && password != null) {
        final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
        final List<String> authpref = new ArrayList<String>();
        authpref.add(AuthPolicy.BASIC);
        authpref.add(AuthPolicy.DIGEST);
        httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
        credentialsProvider.setCredentials(new AuthScope(null, -1), credentials);
    }/* ww  w  .ja  v a  2 s  .  co  m*/

    // use the server list
    final List<String> finalEndpoints = new ArrayList<String>();
    for (String endpoint : slaveServerUrls) {
        if (!endpoint.endsWith("/")) {
            endpoint = endpoint + "/";
        }
        endpoint = endpoint + "repository/" + tenant.getId() + "/cluster_slave_endpoint";
        finalEndpoints.add(endpoint);
    }

    return new HttpClusterManager(httpClient, finalEndpoints);
}

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 ww. j av a  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));

}

From source file:com.redwoodsystems.android.apps.utils.HttpUtil.java

public static void setBasicAuthCredentials(HttpClient client, String userName, String password) {

    //BASIC Authentication
    List<String> authPrefs = new ArrayList<String>(2);
    authPrefs.add(AuthPolicy.BASIC);
    client.getParams().setParameter("http.auth.scheme-pref", authPrefs);

    ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(org.apache.http.auth.AuthScope.ANY,
            new UsernamePasswordCredentials(userName, password));
}

From source file:org.jasig.portlet.calendar.adapter.exchange.NtlmAuthHttpClient.java

@Override
public void afterPropertiesSet() throws Exception {
    if (authenticationSchemes == null) {
        authenticationSchemes = new HashMap<String, AuthSchemeFactory>();
        final AuthSchemeFactory fac = new NTLMSchemeFactory();
        final AuthSchemeFactory bfac = new BasicSchemeFactory();
        authenticationSchemes.put(AuthPolicy.BASIC, bfac);
        authenticationSchemes.put(AuthPolicy.NTLM, fac);
        authenticationSchemes.put(AuthPolicy.SPNEGO, fac);
    }/*from w w  w  . ja  va 2 s. com*/
    setup();
    if (log.isDebugEnabled()) {
        log.debug("Support is available for the following authenticationSchemes="
                + authenticationSchemes.keySet());
    }
}