List of usage examples for org.apache.http.auth AuthSchemeFactory AuthSchemeFactory
AuthSchemeFactory
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 ww . j av a2 s. com 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:com.anaplan.client.transport.ApacheHttpProvider.java
protected ApacheHttpProvider() { super();/*from ww w . jav a 2 s .c o m*/ httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, Boolean.TRUE); httpClient.setCredentialsProvider(new ApacheCredentialsProvider()); try { Class<?> engineClass = Class.forName("com.anaplan.client.transport.JCIFSEngine"); final NTLMEngine ntlmEngine = (NTLMEngine) engineClass.newInstance(); httpClient.getAuthSchemes().register("ntlm", new AuthSchemeFactory() { public AuthScheme newInstance(final HttpParams params) { return new NTLMScheme(ntlmEngine); } }); } catch (InstantiationException instantiationException) { // Normal - the jcifs jar file is not present in the lib folder. } catch (Throwable thrown) { // Abnormal thrown.printStackTrace(); } routePlanner = new ProxySelectorRoutePlanner(httpClient.getConnectionManager().getSchemeRegistry(), getProxySelector()) { private boolean suppressed; @Override public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { HttpRoute httpRoute = super.determineRoute(target, request, context); if (getDebugLevel() >= 1 && !suppressed) { System.err.println( httpRoute.toString() + " (" + getProxySelector().getClass().getSimpleName() + ")"); if (getDebugLevel() == 1) suppressed = true; } return httpRoute; } }; httpClient.setRoutePlanner(routePlanner); }