Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/PermissionCollection/Concurrent.java
41149 views
1
/*
2
* Copyright (c) 2003, 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 4671598
27
* @summary PermissionCollection is not properly synchronized
28
*/
29
30
import java.security.*; // AllPermission, BasicPermission, Permissions
31
import java.net.NetPermission;
32
import java.net.SocketPermission;
33
import java.io.FilePermission;
34
import java.util.PropertyPermission;
35
import javax.security.auth.AuthPermission;
36
import javax.security.auth.kerberos.DelegationPermission;
37
import javax.security.auth.kerberos.ServicePermission;
38
import javax.management.MBeanServerPermission;
39
40
import java.util.*;
41
42
public class Concurrent {
43
private static final int LIMIT1 = 2000;
44
private static final int LIMIT2 = 1000;
45
private static final boolean debug = false;
46
private static final Map errors =
47
Collections.synchronizedMap(new HashMap());
48
49
public static void main(String args[]) throws Exception {
50
testPc(allp);
51
testPc(filep);
52
testPc(sockp);
53
testPc(propp);
54
testPc(basicp);
55
testPc(delegatep);
56
testPc(servicep);
57
testPc(mbeanp);
58
testPc(unresp);
59
60
testPerms();
61
62
if (errors.size() > 0) {
63
if (true) {
64
Iterator iter = errors.entrySet().iterator();
65
while (iter.hasNext()) {
66
System.out.println(iter.next());
67
}
68
};
69
throw (Exception) new Exception("Got errors");
70
}
71
}
72
73
private static void testPc (final Permission[] perm) throws Exception {
74
75
final PermissionCollection pc = perm[0].newPermissionCollection();
76
77
new Thread() {
78
{
79
setDaemon(true);
80
start();
81
}
82
public void run() {
83
try {
84
for (int i = 0; i < LIMIT1; i++) {
85
for (int j = 0; j < perm.length; j++) {
86
pc.add(perm[j]);
87
if (debug) {
88
System.out.println("added " + perm[j]);
89
}
90
}
91
}
92
} catch (Exception e) {
93
errors.put(perm[0].getClass().getName(), e);
94
}
95
}
96
};
97
try {
98
for (int i = 0; i < LIMIT2; i++) {
99
boolean result = pc.implies(perm[perm.length-1]);
100
if (debug) {
101
System.out.println(perm[perm.length-1] + " implies " + result);
102
}
103
104
Enumeration en = pc.elements();
105
while (en.hasMoreElements()) {
106
Object obj = en.nextElement();
107
if (debug) {
108
System.out.println(obj);
109
}
110
}
111
}
112
} catch (Exception e) {
113
errors.put(perm[0].getClass().getName(), e);
114
}
115
}
116
117
private static void testPerms () throws Exception {
118
119
final Permissions pc = new Permissions();
120
121
new Thread() {
122
{
123
setDaemon(true);
124
start();
125
}
126
public void run() {
127
try {
128
for (int i = 0; i < LIMIT1; i++) {
129
for (int j = 0; j < permlist.length; j++) {
130
for (int k = 0; k < permlist[j].length; k++) {
131
pc.add(permlist[j][k]);
132
}
133
}
134
}
135
} catch (Exception e) {
136
errors.put("java.security.Permissions", e);
137
}
138
}
139
};
140
try {
141
for (int i = 0; i < LIMIT2; i++) {
142
for (int j = 0; j < permlist.length; j++) {
143
boolean result = pc.implies(permlist[j][0]);
144
if (debug) {
145
System.out.println(permlist[j][0] + " implies " + result);
146
}
147
}
148
149
Enumeration en = pc.elements();
150
while (en.hasMoreElements()) {
151
Object obj = en.nextElement();
152
if (debug) {
153
System.out.println(obj);
154
}
155
}
156
}
157
} catch (Exception e) {
158
errors.put("java.security.Permissions", e);
159
}
160
}
161
162
private static final Permission[] allp = new Permission[]{
163
new AllPermission(), new AllPermission()};
164
165
private static final Permission[] filep = new Permission[]{
166
new FilePermission("/tmp/foobar", "read"),
167
new FilePermission("/tmp/foo", "write"),
168
new FilePermission("/tmp/foobar", "read,write"),
169
};
170
171
private static final Permission[] sockp = new Permission[]{
172
new SocketPermission("example.net", "connect"),
173
new SocketPermission("www.sun.com", "resolve"),
174
new SocketPermission("www.test1.com", "accept"),
175
new SocketPermission("www.test3.com", "resolve,connect"),
176
new SocketPermission("www.test4.com", "listen"),
177
};
178
179
private static final Permission[] propp = new Permission[]{
180
new PropertyPermission("user.home", "read"),
181
new PropertyPermission("java.home", "write"),
182
new PropertyPermission("test.home", "write"),
183
new PropertyPermission("test1.home", "read"),
184
new PropertyPermission("test2.home", "read"),
185
};
186
187
private static final Permission[] basicp = new Permission[] {
188
new NetPermission("setDefaultAuthenticator"),
189
new NetPermission("requestPasswordAuthentication"),
190
new NetPermission("specifyStreamHandler")
191
};
192
193
private static final Permission[] delegatep = new Permission[] {
194
new DelegationPermission(
195
"\"host/[email protected]\" \"cn=John,o=imc,c=us\""),
196
new DelegationPermission(
197
"\"user/[email protected]\" \"cn=John,o=imc,c=us\""),
198
new DelegationPermission(
199
"\"host/[email protected]\" \"cn=John,o=imc,c=us\"")
200
};
201
202
private static final Permission[] servicep = new Permission[]{
203
new ServicePermission("krbtgt/[email protected]", "initiate"),
204
new ServicePermission("ldap/[email protected]", "initiate"),
205
new ServicePermission("imap/[email protected]", "accept"),
206
new ServicePermission("acap/[email protected]", "initiate"),
207
new ServicePermission("host/[email protected]", "initiate"),
208
};
209
210
private static final Permission[] mbeanp = new Permission[] {
211
new MBeanServerPermission("createMBeanServer"),
212
new MBeanServerPermission("findMBeanServer"),
213
new MBeanServerPermission("newMBeanServer"),
214
new MBeanServerPermission("releaseMBeanServer"),
215
};
216
217
private static final Permission[] unresp = new Permission[] {
218
new UnresolvedPermission("com.unknown.TestClass", "UnknownPermission",
219
"read,write", null),
220
new UnresolvedPermission("com.unknown.TestClass", "APermission",
221
"read,write", null),
222
new UnresolvedPermission("com.unknown.TestClass", "BPermission",
223
"read,write", null),
224
new UnresolvedPermission("com.unknown.CClass", "CPermission",
225
"read,write", null),
226
new UnresolvedPermission("com.unknown.DClass", "DUnknownPermission",
227
"read,write", null),
228
new UnresolvedPermission("com.unknown.EClass", "EUnknownPermission",
229
"read,write", null),
230
};
231
232
private static final Permission[][] permlist = new Permission[][]{
233
allp, filep, sockp, propp, basicp, delegatep, servicep, mbeanp, unresp};
234
}
235
236