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

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

Introduction

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

Prototype

String ANY_REALM

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

Click Source Link

Document

The null value represents any realm.

Usage

From source file:se.anyro.tagtider.utils.Http.java

public static DefaultHttpClient getClient() {
    if (client == null) {
        client = new DefaultHttpClient();
        Credentials creds = new UsernamePasswordCredentials("tagtider", "codemocracy");
        AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
        client.getCredentialsProvider().setCredentials(scope, creds);
    }//w  w w . ja v  a 2s .  c  om
    return client;
}

From source file:org.ow2.bonita.facade.rest.apachehttpclient.ApacheHttpClientUtil.java

public static HttpClient getHttpClient(String serverAddress, String username, String password)
        throws URISyntaxException {
    URI serverURI = new URI(serverAddress);
    DefaultHttpClient client = new DefaultHttpClient();
    AuthScope authScope = new AuthScope(serverURI.getHost(), serverURI.getPort(), AuthScope.ANY_REALM,
            AuthScope.ANY_SCHEME);/*from   w  ww . ja va2 s .  c om*/
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    client.getCredentialsProvider().setCredentials(authScope, credentials);
    return client;
}

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

public static void checkUserCredentials(String username, String password, AuthScheme authScheme)
        throws NoSuchFieldException, IllegalAccessException {
    CredentialsProvider provider = getCredentialsProvider();
    String httpScheme = AuthScope.ANY_SCHEME;
    if (authScheme == AuthScheme.BASIC) {
        httpScheme = AuthSchemes.BASIC;/*  w ww.  j a  v  a  2  s.c om*/
    } else if (authScheme == AuthScheme.DIGEST) {
        httpScheme = AuthSchemes.DIGEST;
    }
    AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM,
            httpScheme);
    Credentials credentials = provider.getCredentials(authScope);
    Assert.assertNotNull("Credentials", credentials);
    Assert.assertTrue("Credentials type is user",
            UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass()));
    UsernamePasswordCredentials pwdCredentials = (UsernamePasswordCredentials) credentials;
    Assert.assertEquals("Username", username, pwdCredentials.getUserName());
    Assert.assertEquals("Password", password, pwdCredentials.getPassword());
}

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

/**
 * Test AuthScope override with no overriding values set. Nothing should
 * change in original host/port.//from   www  .j  a  v  a 2  s  .  c  om
 */
@Test
public void testGetScopeNothingOverridden() {
    BasicAuthScope scope = new BasicAuthScope();

    AuthScope authScope = scope.getScope("original.host.com", 3456);
    Assert.assertEquals("original.host.com", authScope.getHost());
    Assert.assertEquals(3456, authScope.getPort());
    Assert.assertEquals(AuthScope.ANY_REALM, authScope.getRealm());
}

From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java

public ControlappsConnector(String username, String password, String restSubPath) throws Exception {

    this.username = username;
    this.password = password;
    restPrefix = "http://" + RESTSERVICE_HOSTNAME + ":" + RESTSERVICE_PORT + restSubPath;

    try {//from w  ww  .  ja  va 2s .  com
        objMapper = new ObjectMapper();
        objMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); // Ignore unknown fields

        // set authentication for rest template
        AuthScope authScope = new AuthScope(RESTSERVICE_HOSTNAME, RESTSERVICE_PORT, AuthScope.ANY_REALM);
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(authScope, credentials);

        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(client);
        restTemplate = new RestTemplate(factory);
        if (restTemplate == null)
            throw new Exception("");
    } catch (Throwable e) {
        throw new Exception("Failed to initialize connection with controlapps. Is it up?");
    }
}

From source file:org.nuxeo.connect.connector.http.ProxyHelper.java

public static void configureProxyIfNeeded(RequestConfig.Builder requestConfigBuilder,
        CredentialsProvider credentialsProvider, String url) {
    if (ConnectUrlConfig.useProxy()) {
        // configure proxy host
        HttpHost proxyHost = null;// w w w. j  a v  a 2 s. c om
        if (ConnectUrlConfig.useProxyPac()) {
            String[] proxy = pacResolver.findProxy(url);
            if (proxy != null) {
                proxyHost = new HttpHost(proxy[0], Integer.parseInt(proxy[1]));
            }
        } else {
            proxyHost = new HttpHost(ConnectUrlConfig.getProxyHost(), ConnectUrlConfig.getProxyPort());
        }

        if (proxyHost != null) {
            requestConfigBuilder.setProxy(proxyHost);
            // configure proxy auth in BA
            if (ConnectUrlConfig.isProxyAuthenticated()) {
                AuthScope authScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort(),
                        AuthScope.ANY_REALM);
                if (ConnectUrlConfig.isProxyNTLM()) {
                    NTCredentials ntlmCredential = new NTCredentials(ConnectUrlConfig.getProxyLogin(),
                            ConnectUrlConfig.getProxyPassword(), ConnectUrlConfig.getProxyNTLMHost(),
                            ConnectUrlConfig.getProxyNTLMDomain());
                    credentialsProvider.setCredentials(authScope, ntlmCredential);
                } else {
                    Credentials ba = new UsernamePasswordCredentials(ConnectUrlConfig.getProxyLogin(),
                            ConnectUrlConfig.getProxyPassword());
                    credentialsProvider.setCredentials(authScope, ba);
                }
            }
        }
    }
}

From source file:org.tnova.service.catalog.client.RestTemplateFactory.java

@Override
public void afterPropertiesSet() throws Exception {
    final int timeout = 5;

    final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout * 1000)
            .setSocketTimeout(timeout * 1000).build();

    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM),
            new UsernamePasswordCredentials("user1", "user1Pass"));
    final CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig)
            .setDefaultCredentialsProvider(credentialsProvider).build();

    final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(client);
    restTemplate = new RestTemplate(requestFactory);

}

From source file:info.ajaxplorer.client.http.AjxpHttpClient.java

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