Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/System/SecurityManagerWarnings.java
41149 views
1
/*
2
* Copyright (c) 2021, 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 8266459
27
* @summary check various warnings
28
* @library /test/lib
29
*/
30
31
import jdk.test.lib.process.OutputAnalyzer;
32
import jdk.test.lib.process.ProcessTools;
33
34
import java.security.Permission;
35
36
public class SecurityManagerWarnings {
37
public static void main(String args[]) throws Exception {
38
if (args.length == 0) {
39
run(null)
40
.shouldHaveExitValue(0)
41
.shouldContain("SM is enabled: false")
42
.shouldNotContain("Security Manager is deprecated")
43
.shouldContain("setSecurityManager is deprecated");
44
run("allow")
45
.shouldHaveExitValue(0)
46
.shouldContain("SM is enabled: false")
47
.shouldNotContain("Security Manager is deprecated")
48
.shouldContain("setSecurityManager is deprecated");
49
run("disallow")
50
.shouldNotHaveExitValue(0)
51
.shouldContain("SM is enabled: false")
52
.shouldNotContain("Security Manager is deprecated")
53
.shouldContain("UnsupportedOperationException");
54
run("SecurityManagerWarnings$MySM")
55
.shouldHaveExitValue(0)
56
.shouldContain("SM is enabled: true")
57
.shouldContain("Security Manager is deprecated")
58
.shouldContain("setSecurityManager is deprecated");
59
run("")
60
.shouldNotHaveExitValue(0)
61
.shouldContain("SM is enabled: true")
62
.shouldContain("Security Manager is deprecated")
63
.shouldContain("AccessControlException");
64
run("default")
65
.shouldNotHaveExitValue(0)
66
.shouldContain("SM is enabled: true")
67
.shouldContain("Security Manager is deprecated")
68
.shouldContain("AccessControlException");
69
} else {
70
System.out.println("SM is enabled: " + (System.getSecurityManager() != null));
71
System.setSecurityManager(new SecurityManager());
72
}
73
}
74
75
static OutputAnalyzer run(String prop) throws Exception {
76
if (prop == null) {
77
return ProcessTools.executeTestJvm(
78
"SecurityManagerWarnings", "run");
79
} else {
80
return ProcessTools.executeTestJvm(
81
"-Djava.security.manager=" + prop,
82
"SecurityManagerWarnings", "run");
83
}
84
}
85
86
// This SecurityManager allows everything!
87
public static class MySM extends SecurityManager {
88
@Override
89
public void checkPermission(Permission perm) {
90
}
91
}
92
}
93
94