2
|
1 |
/*
|
10057
|
2 |
* Copyright (c) 2001, 2011, 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
|
10057
|
26 |
* @bug 4511601 7054918
|
2
|
27 |
* @summary BasicPermissionCollection does not set permClass
|
|
28 |
* during deserialization
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.security.*;
|
|
32 |
import java.io.*;
|
|
33 |
|
|
34 |
public 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");
|
10057
|
58 |
try (FileInputStream fis = new FileInputStream(sFile);
|
|
59 |
ObjectInputStream ois = new ObjectInputStream(fis)) {
|
|
60 |
PermissionCollection pc = (PermissionCollection)ois.readObject();
|
|
61 |
System.out.println("1.2.1 collection = " + pc);
|
2
|
62 |
|
10057
|
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 |
}
|
2
|
68 |
}
|
|
69 |
|
|
70 |
// read in a 1.3.1 BasicPermissionCollection
|
|
71 |
sFile = new File(dir, "PermClass.1.3.1");
|
10057
|
72 |
try (FileInputStream fis = new FileInputStream(sFile);
|
|
73 |
ObjectInputStream ois = new ObjectInputStream(fis)) {
|
|
74 |
PermissionCollection pc = (PermissionCollection)ois.readObject();
|
|
75 |
System.out.println("1.3.1 collection = " + pc);
|
2
|
76 |
|
10057
|
77 |
if (pc.implies(mp)) {
|
|
78 |
System.out.println("JDK 1.3.1 test passed");
|
|
79 |
} else {
|
|
80 |
throw new Exception("JDK 1.3.1 test failed");
|
|
81 |
}
|
2
|
82 |
}
|
|
83 |
|
|
84 |
// read in a 1.4 BasicPermissionCollection
|
|
85 |
sFile = new File(dir, "PermClass.1.4");
|
10057
|
86 |
try (FileInputStream fis = new FileInputStream(sFile);
|
|
87 |
ObjectInputStream ois = new ObjectInputStream(fis)) {
|
|
88 |
PermissionCollection pc = (PermissionCollection)ois.readObject();
|
|
89 |
System.out.println("1.4 collection = " + pc);
|
2
|
90 |
|
10057
|
91 |
if (pc.implies(mp)) {
|
|
92 |
System.out.println("JDK 1.4 test 1 passed");
|
|
93 |
} else {
|
|
94 |
throw new Exception("JDK 1.4 test 1 failed");
|
|
95 |
}
|
2
|
96 |
}
|
|
97 |
|
|
98 |
// write out current BasicPermissionCollection
|
|
99 |
PermissionCollection bpc = mp.newPermissionCollection();
|
|
100 |
bpc.add(mp);
|
|
101 |
sFile = new File(dir, "PermClass.current");
|
10057
|
102 |
try (FileOutputStream fos = new FileOutputStream("PermClass.current");
|
|
103 |
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
|
|
104 |
oos.writeObject(bpc);
|
|
105 |
}
|
2
|
106 |
|
|
107 |
// read in current BasicPermissionCollection
|
10057
|
108 |
try (FileInputStream fis = new FileInputStream("PermClass.current");
|
|
109 |
ObjectInputStream ois = new ObjectInputStream(fis)) {
|
|
110 |
PermissionCollection pc = (PermissionCollection)ois.readObject();
|
|
111 |
System.out.println("current collection = " + pc);
|
2
|
112 |
|
10057
|
113 |
if (pc.implies(mp)) {
|
|
114 |
System.out.println("JDK 1.4 test 2 passed");
|
|
115 |
} else {
|
|
116 |
throw new Exception("JDK 1.4 test 2 failed");
|
|
117 |
}
|
2
|
118 |
}
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
class MyPermission extends BasicPermission {
|
|
123 |
public MyPermission(String name) {
|
|
124 |
super(name);
|
|
125 |
}
|
|
126 |
}
|