|
1 /* |
|
2 * Copyright 2000 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 4291610 |
|
27 * @summary BasicPermission.newPermissionCollection collection does not |
|
28 * enforce homogeneity |
|
29 */ |
|
30 |
|
31 import java.security.BasicPermission; |
|
32 |
|
33 public class Homogeneity { |
|
34 |
|
35 public static void main(String[] args) { |
|
36 |
|
37 java.lang.RuntimePermission rp = new java.lang.RuntimePermission |
|
38 ("*"); |
|
39 java.lang.RuntimePermission rp2 = new java.lang.RuntimePermission |
|
40 ("exitVM"); |
|
41 java.net.NetPermission np = new java.net.NetPermission |
|
42 ("setDefaultAuthenticator"); |
|
43 |
|
44 // should be able to add identical BasicPermission subclasses to the |
|
45 // same collection |
|
46 java.security.PermissionCollection perms = rp.newPermissionCollection(); |
|
47 try { |
|
48 perms.add(rp); |
|
49 perms.add(rp2); |
|
50 } catch (IllegalArgumentException iae) { |
|
51 throw new SecurityException("GOOD ADD TEST FAILED"); |
|
52 } |
|
53 |
|
54 // make sure you can't add different BasicPermission subclasses |
|
55 // to the same collection |
|
56 try { |
|
57 // this should fail |
|
58 perms.add(np); |
|
59 throw new SecurityException("BAD ADD TEST FAILED"); |
|
60 } catch (IllegalArgumentException iae) { |
|
61 // good |
|
62 } |
|
63 |
|
64 // make sure a BasicPermissionCollection doesn't imply |
|
65 // random BasicPermission subclasses |
|
66 if (perms.implies(np)) { |
|
67 throw new SecurityException("IMPLIES TEST FAILED"); |
|
68 } |
|
69 } |
|
70 } |