Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/security/auth/Subject/Serial.java
41154 views
1
/*
2
* Copyright (c) 2000, 2017, 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 4364826
27
* @modules jdk.security.auth
28
* @summary Subject serialized principal set is
29
* implementation-dependent class
30
* @run main/othervm/policy=Serial.policy Serial
31
*/
32
33
import java.io.FileInputStream;
34
import java.io.FileOutputStream;
35
import java.io.ObjectInputStream;
36
import java.io.ObjectOutputStream;
37
import java.util.HashSet;
38
import java.util.Set;
39
import javax.security.auth.Subject;
40
41
public class Serial implements java.io.Serializable {
42
43
public static void main(String[] args) {
44
45
try {
46
FileOutputStream fos = new FileOutputStream("serial.tmp");
47
ObjectOutputStream oos = new ObjectOutputStream(fos);
48
49
HashSet principals = new HashSet();
50
principals.add
51
(new com.sun.security.auth.NTUserPrincipal("test"));
52
principals.add
53
(new com.sun.security.auth.NTDomainPrincipal("test2"));
54
55
Subject s = new Subject
56
(false,
57
principals,
58
new HashSet(),
59
new HashSet());
60
oos.writeObject(s);
61
oos.flush();
62
fos.close();
63
64
FileInputStream fis = new FileInputStream("serial.tmp");
65
ObjectInputStream ois = new ObjectInputStream(fis);
66
67
Subject s2 = (Subject)ois.readObject();
68
fis.close();
69
70
System.out.println("s2 = " + s2.toString());
71
System.out.println("s2.getPrincipals().size() = " +
72
s2.getPrincipals().size());
73
if (!s.equals(s2) || !s2.equals(s)) {
74
throw new SecurityException("Serial test failed: " +
75
"EQUALS TEST FAILED");
76
}
77
78
// make sure private credentials are not serializable
79
// without permissions
80
81
Set privateCredentials = s.getPrivateCredentials();
82
privateCredentials.add(new Serial());
83
84
fos = new FileOutputStream("serial2.tmp");
85
oos = new ObjectOutputStream(fos);
86
try {
87
oos.writeObject(privateCredentials);
88
oos.flush();
89
fos.close();
90
throw new RuntimeException("Serial test failed: " +
91
"allowed to serialize private credential set");
92
} catch (SecurityException se) {
93
// good
94
se.printStackTrace();
95
}
96
97
System.out.println("Serial test succeeded");
98
} catch (Exception e) {
99
e.printStackTrace();
100
throw new SecurityException("Serial test failed");
101
}
102
}
103
}
104
105