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

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

Introduction

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

Prototype

String DIGEST

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

Click Source Link

Document

Digest authentication scheme as defined in RFC2617.

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);//from  w  w w. j  a  va 2s  . c  o  m
    authpref.add(AuthPolicy.DIGEST);
    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);//www .  ja v  a2s .  co  m
    authpref.add(AuthPolicy.DIGEST);
    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.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  w  w  w. ja va  2s.  co m
    _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);//from  ww w . ja v  a 2  s . c o m
        authpref.add(AuthPolicy.DIGEST);
        httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
        credentialsProvider.setCredentials(new AuthScope(null, -1), credentials);
    }

    // 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:org.eobjects.datacleaner.monitor.pentaho.PentahoCarteClient.java

private HttpClient createHttpClient(PentahoJobType pentahoJobType) {
    final String hostname = pentahoJobType.getCarteHostname();
    final Integer port = pentahoJobType.getCartePort();
    final String username = pentahoJobType.getCarteUsername();
    final String password = pentahoJobType.getCartePassword();

    final DefaultHttpClient httpClient = new DefaultHttpClient();
    final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider();

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

    final List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);//from  w  w w.  j  av a  2 s.c  o  m
    authpref.add(AuthPolicy.DIGEST);
    httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);

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

From source file:org.gradle.internal.resource.transport.http.HttpConnectorFactory.java

private Set<String> getAuthSchemes(Collection<Authentication> authenticationTypes) {
    Set<String> authSchemes = Sets.newHashSet();
    for (Authentication authenticationType : authenticationTypes) {
        if (BasicAuthentication.class.isAssignableFrom(authenticationType.getClass())) {
            authSchemes.add(AuthPolicy.BASIC);
        } else if (DigestAuthentication.class.isAssignableFrom(authenticationType.getClass())) {
            authSchemes.add(AuthPolicy.DIGEST);
        } else {/*ww w .j  av a2 s .c  om*/
            throw new IllegalArgumentException(String.format("Authentication type of '%s' is not supported.",
                    authenticationType.getClass().getSimpleName()));
        }
    }

    if (authSchemes.size() == 0) {
        authSchemes.add(AuthScope.ANY_SCHEME);
    }

    return authSchemes;
}

From source file:dk.deck.resolver.ArtifactResolverRemote.java

public ArtifactResolverRemote(List<String> repositories, String username, String password) {
    this.repositories = Collections.unmodifiableList(repositories);
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(MAX_HTTP_THREADS);
    connectionManager.setDefaultMaxPerRoute(MAX_HTTP_THREADS);
    httpclient = new DefaultHttpClient(connectionManager);

    List<String> authpref = new ArrayList<String>();
    authpref.add(AuthPolicy.BASIC);/*from  w  ww  . ja va2 s.c om*/
    authpref.add(AuthPolicy.DIGEST);
    httpclient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
    httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);

}

From source file:com.mpower.mintel.android.utilities.WebUtils.java

public static final AuthScope buildAuthScopes(String host) {

    AuthScope a;/*from w w  w.  ja va  2  s  .c om*/
    // allow digest auth on any port...
    a = new AuthScope(host, -1, null, AuthPolicy.DIGEST);

    return a;
}