1 /* 2 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 import java.io.File; 27 import java.io.FileWriter; 28 import java.io.IOException; 29 import java.net.URI; 30 import java.util.ArrayList; 31 import java.util.Arrays; 32 import java.util.List; 33 34 /** 35 * @test 36 * @bug 8048362 37 * @compile ../../../lib/testlibrary/JavaToolUtils.java 38 * DoPrivAccomplice.java DoPrivTest.java 39 * @summary Tests the doPrivileged with accomplice Generate two jars 40 * (DoPrivTest.jar and DoPrivAccomplice.jar) and grant permission to 41 * DoPrivAccmplice.jar for reading user.home property from a PrivilagedAction. 42 * Run DoPrivTest.jar and try to access user.home property using 43 * DoPrivAccmplice.jar. 44 * @run main/othervm DoPrivAccompliceTest 45 */ 46 47 public class DoPrivAccompliceTest { 48 49 private static final String PWD = System.getProperty("test.classes", "./"); 50 private static final String ACTION_SOURCE = "DoPrivAccomplice"; 51 private static final String TEST_SOURCE = "DoPrivTest"; 52 53 public static void createPolicyFile(URI codebaseURL) throws IOException { 54 String codebase = codebaseURL.toString(); 55 String quotes = "\""; 56 StringBuilder policyFile = new StringBuilder(); 57 policyFile.append("grant codeBase ").append(quotes). 58 append(codebase).append(quotes).append("{\n"). 59 append("permission java.util.PropertyPermission "). 60 append(quotes).append("user.name").append(quotes). 61 append(",").append(quotes).append("read").append(quotes). 62 append(";\n};"); 63 try (FileWriter writer = new FileWriter(new File(PWD, "java.policy"))) { | 1 /* 2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 import java.io.File; 27 import java.io.FileWriter; 28 import java.io.IOException; 29 import java.net.URI; 30 import java.util.ArrayList; 31 import java.util.Arrays; 32 import java.util.List; 33 34 /* 35 * @test 36 * @bug 8048362 37 * @compile ../../../lib/testlibrary/JavaToolUtils.java 38 * DoPrivAccomplice.java DoPrivTest.java 39 * @summary Tests the doPrivileged with accomplice Generate two jars 40 * (DoPrivTest.jar and DoPrivAccomplice.jar) and grant permission to 41 * DoPrivAccmplice.jar for reading user.home property from a PrivilagedAction. 42 * Run DoPrivTest.jar and try to access user.home property using 43 * DoPrivAccmplice.jar. 44 * @modules jdk.compiler 45 * @run main/othervm DoPrivAccompliceTest 46 */ 47 48 public class DoPrivAccompliceTest { 49 50 private static final String PWD = System.getProperty("test.classes", "./"); 51 private static final String ACTION_SOURCE = "DoPrivAccomplice"; 52 private static final String TEST_SOURCE = "DoPrivTest"; 53 54 public static void createPolicyFile(URI codebaseURL) throws IOException { 55 String codebase = codebaseURL.toString(); 56 String quotes = "\""; 57 StringBuilder policyFile = new StringBuilder(); 58 policyFile.append("grant codeBase ").append(quotes). 59 append(codebase).append(quotes).append("{\n"). 60 append("permission java.util.PropertyPermission "). 61 append(quotes).append("user.name").append(quotes). 62 append(",").append(quotes).append("read").append(quotes). 63 append(";\n};"); 64 try (FileWriter writer = new FileWriter(new File(PWD, "java.policy"))) { |