0N/A/*
2362N/A * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4390546
0N/A * @summary performance regression and other bugs in
0N/A * SubjectDomainCombiner.combine
0N/A *
0N/A * @run main/othervm/policy=Regression.policy -Djava.security.auth.debug=combiner Regression
0N/A */
0N/A
0N/Aimport javax.security.auth.*;
0N/Aimport java.security.ProtectionDomain;
0N/Aimport java.security.CodeSource;
0N/Aimport java.net.URL;
0N/Aimport java.util.Set;
0N/Aimport java.util.HashSet;
0N/A
0N/Apublic class Regression {
0N/A
0N/A public static void main(String[] args) {
0N/A
0N/A Set principals = new HashSet();
0N/A principals.add(new com.sun.security.auth.NTUserPrincipal("test1"));
0N/A principals.add(new com.sun.security.auth.NTUserPrincipal("test2"));
0N/A
0N/A Subject subject = new Subject
0N/A (false, principals, new HashSet(), new HashSet());
0N/A
0N/A SubjectDomainCombiner sdc = new SubjectDomainCombiner(subject);
0N/A
0N/A URL url1;
0N/A URL url2;
0N/A URL url3;
0N/A URL url4;
0N/A try {
0N/A url1 = new URL("http://one");
0N/A url2 = new URL("http://two");
0N/A url3 = new URL("http://three");
0N/A url4 = new URL("http://four");
0N/A } catch (java.net.MalformedURLException mue) {
0N/A mue.printStackTrace();
0N/A throw new SecurityException("Test failed: " + mue.toString());
0N/A }
0N/A
0N/A ProtectionDomain d1 = new ProtectionDomain
0N/A (new CodeSource(url1,
0N/A (java.security.cert.Certificate[]) null),
0N/A null, // permissions
0N/A null, // class loader
0N/A null); // principals
0N/A ProtectionDomain d2 = new ProtectionDomain
0N/A (new CodeSource(url2,
0N/A (java.security.cert.Certificate[]) null),
0N/A null, // permissions
0N/A null, // class loader
0N/A null); // principals
0N/A ProtectionDomain d3 = new ProtectionDomain
0N/A (new CodeSource(url3,
0N/A (java.security.cert.Certificate[]) null),
0N/A null, // permissions
0N/A null, // class loader
0N/A null); // principals
0N/A ProtectionDomain d4 = new ProtectionDomain
0N/A (new CodeSource(url4,
0N/A (java.security.cert.Certificate[]) null),
0N/A null, // permissions
0N/A null, // class loader
0N/A null); // principals
0N/A
0N/A // test 1
0N/A // -- regular combine, make sure we get a proper combination back
0N/A
0N/A ProtectionDomain currentDomains[] = { d1, d2, d3 };
0N/A ProtectionDomain assignedDomains[] = { d4 };
0N/A ProtectionDomain domains1[] = sdc.combine
0N/A (currentDomains, assignedDomains);
0N/A
0N/A if (domains1.length != 4 ||
0N/A domains1[0] == d1 || domains1[1] == d2 || domains1[2] == d3 ||
0N/A domains1[3] != d4 ||
0N/A !domains1[0].implies(new RuntimePermission("queuePrintJob"))) {
0N/A throw new SecurityException("Test failed: combine test 1 failed");
0N/A }
0N/A
0N/A System.out.println("-------- TEST ONE PASSED --------");
0N/A
0N/A // test 2
0N/A // -- repeat combine, make sure combiner cachine returned the
0N/A // same PD's back
0N/A
0N/A ProtectionDomain domains2[] = sdc.combine
0N/A (currentDomains, assignedDomains);
0N/A if (domains2.length != 4 ||
0N/A domains2[0] != domains1[0] || domains2[1] != domains1[1] ||
0N/A domains2[2] != domains1[2] ||
0N/A domains2[3] != domains1[3] ||
0N/A !domains2[0].implies(new RuntimePermission("queuePrintJob"))) {
0N/A throw new SecurityException("Test failed: combine test 2 failed");
0N/A }
0N/A
0N/A System.out.println("-------- TEST TWO PASSED --------");
0N/A
0N/A // test 3
0N/A // -- mutate the Subject and make sure the combiner cache
0N/A // got cleared out
0N/A
0N/A subject.getPrincipals().remove
0N/A (new com.sun.security.auth.NTUserPrincipal("test2"));
0N/A ProtectionDomain domains3[] = sdc.combine
0N/A (currentDomains, assignedDomains);
0N/A if (domains3.length != 4 ||
0N/A domains3[0] == domains1[0] || domains3[1] == domains1[1] ||
0N/A domains3[2] == domains1[2] ||
0N/A domains3[3] != domains1[3] ||
0N/A !domains3[0].implies(new RuntimePermission("createClassLoader")) ||
0N/A domains3[0].implies(new RuntimePermission("queuePrintJob"))) {
0N/A throw new SecurityException("Test failed: combine test 3 failed");
0N/A }
0N/A
0N/A System.out.println("-------- TEST THREE PASSED --------");
0N/A
0N/A System.out.println("Test Passed");
0N/A }
0N/A}