Path: blob/master/test/jdk/javax/security/auth/PrivateCredentialPermission/Serial.java
41153 views
/*1* Copyright (c) 2000, 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 436485526* @summary PrivateCredentialPermission serialized set has27* implementation-dependent class28* @run main/othervm/policy=Serial.policy Serial29*/3031import javax.security.auth.*;32import java.io.*;33import java.util.*;3435public class Serial implements java.io.Serializable {3637public static void main(String[] args) {3839try {40FileOutputStream fos = new FileOutputStream("serial.tmp");41ObjectOutputStream oos = new ObjectOutputStream(fos);4243PrivateCredentialPermission pcp = new PrivateCredentialPermission44("cred1 pc1 \"pn1\" pc2 \"pn2\"", "read");45oos.writeObject(pcp);46oos.flush();47fos.close();4849FileInputStream fis = new FileInputStream("serial.tmp");50ObjectInputStream ois = new ObjectInputStream(fis);5152PrivateCredentialPermission pcp2 =53(PrivateCredentialPermission)ois.readObject();54fis.close();5556System.out.println("pcp2 = " + pcp2.toString());57System.out.println("pcp2.getPrincipals().length = " +58pcp2.getPrincipals().length);59if (!pcp.equals(pcp2) || !pcp2.equals(pcp)) {60throw new SecurityException("Serial test failed: " +61"EQUALS TEST FAILED");62}6364System.out.println("Serial test succeeded");65} catch (Exception e) {66e.printStackTrace();67throw new SecurityException("Serial test failed");68}69}70}717273