Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Policy/ExtensiblePolicy/ExtensiblePolicyWithJarTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 2019, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import TVJar.TVPermission;
25
import java.io.File;
26
import java.nio.file.Files;
27
import java.nio.file.Paths;
28
import java.security.AccessController;
29
import jdk.test.lib.process.ProcessTools;
30
import jdk.test.lib.util.JarUtils;
31
32
/**
33
* @test
34
* @bug 8050402
35
* @summary Check policy is extensible with user defined permissions
36
* @library /test/lib
37
* @build jdk.test.lib.util.JarUtils
38
* @compile TVJar/TVPermission.java
39
* @run main ExtensiblePolicyWithJarTest
40
*/
41
public class ExtensiblePolicyWithJarTest {
42
43
public static void main(String args[]) throws Throwable {
44
final String FS = File.separator;
45
final String PS = File.pathSeparator;
46
final String POL = "ExtensiblePolicyTest3.policy";
47
final String JAVA_HOME = System.getProperty("test.jdk");
48
final String KEYTOOL = JAVA_HOME + FS + "bin" + FS + "keytool";
49
final String JARSIGNER = JAVA_HOME + FS + "bin" + FS + "jarsigner";
50
final String KEYSTORE = "epkeystore";
51
final String PASSWORD = "password";
52
final String ALIAS = "duke2";
53
final String CLASSPATH = System.getProperty("test.class.path", "");
54
final String TESTCLASSES = System.getProperty("test.classes", "");
55
final String TVPERMJAR = "tvPerm.jar";
56
final String PATHTOJAR = System.getProperty("user.dir", "")
57
+ FS + TVPERMJAR;
58
59
// create jar file for TVpermission
60
new File("TVJar").mkdir();
61
Files.copy(Paths.get(TESTCLASSES + FS + "TVJar", "TVPermission.class"),
62
Paths.get("TVJar", "TVPermission.class"));
63
Files.copy(Paths.get(TESTCLASSES + FS + "TVJar",
64
"TVPermissionCollection.class"),
65
Paths.get("TVJar", "TVPermissionCollection.class"));
66
JarUtils.createJar(TVPERMJAR, "TVJar/TVPermission.class",
67
"TVJar/TVPermissionCollection.class");
68
69
// create key pair for jar signing
70
ProcessTools.executeCommand(KEYTOOL,
71
"-genkey",
72
"-keyalg", "DSA",
73
"-alias", ALIAS,
74
"-keystore", KEYSTORE,
75
"-storetype", "JKS",
76
"-keypass", PASSWORD,
77
"-dname", "cn=Blah",
78
"-storepass", PASSWORD
79
).shouldHaveExitValue(0);
80
// sign jar
81
ProcessTools.executeCommand(JARSIGNER,
82
"-keystore", KEYSTORE,
83
"-storepass", PASSWORD,
84
"-keypass", PASSWORD,
85
TVPERMJAR,
86
ALIAS).shouldHaveExitValue(0);
87
// add jar file to classpath
88
String cp = PATHTOJAR + PS + CLASSPATH;
89
90
// policy file grants permission signed by duke2 to watch TVChanel 5
91
try {
92
String[] cmd = {
93
"-classpath", cp,
94
"-Djava.security.manager",
95
"-Djava.security.policy=" + POL,
96
"ExtensiblePolicyTest_orig$TestMain"};
97
ProcessTools.executeTestJvm(cmd).shouldHaveExitValue(0);
98
} catch (Exception ex) {
99
System.out.println("ExtensiblePolicyWithJarTest Failed");
100
}
101
102
}
103
104
public static class TestMain {
105
public static void main(String args[]) {
106
TVPermission perm = new TVPermission("channel:5", "watch");
107
try {
108
AccessController.checkPermission(perm);
109
} catch (SecurityException se) {
110
throw new RuntimeException(se);
111
}
112
}
113
}
114
115
}
116
117