Path: blob/master/test/jdk/javax/security/auth/SubjectDomainCombiner/Regression.java
41152 views
/*1* Copyright (c) 2000, 2017, 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 439054626* @modules jdk.security.auth27* @summary performance regression and other bugs in28* SubjectDomainCombiner.combine29*30* @run main/othervm/policy=Regression.policy -Djava.security.auth.debug=combiner Regression31*/3233import java.security.ProtectionDomain;34import java.security.CodeSource;35import java.net.URL;36import java.util.Set;37import java.util.HashSet;38import javax.security.auth.Subject;39import javax.security.auth.SubjectDomainCombiner;4041public class Regression {4243public static void main(String[] args) {4445Set principals = new HashSet();46principals.add(new com.sun.security.auth.NTUserPrincipal("test1"));47principals.add(new com.sun.security.auth.NTUserPrincipal("test2"));4849Subject subject = new Subject50(false, principals, new HashSet(), new HashSet());5152SubjectDomainCombiner sdc = new SubjectDomainCombiner(subject);5354URL url1;55URL url2;56URL url3;57URL url4;58try {59url1 = new URL("http://one");60url2 = new URL("http://two");61url3 = new URL("http://three");62url4 = new URL("http://four");63} catch (java.net.MalformedURLException mue) {64mue.printStackTrace();65throw new SecurityException("Test failed: " + mue.toString());66}6768ProtectionDomain d1 = new ProtectionDomain69(new CodeSource(url1,70(java.security.cert.Certificate[]) null),71null, // permissions72null, // class loader73null); // principals74ProtectionDomain d2 = new ProtectionDomain75(new CodeSource(url2,76(java.security.cert.Certificate[]) null),77null, // permissions78null, // class loader79null); // principals80ProtectionDomain d3 = new ProtectionDomain81(new CodeSource(url3,82(java.security.cert.Certificate[]) null),83null, // permissions84null, // class loader85null); // principals86ProtectionDomain d4 = new ProtectionDomain87(new CodeSource(url4,88(java.security.cert.Certificate[]) null),89null, // permissions90null, // class loader91null); // principals9293// test 194// -- regular combine, make sure we get a proper combination back9596ProtectionDomain currentDomains[] = { d1, d2, d3 };97ProtectionDomain assignedDomains[] = { d4 };98ProtectionDomain domains1[] = sdc.combine99(currentDomains, assignedDomains);100101if (domains1.length != 4 ||102domains1[0] == d1 || domains1[1] == d2 || domains1[2] == d3 ||103domains1[3] != d4 ||104!domains1[0].implies(new RuntimePermission("queuePrintJob"))) {105throw new SecurityException("Test failed: combine test 1 failed");106}107108System.out.println("-------- TEST ONE PASSED --------");109110// test 2111// -- repeat combine, make sure combiner cachine returned the112// same PD's back113114ProtectionDomain domains2[] = sdc.combine115(currentDomains, assignedDomains);116if (domains2.length != 4 ||117domains2[0] != domains1[0] || domains2[1] != domains1[1] ||118domains2[2] != domains1[2] ||119domains2[3] != domains1[3] ||120!domains2[0].implies(new RuntimePermission("queuePrintJob"))) {121throw new SecurityException("Test failed: combine test 2 failed");122}123124System.out.println("-------- TEST TWO PASSED --------");125126// test 3127// -- mutate the Subject and make sure the combiner cache128// got cleared out129130subject.getPrincipals().remove131(new com.sun.security.auth.NTUserPrincipal("test2"));132ProtectionDomain domains3[] = sdc.combine133(currentDomains, assignedDomains);134if (domains3.length != 4 ||135domains3[0] == domains1[0] || domains3[1] == domains1[1] ||136domains3[2] == domains1[2] ||137domains3[3] != domains1[3] ||138!domains3[0].implies(new RuntimePermission("createClassLoader")) ||139domains3[0].implies(new RuntimePermission("queuePrintJob"))) {140throw new SecurityException("Test failed: combine test 3 failed");141}142143System.out.println("-------- TEST THREE PASSED --------");144145System.out.println("Test Passed");146}147}148149150