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

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

Introduction

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

Prototype

AuthScope ANY

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

Click Source Link

Document

Default scope matching any host, port, realm and authentication scheme.

Usage

From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItem.java

/**
 * @param config Http client configuration
 *///from   ww w . ja va 2  s .  c  o m
HttpClientItem(HttpClientConfig config) {
    this.config = config;

    // optional SSL client certificate support
    SSLContext sslContext;
    if (CertificateLoader.isSslKeyManagerEnabled(config) || CertificateLoader.isSslTrustStoreEnbaled(config)) {
        try {
            sslContext = CertificateLoader.buildSSLContext(config);
        } catch (IOException | GeneralSecurityException ex) {
            throw new IllegalArgumentException("Invalid SSL client certificate configuration.", ex);
        }
    } else {
        sslContext = CertificateLoader.createDefaultSSlContext();
    }

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // optional proxy authentication
    if (StringUtils.isNotEmpty(config.getProxyUser())) {
        credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
                new UsernamePasswordCredentials(config.getProxyUser(), config.getProxyPassword()));
    }
    // optional http basic authentication support
    if (StringUtils.isNotEmpty(config.getHttpUser())) {
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(config.getHttpUser(), config.getHttpPassword()));
    }

    // build http clients
    connectionManager = buildConnectionManager(config, sslContext);
    httpClient = buildHttpClient(config, connectionManager, credentialsProvider);
}

From source file:com.twotoasters.android.hoot.HootTransportHttpClient.java

@Override
public void setup(Hoot hoot) {
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 10);
    ConnManagerParams.setTimeout(params, hoot.getTimeout());
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpConnectionParams.setConnectionTimeout(params, hoot.getTimeout());
    HttpConnectionParams.setSoTimeout(params, hoot.getTimeout());
    HttpConnectionParams.setTcpNoDelay(params, true);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    sslSocketFactory.setHostnameVerifier(hoot.getSSLHostNameVerifier());
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));

    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    mClient = new DefaultHttpClient(cm, params);
    if (hoot.isBasicAuth()) {
        mClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(hoot.getBasicAuthUsername(), hoot.getBasicAuthPassword()));
    }//from  ww w .  j a va2 s. c  om
}

From source file:org.apache.jena.fuseki.embedded.TestFusekiTestAuth.java

@Test(expected = HttpException.class)
public void testServer_auth_bad_user() {
    BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials("USERUSER", PASSWORD);
    credsProvider.setCredentials(AuthScope.ANY, credentials);
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
    } catch (HttpException ex) {
        throw assertAuthHttpException(ex);
    }//from   www. ja  va  2 s . c o m
}

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
 *///from  ww w .  ja  va 2  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;
}

From source file:org.mule.test.integration.security.HttpListenerAuthenticationTestCase.java

private CredentialsProvider getCredentialsProvider(String user, String password) {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    return credsProvider;
}

From source file:aajavafx.LoginController.java

public static String getPassword(String userName) throws MalformedURLException, JSONException, IOException {
    String password = "";

    Managers manager = new Managers();
    Managers myManager = new Managers();
    Gson gson = new Gson();

    JSONObject jo = new JSONObject();
    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("ADMIN", "password");
    provider.setCredentials(AuthScope.ANY, credentials);
    HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
    HttpGet get = new HttpGet("http://localhost:8080/MainServerREST/api/managers/username/" + userName);

    HttpResponse response = client.execute(get);
    System.out.println("RESPONSE IS: " + response);
    JSONArray jsonArray = new JSONArray(
            IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8")));
    System.out.println(jsonArray);
    for (int i = 0; i < jsonArray.length(); i++) {
        jo = (JSONObject) jsonArray.getJSONObject(i);
        manager = gson.fromJson(jo.toString(), Managers.class);
        if (manager.getManUsername().equals(userName)) {
            password = manager.getManPassword();
        }//  ww w.  j  a  v a2 s  .  c om

        System.out.println(password);

    }
    return password;
}

From source file:multichain.command.builders.QueryBuilderCommon.java

protected void initialize(String ip, String port, String login, String password,
        RuntimeParameters queryParameter) {
    httppost = new HttpPost("http://" + ip + ":" + port);

    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(login, password);
    provider.setCredentials(AuthScope.ANY, credentials);
    queryParameters = queryParameter;//from   w  w  w  . j ava  2 s .  c  o m

    httpclient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();

}

From source file:it.cloudicaro.disit.kb.rdf.HttpUtil.java

public static String post(URL url, String data, String contentType, String user, String passwd)
        throws Exception {
    //System.out.println("POST "+url);
    HttpClient client = HttpClients.createDefault();
    HttpPost request = new HttpPost(url.toURI());
    request.setEntity(new StringEntity(data, ContentType.create(contentType, "UTF-8")));

    HttpClientContext context = HttpClientContext.create();
    if (user != null && passwd != null) {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, passwd));
        context.setCredentialsProvider(credsProvider);
    }//from   ww  w .  ja va2 s  .  c  om

    HttpResponse response = client.execute(request, context);

    StatusLine s = response.getStatusLine();
    int code = s.getStatusCode();
    //System.out.println(code);
    if (code == 204)
        return "";
    if (code != 200)
        throw new Exception(
                "failed access to " + url.toString() + " code: " + code + " " + s.getReasonPhrase());

    Reader reader = null;
    try {
        reader = new InputStreamReader(response.getEntity().getContent());

        StringBuilder sb = new StringBuilder();
        {
            int read;
            char[] cbuf = new char[1024];
            while ((read = reader.read(cbuf)) != -1) {
                sb.append(cbuf, 0, read);
            }
        }

        return sb.toString();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.datatorrent.stram.util.WebServicesClient.java

public static void initAuth(ConfigProvider configuration) {
    // Setting up BASIC and DIGEST auth
    setupUserPassAuthScheme(AuthScheme.BASIC, AuthSchemes.BASIC, new BasicSchemeFactory(), configuration);
    setupUserPassAuthScheme(AuthScheme.DIGEST, AuthSchemes.DIGEST, new DigestSchemeFactory(), configuration);

    // Adding kerberos standard auth
    setupHttpAuthScheme(AuthSchemes.KERBEROS, new KerberosSchemeFactory(), AuthScope.ANY,
            DEFAULT_TOKEN_CREDENTIALS);//from   www .  j a  v  a  2s . c  o  m

    authRegistry = registryBuilder.build();
}