@Test public void testLogin() { TestBody.test(new HttpServerTestBody() { @Override protected void execute() throws Exception { List<String> headers = Arrays.asList( Constants.HEADER_REQUEST_TARGET, Constants.HEADER_DATE); setServlet(new AdminServlet(headers)); KeyPair keyPair = KeyTestUtil.getKeyPairFromProperties("b2048", "id_rsa"); DefaultKeychain provider = new DefaultKeychain(); provider.add(new SSHKey(KeyFormat.SSH_RSA, keyPair)); DefaultHttpClient client = new DefaultHttpClient(); Http4Util.enableAuth(client, provider, getKeyId()); HttpUriRequest request = new HttpGet(getAbsoluteUrl(TEST_URL)); HttpResponse response = client.execute(request); assertEquals("should return 200", 200, response.getStatusLine().getStatusCode()); } }); }
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); }
Http4Util { 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); } }
Http4Util { 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); } private  Http4Util(); }
Http4Util { 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); } private  Http4Util(); static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId); }
Http4Util { 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); } private  Http4Util(); static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId);  }