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