Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Policy/PolicyProvider/UseSystemClassLoader.java
41153 views
1
/*
2
* Copyright (c) 2015, 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 java.io.File;
25
import java.net.URL;
26
import java.security.Policy;
27
import java.security.Security;
28
29
/*
30
* @test
31
* @bug 8075706
32
* @summary Check that a custom policy provider can be loaded from the classpath
33
* @modules java.base/sun.security.provider
34
* @run main/othervm -Djava.security.manager=allow UseSystemClassLoader CUSTOM
35
* @run main/othervm -Djava.security.manager=allow UseSystemClassLoader DEFAULT
36
* @run main/othervm -Djava.security.manager=allow UseSystemClassLoader NOT_AVAIL
37
* @run main/othervm -Djava.security.manager=allow UseSystemClassLoader NOT_SET
38
*/
39
40
public class UseSystemClassLoader {
41
42
enum Type {
43
CUSTOM, DEFAULT, NOT_AVAIL, NOT_SET
44
};
45
46
public static void main(String[] args) throws Exception {
47
48
Type t = Type.valueOf(args[0]);
49
50
// We can't use the jtreg java.security.policy option to specify
51
// the policy file because that causes the default JDK policy provider
52
// to be set and once set, we cannot change it. So, instead we use the
53
// policy.url security property.
54
File file = new File(System.getProperty("test.src"), "test.policy");
55
URL policyURL = file.toURI().toURL();
56
Security.setProperty("policy.url.1", policyURL.toString());
57
58
switch (t) {
59
case CUSTOM:
60
// Set policy.provider to our custom policy provider
61
Security.setProperty("policy.provider", "CustomPolicy");
62
break;
63
case NOT_AVAIL:
64
// Set policy.provider to a non-existent policy provider
65
Security.setProperty("policy.provider", "NonExistentPolicy");
66
break;
67
case DEFAULT:
68
// Don't set policy.provider (leave default)
69
break;
70
case NOT_SET:
71
// Set policy.provider to empty string
72
Security.setProperty("policy.provider", "");
73
break;
74
}
75
76
System.setSecurityManager(new SecurityManager());
77
Policy p = Policy.getPolicy();
78
switch (t) {
79
case CUSTOM:
80
// check that the custom policy provider has been set
81
if (!(p instanceof CustomPolicy)) {
82
throw new Exception("CustomPolicy was not set");
83
}
84
break;
85
case NOT_AVAIL:
86
case DEFAULT:
87
case NOT_SET:
88
// check that the default policy provider has been set
89
if (!(p instanceof sun.security.provider.PolicyFile)) {
90
throw new Exception("default provider was not set");
91
}
92
break;
93
}
94
}
95
}
96
97