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

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

Introduction

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

Prototype

int ANY_PORT

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

Click Source Link

Document

The -1 value represents any port.

Usage

From source file:cz.zcu.kiv.eegdatabase.logic.util.BasicAuthHttpClient.java

public BasicAuthHttpClient(URL url, String username, String password, ThreadSafeClientConnManager connManager) {
    super(connManager);
    this.url = url;

    BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(url.getHost(), AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(username, password));
    setCredentialsProvider(credsProvider);
}

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

/**
 * Any scheme, realm and port is allowed.
 * //from w ww . jav a 2  s  . c o m
 * @param host
 * @param username
 * @param password
 */
public Credential(String host, String username, String password) {
    this(host, AuthScope.ANY_PORT, username, password);
}

From source file:pydio.sdk.java.http.AjxpHttpClient.java

public void refreshCredentials(UsernamePasswordCredentials credentials) {
    this.getCredentialsProvider().setCredentials(
            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), credentials);
}

From source file:org.apache.maven.wagon.providers.http.BasicAuthScope.java

/**
 * Create an authScope given the /repository/host and /repository/password
 * and the /server/basicAuth or /server/proxyBasicAuth host, port and realm
 * settings. The basicAuth setting should override the repository settings
 * host and/or port if host, port or realm is set to "ANY".
 * <p/>/*from   w w w .  ja va 2  s .c  o  m*/
 * Realm can also be set to a specific string and will be set if
 * /server/basicAuthentication/realm is non-null
 *
 * @param host The server setting's /server/host value
 * @param port The server setting's /server/port value
 * @return
 */
public AuthScope getScope(String host, int port) {
    if (getHost() != null //
            && "ANY".compareTo(getHost()) == 0 //
            && getPort() != null //
            && "ANY".compareTo(getPort()) == 0 //
            && getRealm() != null //
            && "ANY".compareTo(getRealm()) == 0) {
        return AuthScope.ANY;
    }
    String scopeHost = host;
    if (getHost() != null) {
        if ("ANY".compareTo(getHost()) == 0) {
            scopeHost = AuthScope.ANY_HOST;
        } else {
            scopeHost = getHost();
        }
    }

    int scopePort = port > -1 ? port : AuthScope.ANY_PORT;
    // -1 for server/port settings does this, but providing an override here
    // in
    // the BasicAuthScope config
    if (getPort() != null) {
        if ("ANY".compareTo(getPort()) == 0) {
            scopePort = AuthScope.ANY_PORT;
        } else {
            scopePort = Integer.parseInt(getPort());
        }
    }

    String scopeRealm = AuthScope.ANY_REALM;
    if (getRealm() != null) {
        if ("ANY".compareTo(getRealm()) != 0) {
            scopeRealm = getRealm();
        } else {
            scopeRealm = getRealm();
        }
    }

    return new AuthScope(scopeHost, scopePort, scopeRealm);
}

From source file:com.betfair.testing.utils.cougar.manager.HttpPageManager.java

public int getPage(HttpPageBean bean) {

    // Get bean properties
    String requestedProtocol = bean.getProtocol();
    String requestedHost = bean.getHost();
    int requestedPort = bean.getPort();
    String requestedLink = bean.getLink();
    String username = bean.getAuthusername();
    String password = bean.getAuthpassword();

    final SSLSocketFactory sf = new SSLSocketFactory(createEasySSLContext(),
            SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    Scheme https = new Scheme("https", 9999, sf);

    // Set up httpClient to use given auth details and protocol
    DefaultHttpClient client = new DefaultHttpClient();
    client.getConnectionManager().getSchemeRegistry().register(https);
    client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(username, password));

    int status = -1;

    InputStream inputStream = null;
    // Make the request
    try {/*from w w w.jav  a 2 s . c  o m*/
        final HttpGet httpget = new HttpGet(
                URIUtils.createURI(requestedProtocol, requestedHost, requestedPort, requestedLink, null, null));
        final HttpResponse httpResponse = client.execute(httpget);
        inputStream = httpResponse.getEntity().getContent();
        status = httpResponse.getStatusLine().getStatusCode();

        if (status == HttpStatus.SC_OK) {
            bean.setPageLoaded(true);

            byte[] buffer = new byte[(int) httpResponse.getEntity().getContentLength()];
            int read;
            int count = 0;
            while ((read = inputStream.read()) != -1) {
                buffer[count] = (byte) read;
                count++;
            }
            bean.setPageText(new String(buffer, "UTF-8"));
            bean.setBuffer(buffer);
        }
    } catch (IOException e1) {
        return -1;
    } catch (URISyntaxException e) {
        return -1;
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    return status;
}

From source file:com.cognifide.qa.bb.provider.http.HttpClientProvider.java

private AuthScope getAuthScope(String urlString) {
    String host = AuthScope.ANY_HOST;
    int port = AuthScope.ANY_PORT;
    try {//  w w w  .  j a v  a 2 s . co m
        URI uri = new URI(urlString);
        host = StringUtils.defaultString(uri.getHost(), AuthScope.ANY_HOST);
        port = uri.getPort();
    } catch (URISyntaxException e) {
        LOG.error("Could not parse '{}' as a valid URI", urlString, e);
    }
    return new AuthScope(host, port);
}

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

@Override
public Object dump() throws Exception {
    Requisition requisition = null;//from  w  ww . j av a 2  s.co  m

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

        // If username and password was found, inject the credentials
        if (getUserName() != null && getPassword() != 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(getUserName(),
                    getPassword());

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

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

        HttpClient client = builder.build();
        HttpGet request = new HttpGet(getUrl());
        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);
    } else {
        LOGGER.error("Parameter requisition.url is missing in requisition.properties");
    }
    if (requisition == null) {
        LOGGER.error("Requisition is null for unknown reasons");
        return null;
    }
    LOGGER.info("HttpRequisitionSource delivered for requisition '{}'", requisition.getNodes().size());
    return requisition;
}

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);
    }//  w  ww  . jav  a 2  s .c om
}

From source file:org.openhab.binding.rwesmarthome.internal.communicator.util.HttpComponentsHelper.java

/**
 * prepare for the https connection/*from w w  w .  jav  a  2 s  .  c  o m*/
 * call this in the constructor of the class that does the connection if
 * it's used multiple times
 */
private void setup() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

    params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf8");

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // set the user credentials for our site "example.com"
    credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT),
            new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere"));
    clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    context = new BasicHttpContext();
    context.setAttribute("http.auth.credentials-provider", credentialsProvider);
}

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

/**
 * Set the credentials, if the client was created without them.
 * //  w w w .  j  a v a 2  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));
}