Example usage for org.apache.http.auth AuthScope ANY_HOST

List of usage examples for org.apache.http.auth AuthScope ANY_HOST

Introduction

In this page you can find the example usage for org.apache.http.auth AuthScope ANY_HOST.

Prototype

String ANY_HOST

To view the source code for org.apache.http.auth AuthScope ANY_HOST.

Click Source Link

Document

The null value represents any host.

Usage

From source file:be.fedict.trust.Credential.java

/**
 * Any scheme, realm, port and host is allowed.
 * //from   ww w.j  a v a2  s  .  com
 * @param username
 * @param password
 */
public Credential(String username, String password) {
    this(AuthScope.ANY_HOST, username, password);
}

From source file:org.gradle.api.internal.artifacts.repositories.transport.http.HttpClientConfigurer.java

private void configureCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials) {
    if (GUtil.isTrue(credentials.getUsername())) {
        useCredentials(httpClient, credentials, AuthScope.ANY_HOST, AuthScope.ANY_PORT);
    }/*from   w  w w . j  a  v a  2s .  co m*/
}

From source file:es.tsb.ltba.nomhad.httpclient.NomhadHttpClient.java

/**
 * Set the credentials, if the client was created without them.
 * /*from   w  w  w .j ava2  s . c  o m*/
 * @param usr
 *            user
 * @param pwd
 *            password
 */
public void setCredentials(String usr, String pwd) {
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(usr, pwd));
}

From source file:net.seedboxer.seedroid.utils.RestClient.java

public void AddBasicAuthentication(String username, String password) {
    credProvider = new BasicCredentialsProvider();
    credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(username, password));
}

From source file:com.ibm.connectors.splunklog.SplunkHttpConnection.java

public Properties sendLogEvent(SplunkConnectionData connData, byte[] thePayload, Properties properties)
        throws ConnectorException {
    HttpClient myhClient = HttpClients.custom().setConnectionManager(this.cm).build();

    HttpClientContext myhContext = HttpClientContext.create();

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(connData.getUser(), connData.getPass()));
    AuthCache authCache = new BasicAuthCache();
    authCache.put(new HttpHost(connData.getHost(), Integer.parseInt(connData.getPort()), connData.getScheme()),
            new BasicScheme());

    myhContext.setCredentialsProvider(credsProvider);
    myhContext.setAuthCache(authCache);/*from  ww  w .  jav a 2s .  c  o  m*/

    HttpPost myhPost = new HttpPost(connData.getSplunkURI());

    ByteArrayEntity payload = new ByteArrayEntity(thePayload);
    try {
        myhPost.setEntity(payload);
        HttpResponse response = myhClient.execute(myhPost, myhContext);
        Integer statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200 && !connData.getIgnoreSplunkErrors()) {
            throw new ConnectorException(
                    "Error posting log event to Splunk: " + response.getStatusLine().toString());
        }
        System.out.println(response.getStatusLine().toString());
        properties.setProperty("status", String.valueOf(statusCode));
        Integer leasedConns = Integer
                .valueOf(((PoolingHttpClientConnectionManager) this.cm).getTotalStats().getLeased());
        properties.setProperty("conns_leased", leasedConns.toString());
        Integer availConns = Integer
                .valueOf(((PoolingHttpClientConnectionManager) this.cm).getTotalStats().getAvailable());
        properties.setProperty("conns_available", availConns.toString());
    } catch (IOException e) {
        e.fillInStackTrace();
        throw new ConnectorException(e.toString());
    }
    return properties;
}

From source file:org.duracloud.common.web.RestHttpHelper.java

public RestHttpHelper(Credential credential, int socketTimeoutMs) {
    if (credential != null) {
        credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                new UsernamePasswordCredentials(credential.getUsername(), credential.getPassword()));
    }/*from w ww .ja v  a2 s  .c o  m*/

    this.socketTimeoutMs = socketTimeoutMs;
}

From source file:me.willowcheng.makerthings.util.MjpegStreamer.java

public InputStream httpRequest(String url, String usr, String pwd) {
    HttpResponse res = null;//from   w w w .  jav a 2  s .co  m
    DefaultHttpClient httpclient = new DefaultHttpClient();
    CredentialsProvider credProvider = new BasicCredentialsProvider();
    credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(usr, pwd));
    httpclient.setCredentialsProvider(credProvider);
    Log.d(TAG, "1. Sending http request");
    try {
        res = httpclient.execute(new HttpGet(URI.create(url)));
        Log.d(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode());
        if (res.getStatusLine().getStatusCode() == 401) {
            //You must turn off camera User Access Control before this will work
            return null;
        }
        Log.d(TAG, "content-type = " + res.getEntity().getContentType());
        Log.d(TAG, "content-encoding = " + res.getEntity().getContentEncoding());
        return res.getEntity().getContent();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Log.d(TAG, "Request failed-ClientProtocolException", e);
        //Error connecting to camera
    } catch (IOException e) {
        e.printStackTrace();
        Log.d(TAG, "Request failed-IOException", e);
        //Error connecting to camera
    }

    return null;

}

From source file:org.dataconservancy.dcs.integration.main.IngestTest.java

@Test
public void sipIngest_db_authentication() throws Exception {
    client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials("seadva@gmail.com", hashPassword("password")));
    String agentId = "agent:" + UUID.randomUUID().toString();
    Agent agent = new Agent();
    agent.setFirstName("Kavitha");
    agent.setLastName("Chandrasekar");
    agent.setId(agentId);//from ww w. j a va 2 s.c om
    agent.setEntityName(agent.getLastName());
    agent.setEntityCreatedTime(new Date());
    agent.setEntityLastUpdatedTime(new Date());

    new RegistryClient(registryUrl).postAgent(agent, "Curator");

    File sipFile = new File(IngestTest.class.getResource("/" + "sampleSip_2.xml").getPath());

    ResearchObject sip = new SeadXstreamStaxModelBuilder()
            .buildSip(new FileInputStream(sipFile.getAbsolutePath()));

    Collection<DcsDeliverableUnit> dus = sip.getDeliverableUnits();
    for (DcsDeliverableUnit du : dus) {
        if (du.getParents() == null || du.getParents().size() == 0) {
            SeadPerson submitter = new SeadPerson();
            submitter.setName(agent.getFirstName() + " " + agent.getLastName());
            submitter.setId(agentId);
            submitter.setIdType("registryId");
            ((SeadDeliverableUnit) du).setSubmitter(submitter);
        }
    }
    sip.setDeliverableUnits(dus);

    new SeadXstreamStaxModelBuilder().buildSip(sip, new FileOutputStream(sipFile.getAbsolutePath()));

    int code = doDeposit(sipFile);
    assertEquals(code, 202);
}

From source file:net.bioclipse.dbxp.business.DbxpManager.java

public static HttpResponse postValues(HashMap<String, String> postvars, String url)
        throws NoSuchAlgorithmException, ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(userName, password));

    List<NameValuePair> formparams = new ArrayList<NameValuePair>();
    Iterator<Entry<String, String>> it = postvars.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> next = (Map.Entry<String, String>) it.next();
        Map.Entry<String, String> pairs = next;
        formparams.add(new BasicNameValuePair(pairs.getKey(), pairs.getValue()));
    }//  w ww.  j  a  va  2s  .  com
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
    HttpPost httppost = new HttpPost(url);
    httppost.setEntity(entity);
    HttpContext localContext = new BasicHttpContext();
    return httpclient.execute(httppost, localContext);
}

From source file:org.opennms.opennms.pris.plugins.defaults.source.HttpRequisitionMergeSource.java

private Requisition getRequisition(String url, String userName, String password) {
    Requisition requisition = null;/*from   ww  w  . ja  v  a 2s  . c o m*/

    if (url != null) {
        try {
            HttpClientBuilder builder = HttpClientBuilder.create();

            // If username and password was found, inject the credentials
            if (userName != null && password != null) {

                CredentialsProvider provider = new BasicCredentialsProvider();

                // Create the authentication scope
                AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);

                // Create credential pair
                UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password);

                // Inject the credentials
                provider.setCredentials(scope, credentials);

                // Set the default credentials provider
                builder.setDefaultCredentialsProvider(provider);
            }

            HttpClient client = builder.build();
            HttpGet request = new HttpGet(url);
            HttpResponse response = client.execute(request);
            try {

                BufferedReader bufferedReader = new BufferedReader(
                        new InputStreamReader(response.getEntity().getContent()));
                JAXBContext jaxbContext = JAXBContext.newInstance(Requisition.class);

                Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
                requisition = (Requisition) jaxbUnmarshaller.unmarshal(bufferedReader);

            } catch (JAXBException e) {
                LOGGER.error("The response did not contain a valid requisition as xml.", e);
            }
            LOGGER.debug("Got Requisition {}", requisition);
        } catch (IOException ex) {
            LOGGER.error("Requesting requisition from {} failed", url, ex);
            return null;
        }
    } else {
        LOGGER.error("Parameter requisition.url is missing in requisition.properties");
        return null;
    }
    return requisition;
}