blob: 9716b3857ffe93b64552fd4a08138c54e6fec34c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001 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 4511601
27 * @summary BasicPermissionCollection does not set permClass
28 * during deserialization
29 */
30
31import java.security.*;
32import java.io.*;
33
34public class PermClass {
35
36 public static void main(String[] args) throws Exception {
37
38 String dir = System.getProperty("test.src");
39 if (dir == null) {
40 dir = ".";
41 }
42
43 MyPermission mp = new MyPermission("PermClass");
44 if (args != null && args.length == 1 && args[0] != null) {
45 // set up serialized file (arg is JDK version)
46 PermissionCollection bpc = mp.newPermissionCollection();
47 bpc.add(mp);
48 File sFile = new File(dir, "PermClass." + args[0]);
49 ObjectOutputStream oos = new ObjectOutputStream
50 (new FileOutputStream("PermClass." + args[0]));
51 oos.writeObject(bpc);
52 oos.close();
53 System.exit(0);
54 }
55
56 // read in a 1.2.1 BasicPermissionCollection
57 File sFile = new File(dir, "PermClass.1.2.1");
58 ObjectInputStream ois = new ObjectInputStream
59 (new FileInputStream(sFile));
60 PermissionCollection pc = (PermissionCollection)ois.readObject();
61 System.out.println("1.2.1 collection = " + pc);
62
63 if (pc.implies(mp)) {
64 System.out.println("JDK 1.2.1 test passed");
65 } else {
66 throw new Exception("JDK 1.2.1 test failed");
67 }
68
69 // read in a 1.3.1 BasicPermissionCollection
70 sFile = new File(dir, "PermClass.1.3.1");
71 ois = new ObjectInputStream(new FileInputStream(sFile));
72 pc = (PermissionCollection)ois.readObject();
73 System.out.println("1.3.1 collection = " + pc);
74
75 if (pc.implies(mp)) {
76 System.out.println("JDK 1.3.1 test passed");
77 } else {
78 throw new Exception("JDK 1.3.1 test failed");
79 }
80
81 // read in a 1.4 BasicPermissionCollection
82 sFile = new File(dir, "PermClass.1.4");
83 ois = new ObjectInputStream(new FileInputStream(sFile));
84 pc = (PermissionCollection)ois.readObject();
85 System.out.println("1.4 collection = " + pc);
86
87 if (pc.implies(mp)) {
88 System.out.println("JDK 1.4 test 1 passed");
89 } else {
90 throw new Exception("JDK 1.4 test 1 failed");
91 }
92
93 // write out current BasicPermissionCollection
94 PermissionCollection bpc = mp.newPermissionCollection();
95 bpc.add(mp);
96 sFile = new File(dir, "PermClass.current");
97 ObjectOutputStream oos = new ObjectOutputStream
98 (new FileOutputStream("PermClass.current"));
99 oos.writeObject(bpc);
100 oos.close();
101
102 // read in current BasicPermissionCollection
103 ois = new ObjectInputStream(new FileInputStream("PermClass.current"));
104 pc = (PermissionCollection)ois.readObject();
105 System.out.println("current collection = " + pc);
106
107 if (pc.implies(mp)) {
108 System.out.println("JDK 1.4 test 2 passed");
109 } else {
110 throw new Exception("JDK 1.4 test 2 failed");
111 }
112 }
113}
114
115class MyPermission extends BasicPermission {
116 public MyPermission(String name) {
117 super(name);
118 }
119}