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

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

Introduction

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

Prototype

public AuthScope(final String host, final int port) 

Source Link

Document

Creates a new credentials scope for the given host, port, any realm name, and any authentication scheme.

Usage

From source file:magicware.scm.redmine.tools.RedmineClient.java

public void fillBasicAuth(String userName, String base64Pwd) {

    // Basic?// w  w  w. j a va2  s .  co m
    httpclient.getCredentialsProvider().setCredentials(
            new AuthScope(targetHost.getHostName(), targetHost.getPort()),
            new UsernamePasswordCredentials(userName,
                    StringUtils.isEmpty(base64Pwd) ? UUID.randomUUID().toString()
                            : new String(Base64.decodeBase64(base64Pwd))));
    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(targetHost, basicAuth);
    BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}

From source file:org.openhab.binding.insteonplm.internal.driver.hub.HubIOStream.java

@Override
public boolean open() {
    m_client = new DefaultHttpClient();
    if (m_user != null && m_pass != null) {
        m_client.getCredentialsProvider().setCredentials(new AuthScope(m_host, m_port),
                new UsernamePasswordCredentials(m_user, m_pass));
    }/* w ww .j a  va 2s.  c o m*/
    HttpConnectionParams.setConnectionTimeout(m_client.getParams(), 5000);

    m_in = new HubInputStream();

    m_pollThread = new Thread(this);
    m_pollThread.start();

    m_out = new HubOutputStream();
    return true;
}

From source file:org.cerberus.util.HTTPSession.java

/**
 * Start a HTTP Session with authorisation
 *
 * @param username/*from  ww  w .j a v a 2  s .  c o  m*/
 * @param password
 */
public void startSession(String username, String password) {
    // Create your httpclient
    client = new DefaultHttpClient();
    client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

    // Then provide the right credentials
    client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(username, password));

    // Generate BASIC scheme object and stick it to the execution context
    basicAuth = new BasicScheme();
    context = new BasicHttpContext();
    context.setAttribute("preemptive-auth", basicAuth);

    // Add as the first (because of the zero) request interceptor
    // It will first intercept the request and preemptively initialize the authentication scheme if there is not
    client.addRequestInterceptor(new PreemptiveAuth(), 0);
}

From source file:org.commonjava.indy.httprox.AbstractHttproxFunctionalTest.java

protected HttpClientContext proxyContext(final String user, final String pass) {
    final CredentialsProvider creds = new BasicCredentialsProvider();
    creds.setCredentials(new AuthScope(HOST, proxyPort), new UsernamePasswordCredentials(user, pass));
    final HttpClientContext ctx = HttpClientContext.create();
    ctx.setCredentialsProvider(creds);/*from  ww w.  ja v  a  2 s  . c  om*/

    return ctx;
}

From source file:com.google.resting.rest.client.HttpContext.java

public HttpContext setAuthScope(String host, int port) {
    authScope = new AuthScope(host, port);
    return this;
}

From source file:com.isotrol.impe3.connectors.httpclient.AbstractHttpClientConnector.java

/**
 * Create new default http client.//w ww  . j  av a 2  s .  c o  m
 */
public void init() {
    httpclient = new DefaultHttpClient();

    if (isAuthenticated()) {
        httpclient.getCredentialsProvider().setCredentials(new AuthScope(scopeserver, scopeport),
                new UsernamePasswordCredentials(user, pass));
    }
}

From source file:org.jugvale.peoplemanagement.client.service.RESTPersonService.java

private void createClient() {
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    DefaultHttpClient httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            credentials);/*  w w  w .j  a v a  2s.  co m*/
    client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(httpClient)).build();
}

From source file:net.homelinux.penecoptero.android.citybikes.app.RESTHelper.java

private static DefaultHttpClient setCredentials(DefaultHttpClient httpclient, String url, String username,
        String password) throws HttpException, IOException {
    HttpHost targetHost = new HttpHost(url);
    final UsernamePasswordCredentials access = new UsernamePasswordCredentials(username, password);

    httpclient.getCredentialsProvider()/*from   w  ww  . j a v a2  s . c o m*/
            .setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), access);

    httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {

            AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
            if (authState.getAuthScheme() == null) {
                authState.setAuthScheme(new BasicScheme());
                authState.setCredentials(access);
            }
        }
    }, 0);
    return httpclient;
}

From source file:org.mule.jenkins.Helper.java

public void setClientInfo() {
    client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(user, password));
    BasicScheme basicAuth = new BasicScheme();

    context.setAttribute("preemptive-auth", basicAuth);

    client.addRequestInterceptor(new PreemptiveAuth(), 0);
}

From source file:ca.sqlpower.enterprise.ClientSideSessionUtils.java

public static HttpClient createHttpClient(SPServerInfo serviceInfo, CookieStore cookieStore) {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 2000);
    DefaultHttpClient httpClient = new DefaultHttpClient(params);
    httpClient.setCookieStore(cookieStore);
    httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(serviceInfo.getServerAddress(), AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()));
    return httpClient;
}