Java Code Examples for org.apache.http.auth.AuthScope#ANY_HOST

The following examples show how to use org.apache.http.auth.AuthScope#ANY_HOST . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebServicesClientTest.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
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;
  } 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());
}
 
Example 2
Source File: WebServicesClient.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static void setupUserPassAuthScheme(AuthScheme scheme, String httpScheme, AuthSchemeProvider provider, ConfigProvider configuration)
{
  String username = configuration.getProperty(scheme, "username");
  String password = configuration.getProperty(scheme, "password");
  if ((username != null) && (password != null)) {
    LOG.info("Setting up scheme {}", scheme);
    AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    setupHttpAuthScheme(httpScheme, provider, authScope, credentials);
  } else if ((username != null) || (password != null)) {
    LOG.warn("Not setting up scheme {}, missing credentials {}", scheme, (username == null) ? "username" : "password");
  }
}
 
Example 3
Source File: HttpClientProvider.java    From bobcat with Apache License 2.0 5 votes vote down vote up
private AuthScope getAuthScope(String urlString) {
  String host = AuthScope.ANY_HOST;
  int port = AuthScope.ANY_PORT;
  try {
    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);
}
 
Example 4
Source File: WebServicesClient.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private static void setupUserPassAuthScheme(AuthScheme scheme, String httpScheme, AuthSchemeProvider provider, ConfigProvider configuration)
{
  String username = configuration.getProperty(scheme, "username");
  String password = configuration.getProperty(scheme, "password");
  if ((username != null) && (password != null)) {
    LOG.info("Setting up scheme {}", scheme);
    AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme);
    Credentials credentials = new UsernamePasswordCredentials(username, password);
    setupHttpAuthScheme(httpScheme, provider, authScope, credentials);
  } else if ((username != null) || (password != null)) {
    LOG.warn("Not setting up scheme {}, missing credentials {}", scheme, (username == null) ? "username" : "password");
  }
}
 
Example 5
Source File: KieRequestBuilder.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected DefaultHttpClient setupAuthenticationClient() {
    DefaultHttpClient httpclient = new DefaultHttpClient();

    // basic authentication
    String username = _configClient.getCredentials().getUsername();
    String password = _configClient.getCredentials().getPassword();
    UsernamePasswordCredentials authCredentials = new UsernamePasswordCredentials(username, password);

    // TODO restrict host and scope!
    AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT);
    httpclient.getCredentialsProvider().setCredentials(authScope, authCredentials);
    return httpclient;
}