< prev index next >

test/jdk/java/net/httpclient/security/Security.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 80,90 **** import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; - import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.ExecutorService; import java.util.concurrent.Flow; import java.util.logging.ConsoleHandler; import java.util.logging.Level; --- 80,89 ----
*** 295,313 **** HttpResponse.BodyHandler<String> sth = asString(); CompletableFuture<HttpResponse<String>> cf = client.sendAsync(request, new HttpResponse.BodyHandler<String>() { @Override ! public HttpResponse.BodyProcessor<String> apply(int status, HttpHeaders responseHeaders) { ! final HttpResponse.BodyProcessor<String> stproc = sth.apply(status, responseHeaders); ! return new HttpResponse.BodyProcessor<String>() { @Override public CompletionStage<String> getBody() { return stproc.getBody(); } @Override ! public void onNext(ByteBuffer item) { SecurityManager sm = System.getSecurityManager(); // should succeed. sm.checkPermission(new RuntimePermission("foobar")); // do some mischief here System.setSecurityManager(null); --- 294,312 ---- HttpResponse.BodyHandler<String> sth = asString(); CompletableFuture<HttpResponse<String>> cf = client.sendAsync(request, new HttpResponse.BodyHandler<String>() { @Override ! public HttpResponse.BodySubscriber<String> apply(int status, HttpHeaders responseHeaders) { ! final HttpResponse.BodySubscriber<String> stproc = sth.apply(status, responseHeaders); ! return new HttpResponse.BodySubscriber<String>() { @Override public CompletionStage<String> getBody() { return stproc.getBody(); } @Override ! public void onNext(List<ByteBuffer> item) { SecurityManager sm = System.getSecurityManager(); // should succeed. sm.checkPermission(new RuntimePermission("foobar")); // do some mischief here System.setSecurityManager(null);
*** 335,344 **** --- 334,346 ---- cf.join(); } catch (CompletionException e) { Throwable t = e.getCause(); if (t instanceof SecurityException) throw (SecurityException)t; + else if ((t instanceof IOException) + && (t.getCause() instanceof SecurityException)) + throw ((SecurityException)t.getCause()); else throw new RuntimeException(t); } }) };
*** 377,387 **** System.out.println("Using policy file: " + policy); try { r.execute(); if (!succeeds) { System.out.println("FAILED: expected security exception"); ! throw new RuntimeException("Failed"); } System.out.println (policy + " succeeded as expected"); } catch (BindException e) { System.exit(10); } catch (SecurityException e) { --- 379,389 ---- System.out.println("Using policy file: " + policy); try { r.execute(); if (!succeeds) { System.out.println("FAILED: expected security exception"); ! throw new RuntimeException("FAILED: expected security exception\""); } System.out.println (policy + " succeeded as expected"); } catch (BindException e) { System.exit(10); } catch (SecurityException e) {
*** 417,432 **** TestAndResult tr = tests[testnum]; runtest(tr.test, policy, tr.result); } finally { s1.stop(0); executor.shutdownNow(); - for (HttpClient client : clients) { - Executor e = client.executor(); - if (e instanceof ExecutorService) { - ((ExecutorService)e).shutdownNow(); - } - } } } public static void initServer() throws Exception { String portstring = System.getProperty("port.number"); --- 419,428 ----
< prev index next >