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/Policy/Dynamic/DynamicPolicy.java
38828 views
1
/*
2
* Copyright (c) 2000, 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.security.*;
25
import java.util.PropertyPermission;
26
import java.net.SocketPermission;
27
import java.lang.*;
28
29
public class DynamicPolicy extends Policy{
30
31
static int refresher = 0;
32
33
34
public DynamicPolicy() {
35
}
36
37
public PermissionCollection getPermissions(CodeSource cs) {
38
39
Permissions perms = new Permissions();
40
initStaticPolicy(perms);
41
// Defalut policy in the beginning...
42
// toggle from refresh to refresh
43
if (refresher == 1)
44
perms.add(new PropertyPermission("user.name","read"));
45
46
System.err.println("perms=[" + perms + "]");
47
return perms;
48
}
49
50
public boolean implies(ProtectionDomain pd, Permission p) {
51
return getPermissions(pd).implies(p);
52
}
53
54
public PermissionCollection getPermissions(ProtectionDomain pd) {
55
56
Permissions perms = new Permissions();
57
initStaticPolicy(perms);
58
// Defalut policy in the beginning...
59
// toggle from refresh to refresh
60
if (refresher == 1)
61
perms.add(new PropertyPermission("user.name","read"));
62
63
return perms;
64
}
65
66
public void refresh() {
67
refresher++;
68
}
69
70
private void initStaticPolicy(PermissionCollection perms) {
71
72
perms.add(new java.security.SecurityPermission("getPolicy"));
73
perms.add(new java.security.SecurityPermission("setPolicy"));
74
perms.add(new java.lang.RuntimePermission("stopThread"));
75
perms.add(new java.net.SocketPermission("localhost:1024-", "listen"));
76
perms.add(new PropertyPermission("java.version","read"));
77
perms.add(new PropertyPermission("java.vendor","read"));
78
perms.add(new PropertyPermission("java.vendor.url","read"));
79
perms.add(new PropertyPermission("java.class.version","read"));
80
perms.add(new PropertyPermission("os.name","read"));
81
perms.add(new PropertyPermission("os.version","read"));
82
perms.add(new PropertyPermission("os.arch","read"));
83
perms.add(new PropertyPermission("file.separator","read"));
84
perms.add(new PropertyPermission("path.separator","read"));
85
perms.add(new PropertyPermission("line.separator","read"));
86
perms.add(new PropertyPermission("java.specification.version", "read"));
87
perms.add(new PropertyPermission("java.specification.vendor", "read"));
88
perms.add(new PropertyPermission("java.specification.name", "read"));
89
perms.add(new PropertyPermission("java.vm.specification.version", "read"));
90
perms.add(new PropertyPermission("java.vm.specification.vendor", "read"));
91
perms.add(new PropertyPermission("java.vm.specification.name", "read"));
92
perms.add(new PropertyPermission("java.vm.version", "read"));
93
perms.add(new PropertyPermission("java.vm.vendor", "read"));
94
perms.add(new PropertyPermission("java.vm.name", "read"));
95
return;
96
}
97
}
98
99