1/*
2 * Copyright (c) 2000, Oracle and/or its affiliates. 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 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.
22 */
23
24/*
25 * @test
26 * @bug 4364855
27 * @summary     PrivateCredentialPermission serialized set has
28 *              implementation-dependent class
29 * @run main/othervm/policy=Serial.policy Serial
30 */
31
32import javax.security.auth.*;
33import java.io.*;
34import java.util.*;
35
36public class Serial implements java.io.Serializable {
37
38    public static void main(String[] args) {
39
40        try {
41            FileOutputStream fos = new FileOutputStream("serial.tmp");
42            ObjectOutputStream oos = new ObjectOutputStream(fos);
43
44            PrivateCredentialPermission pcp = new PrivateCredentialPermission
45                        ("cred1 pc1 \"pn1\" pc2 \"pn2\"", "read");
46            oos.writeObject(pcp);
47            oos.flush();
48            fos.close();
49
50            FileInputStream fis = new FileInputStream("serial.tmp");
51            ObjectInputStream ois = new ObjectInputStream(fis);
52
53            PrivateCredentialPermission pcp2 =
54                (PrivateCredentialPermission)ois.readObject();
55            fis.close();
56
57            System.out.println("pcp2 = " + pcp2.toString());
58            System.out.println("pcp2.getPrincipals().length = " +
59                                pcp2.getPrincipals().length);
60            if (!pcp.equals(pcp2) || !pcp2.equals(pcp)) {
61                throw new SecurityException("Serial test failed: " +
62                                        "EQUALS TEST FAILED");
63            }
64
65            System.out.println("Serial test succeeded");
66        } catch (Exception e) {
67            e.printStackTrace();
68            throw new SecurityException("Serial test failed");
69        }
70    }
71}
72