public static void main(String[] args) throws Exception { // assume NTLM is not supported when Kerberos is not available try { Class.forName("javax.security.auth.kerberos.KerberosPrincipal"); System.out.println("Kerberos is present, assuming NTLM is supported too"); return; } catch (ClassNotFoundException okay) { } // setup Authenticator Authenticator.setDefault( new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("user", "pass".toCharArray()); } }); // test combinations of authentication schemes test("Basic"); test("Digest"); test("Basic", "Digest"); test("Basic", "NTLM"); test("Digest", "NTLM"); test("Basic", "Digest", "NTLM"); // test NTLM only, this should fail with "401 Unauthorized" testNTLM(); System.out.println(); System.out.println("TEST PASSED"); }
public static void main(String[] args) throws Exception { MyAuthenticator auth = new MyAuthenticator(); Authenticator.setDefault(auth); try { server = new HttpServer(new AuthHeaderTest(), 1, 10, 0); System.out.println("Server: listening on port: " + server.getLocalPort()); client("http://localhost:" + server.getLocalPort() + "/d1/foo.html"); } catch (Exception e) { if (server != null) { server.terminate(); } throw e; } int f = auth.getCount(); if (f != 1) { except("Authenticator was called " + f + " times. Should be 1"); } server.terminate(); }
private void configureProxyAuthentication() { if (System.getProperty("http.proxyUser") != null) { Authenticator.setDefault(new SystemPropertiesProxyAuthenticator()); } }