Path: blob/master/test/jdk/java/security/BasicPermission/PermClass.java
41149 views
/*1* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4511601 705491826* @summary BasicPermissionCollection does not set permClass27* during deserialization28*/2930import java.security.*;31import java.io.*;3233public class PermClass {3435public static void main(String[] args) throws Exception {3637String dir = System.getProperty("test.src");38if (dir == null) {39dir = ".";40}4142MyPermission mp = new MyPermission("PermClass");43if (args != null && args.length == 1 && args[0] != null) {44// set up serialized file (arg is JDK version)45PermissionCollection bpc = mp.newPermissionCollection();46bpc.add(mp);47File sFile = new File(dir, "PermClass." + args[0]);48ObjectOutputStream oos = new ObjectOutputStream49(new FileOutputStream("PermClass." + args[0]));50oos.writeObject(bpc);51oos.close();52System.exit(0);53}5455// read in a 1.2.1 BasicPermissionCollection56File sFile = new File(dir, "PermClass.1.2.1");57try (FileInputStream fis = new FileInputStream(sFile);58ObjectInputStream ois = new ObjectInputStream(fis)) {59PermissionCollection pc = (PermissionCollection)ois.readObject();60System.out.println("1.2.1 collection = " + pc);6162if (pc.implies(mp)) {63System.out.println("JDK 1.2.1 test passed");64} else {65throw new Exception("JDK 1.2.1 test failed");66}67}6869// read in a 1.3.1 BasicPermissionCollection70sFile = new File(dir, "PermClass.1.3.1");71try (FileInputStream fis = new FileInputStream(sFile);72ObjectInputStream ois = new ObjectInputStream(fis)) {73PermissionCollection pc = (PermissionCollection)ois.readObject();74System.out.println("1.3.1 collection = " + pc);7576if (pc.implies(mp)) {77System.out.println("JDK 1.3.1 test passed");78} else {79throw new Exception("JDK 1.3.1 test failed");80}81}8283// read in a 1.4 BasicPermissionCollection84sFile = new File(dir, "PermClass.1.4");85try (FileInputStream fis = new FileInputStream(sFile);86ObjectInputStream ois = new ObjectInputStream(fis)) {87PermissionCollection pc = (PermissionCollection)ois.readObject();88System.out.println("1.4 collection = " + pc);8990if (pc.implies(mp)) {91System.out.println("JDK 1.4 test 1 passed");92} else {93throw new Exception("JDK 1.4 test 1 failed");94}95}9697// write out current BasicPermissionCollection98PermissionCollection bpc = mp.newPermissionCollection();99bpc.add(mp);100sFile = new File(dir, "PermClass.current");101try (FileOutputStream fos = new FileOutputStream("PermClass.current");102ObjectOutputStream oos = new ObjectOutputStream(fos)) {103oos.writeObject(bpc);104}105106// read in current BasicPermissionCollection107try (FileInputStream fis = new FileInputStream("PermClass.current");108ObjectInputStream ois = new ObjectInputStream(fis)) {109PermissionCollection pc = (PermissionCollection)ois.readObject();110System.out.println("current collection = " + pc);111112if (pc.implies(mp)) {113System.out.println("JDK 1.4 test 2 passed");114} else {115throw new Exception("JDK 1.4 test 2 failed");116}117}118}119}120121class MyPermission extends BasicPermission {122public MyPermission(String name) {123super(name);124}125}126127128