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); }
@Override public AuthSchemeFactory getPreemptiveAuthSchemeFactory() { // anonymous authentication doesn't support preemptive authentication return null; }
@Override public AuthSchemeFactory getPreemptiveAuthSchemeFactory() { return BASIC_SCHEME_FACTORY; }
/** * Get an AuthSchemeFactory for {@link AuthScheme}s that can be used to authenticate preemptively. * * @return An {@link AuthSchemeFactory} or <code>null</code> if this scheme doesn't support preemptive authentication. */ public AuthSchemeFactory getPreemptiveAuthSchemeFactory();