Example usage for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials

List of usage examples for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials

Introduction

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

Prototype

public UsernamePasswordCredentials(final String userName, final String password) 

Source Link

Document

The constructor with the username and password arguments.

Usage

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   ww  w .  j a v a2 s.  c o  m*/
    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.mondora.chargify.controller.ChargifyAdapter.java

protected void setup(String key, String domain) {
    this.domain = domain;
    this.key = key;
    host = new HttpHost(domain + ".chargify.com", 443, "https");

    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(key, "x");
    credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(domain + ".chargify.com", 443, "ChargifyAdapter API"), creds);

    // todo preemtive and cache autentication
    //        client.getParams().setAuthenticationPreemptive(true);
    //        org.apache.http.client.AuthCache authCache = new BasicAuthCache();
    //        // Generate BASIC scheme object and add it to the local auth cache
    //        BasicScheme basicAuth = new BasicScheme();
    //        authCache.put("chargify.com", basicAuth);

    if (logger.isDebugEnabled())
        logger.debug("ChargifyAdapter client created for domain " + domain);
}

From source file:org.eclipse.lyo.testsuite.oslcv2.TestsBase.java

public static void staticSetup() {
    if (setupProps == null) {
        setupProps = SetupProperties.setup(null);
        updateParams = setupProps.getProperty("updateParams");
        String userId = setupProps.getProperty("userId");
        String pw = setupProps.getProperty("pw");
        basicCreds = new UsernamePasswordCredentials(userId, pw);
        Header h = new BasicHeader("OSLC-Core-Version", "2.0");
        Header h2 = new BasicHeader("DoorsRP-Request-Type", "private"); // TODO: RRC special sauce
        headers = new Header[] { h, h2 };
        String onlyOnceStr = setupProps.getProperty("runOnlyOnce");
        if (onlyOnceStr != null && onlyOnceStr.equals("false")) {
            onlyOnce = false;/*from   www.j a v  a 2  s  .  c  o m*/
        }
        String defUsageStr = setupProps.getProperty("useDefaultUsageForCreation");
        if (defUsageStr != null && defUsageStr.equals("false")) {
            useDefaultUsageForCreation = false;
        }
        setupBaseUrl = setupProps.getProperty("baseUri");
        String authType = setupProps.getProperty("authMethod");
        if (authType.equalsIgnoreCase("OAUTH")) {
            authMethod = AuthMethods.OAUTH;
        } else if (authType.equalsIgnoreCase("FORM")) {
            authMethod = AuthMethods.FORM;
            formLogin(userId, pw);
        }

        useThisServiceProvider = setupProps.getProperty("useThisServiceProvider");

        // First, Setup plain old XML
        String fileName = setupProps.getProperty("createTemplateXmlFile");
        if (fileName != null)
            xmlCreateTemplate = OSLCUtils.readFileByNameAsString(fileName);
        fileName = setupProps.getProperty("updateTemplateXmlFile");
        if (fileName != null)
            xmlUpdateTemplate = OSLCUtils.readFileByNameAsString(fileName);
        // Now RDF/XML
        fileName = setupProps.getProperty("createTemplateRdfXmlFile");
        if (fileName != null)
            rdfXmlCreateTemplate = OSLCUtils.readFileByNameAsString(fileName);
        fileName = setupProps.getProperty("updateTemplateRdfXmlFile");
        if (fileName != null)
            rdfXmlUpdateTemplate = OSLCUtils.readFileByNameAsString(fileName);
        // Now JSON
        fileName = setupProps.getProperty("createTemplateJsonFile");
        if (fileName != null)
            jsonCreateTemplate = OSLCUtils.readFileByNameAsString(fileName);
        fileName = setupProps.getProperty("updateTemplateJsonFile");
        if (fileName != null)
            jsonUpdateTemplate = OSLCUtils.readFileByNameAsString(fileName);
        // Now handle if RDF/XML wasn't given
        if (rdfXmlCreateTemplate == null)
            rdfXmlCreateTemplate = xmlCreateTemplate;
        if (rdfXmlUpdateTemplate == null)
            rdfXmlUpdateTemplate = xmlUpdateTemplate;
    }
}

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: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()));
    }//  w w  w. j  a va 2  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 ww  .j a  v  a2 s . c om*/
    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);// w  w w . ja  va  2  s . co m
    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:org.sonatype.spice.zapper.client.hc4.Hc4ClientPreemptiveAuthTest.java

@Override
protected Client getClient(Parameters parameters, String remoteUrl) {
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USERNAME, PASSWORD));
    return new Hc4ClientBuilder(parameters, remoteUrl).withPreemptiveRealm(credentialsProvider).build();
}

From source file:com.byteengine.client.Client.java

public void setProxySettings(String proxyHost, int proxyPort, String proxyUsername, String proxyPass) {
    HttpHost proxy = new HttpHost(proxyHost, proxyPort);

    proxyConfig = RequestConfig.custom().setProxy(proxy).build();

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    AuthScope authScope = new AuthScope(proxyHost, proxyPort);
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(proxyUsername, proxyPass);
    credsProvider.setCredentials(authScope, creds);

    httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}

From source file:org.zaizi.alfresco.publishing.marklogic.MarkLogicPublishingHelper.java

/**
 * Build a httpContext from channel properties.
 *
 * @param channelProperties the channel properties
 * @return the http context from channel properties
 *///  www  .  j  a  va2  s .c om
public HttpContext getHttpContextFromChannelProperties(final Map<QName, Serializable> channelProperties) {

    String markLogicUsername = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_USERNAME,
            channelProperties.get(PublishingModel.PROP_CHANNEL_USERNAME));
    String markLogicPassword = (String) encryptor.decrypt(PublishingModel.PROP_CHANNEL_PASSWORD,
            channelProperties.get(PublishingModel.PROP_CHANNEL_PASSWORD));

    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(markLogicUsername, markLogicPassword);
    HttpContext context = new BasicHttpContext();
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, creds);
    context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);

    return context;
}