com.sun.net.httpserver.BasicAuthenticator Java Examples
The following examples show how to use
com.sun.net.httpserver.BasicAuthenticator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthUT.java From NoraUi with GNU Affero General Public License v3.0 | 6 votes |
public void start() { try { server = HttpServer.create(new InetSocketAddress(8000), 0); } catch (final Exception e) { Assert.fail("Exception thrown: " + e.getMessage()); } server.createContext("/unprotected", new TestHttpHandler()); final HttpContext protectedContext = server.createContext("/protected", new TestHttpHandler()); protectedContext.setAuthenticator(new BasicAuthenticator("get") { @Override public boolean checkCredentials(String user, String pwd) { return user.equals("admin") && pwd.equals("admin"); } }); server.createContext("/cookieprotected", new CookieTestHttpHandler()); server.start(); }
Example #2
Source File: RestApiCallDemoClient.java From iotplatform with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(HTTP_SERVER_PORT), 0); HttpContext secureContext = server.createContext(DEMO_REST_BASIC_AUTH, new RestDemoHandler()); secureContext.setAuthenticator(new BasicAuthenticator("demo-auth") { @Override public boolean checkCredentials(String user, String pwd) { return user.equals(USERNAME) && pwd.equals(PASSWORD); } }); server.createContext(DEMO_REST_NO_AUTH, new RestDemoHandler()); server.setExecutor(null); System.out.println("[*] Waiting for messages."); server.start(); }
Example #3
Source File: TestHelper.java From ant-ivy with Apache License 2.0 | 5 votes |
/** * Creates a HTTP server, backed by a local file system, which can be used as a repository to * serve Ivy module descriptors and artifacts. The context within the server will be backed by * {@code BASIC} authentication mechanism with {@code realm} as the realm and * {@code validCredentials} as the credentials that the server will recognize. The server will * allow access to resources, only if the credentials that are provided by the request, belong * to these credentials. * <p> * NOTE: This is supposed to be used only in test cases and only a limited functionality is * added in the handler(s) backing the server * * @param serverAddress The address to which the server will be bound * @param webAppContext The context root of the application which will be handling * the requests to the server * @param localFilesystemRepoRoot The path to the root directory containing the module * descriptors and artifacts * @param realm The realm to use for the {@code BASIC} auth mechanism * @param validCredentials A {@link Map} of valid credentials, the key being the user * name and the value being the password, that the server will * use during the authentication process of the incoming requests * @return AutoCloseable * @throws IOException if something goes wrong */ public static AutoCloseable createBasicAuthHttpServerBackedRepo(final InetSocketAddress serverAddress, final String webAppContext, final Path localFilesystemRepoRoot, final String realm, final Map<String, String> validCredentials) throws IOException { final LocalFileRepoOverHttp handler = new LocalFileRepoOverHttp(webAppContext, localFilesystemRepoRoot); final HttpServer server = HttpServer.create(serverAddress, -1); // setup the handler final HttpContext context = server.createContext(webAppContext, handler); // setup basic auth on this context final com.sun.net.httpserver.Authenticator authenticator = new BasicAuthenticator(realm) { @Override public boolean checkCredentials(final String user, final String pass) { if (validCredentials == null || !validCredentials.containsKey(user)) { return false; } final String expectedPass = validCredentials.get(user); return expectedPass != null && expectedPass.equals(pass); } }; context.setAuthenticator(authenticator); // setup a auth filter backed by the authenticator context.getFilters().add(new AuthFilter(authenticator)); // start the server server.start(); return new AutoCloseable() { @Override public void close() throws Exception { final int delaySeconds = 0; server.stop(delaySeconds); } }; }
Example #4
Source File: BasicLongCredentials.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #5
Source File: Deadlock.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #6
Source File: BasicLongCredentials.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #7
Source File: Deadlock.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #8
Source File: BasicLongCredentials.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #9
Source File: BasicLongCredentials.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #10
Source File: Deadlock.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #11
Source File: BasicLongCredentials.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #12
Source File: Deadlock.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #13
Source File: BasicLongCredentials.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #14
Source File: Deadlock.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #15
Source File: BasicLongCredentials.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #16
Source File: Deadlock.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #17
Source File: JobEntryHTTP_PDI_18044_Test.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private static void startHTTPServer() throws IOException { httpServer = HttpServer.create( new InetSocketAddress( JobEntryHTTP_PDI208_Test.HTTP_HOST, JobEntryHTTP_PDI208_Test.HTTP_PORT ), 10 ); HttpContext uploadFileContext = httpServer.createContext( "/uploadFile", new JobEntryHTTP_PDI_18044_Test_Handler() ); //HttpContext getContext = httpServer.createContext( "/get", new GetHandler() ); uploadFileContext.setAuthenticator( new BasicAuthenticator( "uploadFile" ) { @Override public boolean checkCredentials( String username, String password ) { return username.equals( "admin" ) && password.equals( "password" ); } } ); httpServer.start(); }
Example #18
Source File: Deadlock.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #19
Source File: Deadlock.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #20
Source File: BasicLongCredentials.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #21
Source File: HTTPTestServer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static void setContextAuthenticator(HttpContext ctxt, HttpTestAuthenticator auth) { final String realm = auth.getRealm(); com.sun.net.httpserver.Authenticator authenticator = new BasicAuthenticator(realm) { @Override public boolean checkCredentials(String username, String pwd) { return auth.getUserName().equals(username) && new String(auth.getPassword(username)).equals(pwd); } }; ctxt.setAuthenticator(authenticator); }
Example #22
Source File: MultiAuthTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static HttpServer createServer(ExecutorService e, BasicAuthenticator sa) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 10); Handler h = new Handler(); HttpContext serverContext = server.createContext("/test", h); serverContext.setAuthenticator(sa); server.setExecutor(e); server.start(); return server; }
Example #23
Source File: Deadlock.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #24
Source File: BasicLongCredentials.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #25
Source File: Deadlock.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #26
Source File: BasicLongCredentials.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #27
Source File: Deadlock.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #28
Source File: BasicLongCredentials.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }
Example #29
Source File: Deadlock.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { Handler handler = new Handler(); InetSocketAddress addr = new InetSocketAddress (0); HttpServer server = HttpServer.create(addr, 0); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator("[email protected]") { @Override public boolean checkCredentials (String username, String pw) { return "fred".equals(username) && pw.charAt(0) == 'x'; } }; ctx.setAuthenticator(a); ExecutorService executor = Executors.newCachedThreadPool(); server.setExecutor(executor); server.start (); java.net.Authenticator.setDefault(new MyAuthenticator()); System.out.print("Deadlock: " ); for (int i=0; i<2; i++) { Runner t = new Runner(server, i); t.start(); t.join(); } server.stop(2); executor.shutdown(); if (error) { throw new RuntimeException("test failed error"); } if (count != 2) { throw new RuntimeException("test failed count = " + count); } System.out.println("OK"); }
Example #30
Source File: BasicLongCredentials.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main (String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(0), 0); try { Handler handler = new Handler(); HttpContext ctx = server.createContext("/test", handler); BasicAuthenticator a = new BasicAuthenticator(REALM) { public boolean checkCredentials (String username, String pw) { return USERNAME.equals(username) && PASSWORD.equals(pw); } }; ctx.setAuthenticator(a); server.start(); Authenticator.setDefault(new MyAuthenticator()); URL url = new URL("http://localhost:"+server.getAddress().getPort()+"/test/"); HttpURLConnection urlc = (HttpURLConnection)url.openConnection(); InputStream is = urlc.getInputStream(); int c = 0; while (is.read()!= -1) { c ++; } if (c != 0) { throw new RuntimeException("Test failed c = " + c); } if (error) { throw new RuntimeException("Test failed: error"); } System.out.println ("OK"); } finally { server.stop(0); } }