List of usage examples for org.apache.http.impl.client AbstractHttpClient getAuthSchemes
public synchronized final AuthSchemeRegistry getAuthSchemes()
From source file:nl.esciencecenter.octopus.webservice.JobLauncherService.java
/** * Adds MAC Access Authentication scheme to http client and registers list of MAC credentials with http client. * * Http client will use MAC Access Authentication when url is in scope of given MAC credentials. * * @param httpClient//from w w w. ja v a 2s . c o m * @param macs * @return httpClient with MAC access authentication and credentials injected. */ public static AbstractHttpClient macifyHttpClient(AbstractHttpClient httpClient, ImmutableList<MacCredential> macs) { // Add MAC scheme httpClient.getAuthSchemes().register(MacScheme.SCHEME_NAME, new MacSchemeFactory()); // Add configured MAC id/key pairs. CredentialsProvider credentialProvider = httpClient.getCredentialsProvider(); for (MacCredential mac : macs) { credentialProvider.setCredentials(mac.getAuthScope(), mac); } // Add MAC scheme to ordered list of supported authentication schemes // See HTTP authentication parameters chapter on // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html List<String> authSchemes = Collections.unmodifiableList(Arrays.asList(new String[] { MacScheme.SCHEME_NAME, AuthPolicy.SPNEGO, AuthPolicy.KERBEROS, AuthPolicy.NTLM, AuthPolicy.DIGEST, AuthPolicy.BASIC })); httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authSchemes); return httpClient; }
From source file:net.adamcin.httpsig.http.apache4.Http4Util.java
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) { if (client == null) { throw new NullPointerException("client"); }//from w w w .j a v a 2 s .c o m 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); }
From source file:org.apache.solr.client.solrj.impl.HttpClientUtilTest.java
@Test public void testAuthSchemeConfiguration() { System.setProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP, "test"); try {/*from w w w . j a v a2 s . c o m*/ HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); AbstractHttpClient client = (AbstractHttpClient) HttpClientUtil.createClient(null); assertEquals(1, client.getAuthSchemes().getSchemeNames().size()); assertTrue(AuthSchemes.SPNEGO.equalsIgnoreCase(client.getAuthSchemes().getSchemeNames().get(0))); } finally { //Cleanup the system property. System.clearProperty(Krb5HttpClientConfigurer.LOGIN_CONFIG_PROP); } }
From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.java
protected void setAuthenticationInfo(AbstractHttpClient agent, MessageContext msgCtx) throws AxisFault { HTTPAuthenticator authenticator;//from www . ja va2 s . c om Object obj = msgCtx.getProperty(HTTPConstants.AUTHENTICATE); if (obj != null) { if (obj instanceof HTTPAuthenticator) { authenticator = (HTTPAuthenticator) obj; String username = authenticator.getUsername(); String password = authenticator.getPassword(); String host = authenticator.getHost(); String domain = authenticator.getDomain(); int port = authenticator.getPort(); String realm = authenticator.getRealm(); /* If retrying is available set it first */ isAllowedRetry = authenticator.isAllowedRetry(); Credentials creds; // TODO : Set preemptive authentication, but its not recommended in HC 4 if (host != null) { if (domain != null) { /* Credentials for NTLM Authentication */ agent.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); creds = new NTCredentials(username, password, host, domain); } else { /* Credentials for Digest and Basic Authentication */ creds = new UsernamePasswordCredentials(username, password); } agent.getCredentialsProvider().setCredentials(new AuthScope(host, port, realm), creds); } else { if (domain != null) { /* * Credentials for NTLM Authentication when host is * ANY_HOST */ agent.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); creds = new NTCredentials(username, password, AuthScope.ANY_HOST, domain); agent.getCredentialsProvider() .setCredentials(new AuthScope(AuthScope.ANY_HOST, port, realm), creds); } else { /* Credentials only for Digest and Basic Authentication */ creds = new UsernamePasswordCredentials(username, password); agent.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), creds); } } /* Customizing the priority Order */ List schemes = authenticator.getAuthSchemes(); if (schemes != null && schemes.size() > 0) { List authPrefs = new ArrayList(3); for (int i = 0; i < schemes.size(); i++) { if (schemes.get(i) instanceof AuthPolicy) { authPrefs.add(schemes.get(i)); continue; } String scheme = (String) schemes.get(i); authPrefs.add(authenticator.getAuthPolicyPref(scheme)); } agent.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authPrefs); } } else { throw new AxisFault("HttpTransportProperties.Authenticator class cast exception"); } } }