Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/AccessController/DoPrivAccompliceTest.java
38813 views
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"))) {
64
writer.write(policyFile.toString());
65
writer.close();
66
} catch (IOException e) {
67
System.err.println("Error while creating policy file");
68
throw e;
69
}
70
}
71
72
public static void main(String[] args) throws Exception {
73
final File class1 = new File(PWD, ACTION_SOURCE + ".class");
74
final File class2 = new File(PWD, TEST_SOURCE + ".class");
75
final File jarFile1 = new File(PWD, ACTION_SOURCE + ".jar");
76
final File jarFile2 = new File(PWD, TEST_SOURCE + ".jar");
77
System.out.println("Compilation successfull");
78
JavaToolUtils.createJar(jarFile1, Arrays.asList(new File[]{class1}));
79
System.out.println("Created jar file " + jarFile1);
80
JavaToolUtils.createJar(jarFile2, Arrays.asList(new File[]{class2}));
81
System.out.println("Created jar file " + jarFile2);
82
createPolicyFile(jarFile1.toURI());
83
84
List<String> commands = new ArrayList<>();
85
final String pathSepartor = System.getProperty("path.separator");
86
commands.add("-Djava.security.manager");
87
commands.add("-Djava.security.policy=" + PWD + "/java.policy");
88
commands.add("-classpath");
89
commands.add(PWD + "/" + TEST_SOURCE + ".jar" + pathSepartor
90
+ PWD + "/" + ACTION_SOURCE + ".jar");
91
commands.add(TEST_SOURCE);
92
if (JavaToolUtils.runJava(commands) == 0) {
93
System.out.println("Test PASSES");
94
}
95
}
96
97
}
98
99