org.apache.http.auth.params.AuthPNames Java Examples

The following examples show how to use org.apache.http.auth.params.AuthPNames. 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: Http4Util.java    From httpsig-java with The Unlicense 6 votes vote down vote up
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) {
    if (client == null) {
        throw new NullPointerException("client");
    }

    if (keychain == null) {
        throw new NullPointerException("keychain");
    }

    client.getAuthSchemes().register(Constants.SCHEME, new AuthSchemeFactory() {
        public AuthScheme newInstance(HttpParams params) {
            return new Http4SignatureAuthScheme();
        }
    });

    Signer signer = new Signer(keychain, keyId);
    client.getCredentialsProvider().setCredentials(AuthScope.ANY, new SignerCredentials(signer));
    client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
                                    Arrays.asList(Constants.SCHEME));

    HttpClientParams.setAuthenticating(client.getParams(), true);
}
 
Example #2
Source File: Kick.java    From freeacs with MIT License 5 votes vote down vote up
private HttpGet authenticate(
    DefaultHttpClient client, HttpGet get, String urlStr, String username, String password)
    throws MalformedURLException {
  URL url = new URL(urlStr);
  List<String> authPrefs = new ArrayList<String>(2);
  authPrefs.add(AuthPolicy.DIGEST);
  authPrefs.add(AuthPolicy.BASIC);
  client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authPrefs);
  client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authPrefs);
  Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
  client
      .getCredentialsProvider()
      .setCredentials(new AuthScope(url.getHost(), url.getPort()), defaultcreds);
  return get;
}
 
Example #3
Source File: HttpSolrClientFactory.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void appendAuthentication(Credentials credentials, String authPolicy, SolrClient solrClient) {
	if (isHttpSolrClient(solrClient)) {
		HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient;

		if (credentials != null && StringUtils.isNotBlank(authPolicy)
				&& assertHttpClientInstance(httpSolrClient.getHttpClient())) {
			AbstractHttpClient httpClient = (AbstractHttpClient) httpSolrClient.getHttpClient();
			httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), credentials);
			httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(authPolicy));
		}
	}
}
 
Example #4
Source File: URIHandle.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
public URIHandle(String host, int port, String user, String password, Authentication authType) {
  super();

  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
    new Scheme("http", port, PlainSocketFactory.getSocketFactory())
  );

  // PoolingClientConnectionManager connMgr = new PoolingClientConnectionManager(  // 4.2
  ThreadSafeClientConnManager connMgr = new ThreadSafeClientConnManager(
    schemeRegistry);
  connMgr.setDefaultMaxPerRoute(100);

  DefaultHttpClient defaultClient = new DefaultHttpClient(connMgr);

  List<String> prefList = new ArrayList<>();
  if (authType == Authentication.BASIC)
    prefList.add(AuthPolicy.BASIC);
  else if (authType == Authentication.DIGEST)
    prefList.add(AuthPolicy.DIGEST);
  else
    throw new IllegalArgumentException("Unknown authentication type "+authType.name());

  defaultClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, prefList);

  defaultClient.getCredentialsProvider().setCredentials(
    new AuthScope(host, port),
    new UsernamePasswordCredentials(user, password)
  );

  setClient(defaultClient);
}