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