2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2000, 2003, 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
|
|
26 |
* @bug 4390546
|
|
27 |
* @summary performance regression and other bugs in
|
|
28 |
* SubjectDomainCombiner.combine
|
|
29 |
*
|
|
30 |
* @run main/othervm/policy=Regression.policy -Djava.security.auth.debug=combiner Regression
|
|
31 |
*/
|
|
32 |
|
|
33 |
import javax.security.auth.*;
|
|
34 |
import java.security.ProtectionDomain;
|
|
35 |
import java.security.CodeSource;
|
|
36 |
import java.net.URL;
|
|
37 |
import java.util.Set;
|
|
38 |
import java.util.HashSet;
|
|
39 |
|
|
40 |
public class Regression {
|
|
41 |
|
|
42 |
public static void main(String[] args) {
|
|
43 |
|
|
44 |
Set principals = new HashSet();
|
|
45 |
principals.add(new com.sun.security.auth.NTUserPrincipal("test1"));
|
|
46 |
principals.add(new com.sun.security.auth.NTUserPrincipal("test2"));
|
|
47 |
|
|
48 |
Subject subject = new Subject
|
|
49 |
(false, principals, new HashSet(), new HashSet());
|
|
50 |
|
|
51 |
SubjectDomainCombiner sdc = new SubjectDomainCombiner(subject);
|
|
52 |
|
|
53 |
URL url1;
|
|
54 |
URL url2;
|
|
55 |
URL url3;
|
|
56 |
URL url4;
|
|
57 |
try {
|
|
58 |
url1 = new URL("http://one");
|
|
59 |
url2 = new URL("http://two");
|
|
60 |
url3 = new URL("http://three");
|
|
61 |
url4 = new URL("http://four");
|
|
62 |
} catch (java.net.MalformedURLException mue) {
|
|
63 |
mue.printStackTrace();
|
|
64 |
throw new SecurityException("Test failed: " + mue.toString());
|
|
65 |
}
|
|
66 |
|
|
67 |
ProtectionDomain d1 = new ProtectionDomain
|
|
68 |
(new CodeSource(url1,
|
|
69 |
(java.security.cert.Certificate[]) null),
|
|
70 |
null, // permissions
|
|
71 |
null, // class loader
|
|
72 |
null); // principals
|
|
73 |
ProtectionDomain d2 = new ProtectionDomain
|
|
74 |
(new CodeSource(url2,
|
|
75 |
(java.security.cert.Certificate[]) null),
|
|
76 |
null, // permissions
|
|
77 |
null, // class loader
|
|
78 |
null); // principals
|
|
79 |
ProtectionDomain d3 = new ProtectionDomain
|
|
80 |
(new CodeSource(url3,
|
|
81 |
(java.security.cert.Certificate[]) null),
|
|
82 |
null, // permissions
|
|
83 |
null, // class loader
|
|
84 |
null); // principals
|
|
85 |
ProtectionDomain d4 = new ProtectionDomain
|
|
86 |
(new CodeSource(url4,
|
|
87 |
(java.security.cert.Certificate[]) null),
|
|
88 |
null, // permissions
|
|
89 |
null, // class loader
|
|
90 |
null); // principals
|
|
91 |
|
|
92 |
// test 1
|
|
93 |
// -- regular combine, make sure we get a proper combination back
|
|
94 |
|
|
95 |
ProtectionDomain currentDomains[] = { d1, d2, d3 };
|
|
96 |
ProtectionDomain assignedDomains[] = { d4 };
|
|
97 |
ProtectionDomain domains1[] = sdc.combine
|
|
98 |
(currentDomains, assignedDomains);
|
|
99 |
|
|
100 |
if (domains1.length != 4 ||
|
|
101 |
domains1[0] == d1 || domains1[1] == d2 || domains1[2] == d3 ||
|
|
102 |
domains1[3] != d4 ||
|
|
103 |
!domains1[0].implies(new RuntimePermission("queuePrintJob"))) {
|
|
104 |
throw new SecurityException("Test failed: combine test 1 failed");
|
|
105 |
}
|
|
106 |
|
|
107 |
System.out.println("-------- TEST ONE PASSED --------");
|
|
108 |
|
|
109 |
// test 2
|
|
110 |
// -- repeat combine, make sure combiner cachine returned the
|
|
111 |
// same PD's back
|
|
112 |
|
|
113 |
ProtectionDomain domains2[] = sdc.combine
|
|
114 |
(currentDomains, assignedDomains);
|
|
115 |
if (domains2.length != 4 ||
|
|
116 |
domains2[0] != domains1[0] || domains2[1] != domains1[1] ||
|
|
117 |
domains2[2] != domains1[2] ||
|
|
118 |
domains2[3] != domains1[3] ||
|
|
119 |
!domains2[0].implies(new RuntimePermission("queuePrintJob"))) {
|
|
120 |
throw new SecurityException("Test failed: combine test 2 failed");
|
|
121 |
}
|
|
122 |
|
|
123 |
System.out.println("-------- TEST TWO PASSED --------");
|
|
124 |
|
|
125 |
// test 3
|
|
126 |
// -- mutate the Subject and make sure the combiner cache
|
|
127 |
// got cleared out
|
|
128 |
|
|
129 |
subject.getPrincipals().remove
|
|
130 |
(new com.sun.security.auth.NTUserPrincipal("test2"));
|
|
131 |
ProtectionDomain domains3[] = sdc.combine
|
|
132 |
(currentDomains, assignedDomains);
|
|
133 |
if (domains3.length != 4 ||
|
|
134 |
domains3[0] == domains1[0] || domains3[1] == domains1[1] ||
|
|
135 |
domains3[2] == domains1[2] ||
|
|
136 |
domains3[3] != domains1[3] ||
|
|
137 |
!domains3[0].implies(new RuntimePermission("createClassLoader")) ||
|
|
138 |
domains3[0].implies(new RuntimePermission("queuePrintJob"))) {
|
|
139 |
throw new SecurityException("Test failed: combine test 3 failed");
|
|
140 |
}
|
|
141 |
|
|
142 |
System.out.println("-------- TEST THREE PASSED --------");
|
|
143 |
|
|
144 |
System.out.println("Test Passed");
|
|
145 |
}
|
|
146 |
}
|