Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/provider/PolicyFile/DefaultPolicy.java
41153 views
1
/*
2
* Copyright (c) 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.
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
/*
25
* @test
26
* @bug 8159752
27
* @summary Test that default policy permissions are always granted
28
* @run main/othervm DefaultPolicy
29
*/
30
31
import java.net.URI;
32
import java.net.URL;
33
import java.nio.file.Paths;
34
import java.security.AllPermission;
35
import java.security.CodeSigner;
36
import java.security.CodeSource;
37
import java.security.Policy;
38
import java.security.ProtectionDomain;
39
import java.security.URIParameter;
40
41
public class DefaultPolicy {
42
43
public static void main(String[] args) throws Exception {
44
45
// Check policy with no java.security.policy property set
46
Policy p = Policy.getPolicy();
47
checkPolicy(p);
48
49
// Check policy with java.security.policy '=' option
50
System.setProperty("java.security.policy", "Extra.policy");
51
p.refresh();
52
checkPolicy(p);
53
54
// Check policy with java.security.policy override '==' option
55
System.setProperty("java.security.policy", "=Extra.policy");
56
p.refresh();
57
checkPolicy(p);
58
59
// Check Policy.getInstance
60
URI policyURI = Paths.get(System.getProperty("test.src"),
61
"Extra.policy").toUri();
62
p = Policy.getInstance("JavaPolicy", new URIParameter(policyURI));
63
checkPolicy(p);
64
}
65
66
private static void checkPolicy(Policy p) throws Exception {
67
// check if jdk.crypto.ec module has been de-privileged
68
CodeSource cs =
69
new CodeSource(new URL("jrt:/jdk.crypto.ec"), (CodeSigner[])null);
70
ProtectionDomain pd = new ProtectionDomain(cs, null, null, null);
71
if (p.implies(pd, new AllPermission())) {
72
throw new Exception("module should not be granted AllPermission");
73
}
74
if (!p.implies(pd, new RuntimePermission("loadLibrary.sunec"))) {
75
throw new Exception("module should be granted RuntimePermission");
76
}
77
}
78
}
79
80