org.apache.http.client.params.AuthPolicy Java Examples

The following examples show how to use org.apache.http.client.params.AuthPolicy. 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: AuthenticatorTestCase.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
 
Example #2
Source File: AuthenticatorTestCase.java    From big-c with Apache License 2.0 6 votes vote down vote up
private SystemDefaultHttpClient getHttpClient() {
  final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
  httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
   Credentials use_jaas_creds = new Credentials() {
     public String getPassword() {
       return null;
     }

     public Principal getUserPrincipal() {
       return null;
     }
   };

   httpClient.getCredentialsProvider().setCredentials(
     AuthScope.ANY, use_jaas_creds);
   return httpClient;
}
 
Example #3
Source File: AuthenticatorTestCase.java    From registry with Apache License 2.0 6 votes vote down vote up
private SystemDefaultHttpClient getHttpClient() {
    final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
    httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
    Credentials use_jaas_creds = new Credentials() {
        public String getPassword() {
            return null;
        }

        public Principal getUserPrincipal() {
            return null;
        }
    };

    httpClient.getCredentialsProvider().setCredentials(
            AuthScope.ANY, use_jaas_creds);
    return httpClient;
}
 
Example #4
Source File: HttpClientConfigurer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
    Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);

    NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
    Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);

    LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}
 
Example #5
Source File: HttpClientConfigurer.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
    Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);

    NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
    Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);

    LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}
 
Example #6
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 #7
Source File: HttpClientConfigurer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
    Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);

    NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
    Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);

    LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}
 
Example #8
Source File: HttpClientConfigurer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
    Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);

    NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
    Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);

    LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}
 
Example #9
Source File: WebdavClientImpl.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
private WebdavClientImpl(String username, String password, ProxyConfiguration proxyConfiguration) {
	super(username, password, proxyConfiguration.getProxySelector());
	
	// prefer basic authentication, as NTLM does not seem to work
	// FIXME deprecated since 4.2, but ProxyAuthenticationStrategy does not support default scheme priority overriding
	client.setProxyAuthenticationHandler(new DefaultProxyAuthenticationHandler() {

		@Override
		protected List<String> getAuthPreferences(HttpResponse response, HttpContext context) {
        	return Arrays.asList(
        			AuthPolicy.BASIC,
        			AuthPolicy.DIGEST,
        			AuthPolicy.SPNEGO,
        			AuthPolicy.NTLM);
		}
           
       });
	
	if (proxyConfiguration.isProxyUsed()) {
		UserInfo userInfo = proxyConfiguration.getUserInfo();
		if (!userInfo.isEmpty()) {
			HttpHost proxyHost = new HttpHost(proxyConfiguration.getHost(), proxyConfiguration.getPort());
			client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost);
			setProxyCredentials(client, proxyHost.getHostName(), proxyHost.getPort(), userInfo.getUserInfo());
		}
	}
}
 
Example #10
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);
}