Path: blob/master/test/jdk/javax/security/auth/SubjectDomainCombiner/Optimize.java
41152 views
/*1* Copyright (c) 2000, 2015, 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 488701726* @summary SubjectDomainCombiner optimization incorrect27*/2829import javax.security.auth.Subject;30import javax.security.auth.SubjectDomainCombiner;31import java.security.*;3233public class Optimize {3435public static void main(String[] args) {3637ProtectionDomain pd1 = new ProtectionDomain(38new CodeSource(null, (java.security.cert.Certificate[]) null),39new Permissions(),40null, null);41ProtectionDomain pd2 = new ProtectionDomain(42new CodeSource(null, (java.security.cert.Certificate[]) null),43new Permissions(),44null, null);45ProtectionDomain pd3 = new ProtectionDomain(46new CodeSource(null, (java.security.cert.Certificate[]) null),47new Permissions(),48null, null);4950ProtectionDomain[] current = new ProtectionDomain[] {pd1, pd2};51ProtectionDomain[] assigned = new ProtectionDomain[] {pd3, pd2};5253SubjectDomainCombiner sdc = new SubjectDomainCombiner(new Subject());54ProtectionDomain[] combined = sdc.combine(current, assigned);5556// this depends on current SubjectDomainCombiner implementation57// (ordering of returned domains)58if (combined.length == 4 &&59combined[0] != pd1 && combined[1] != pd2 &&60combined[2] == pd3 && combined[3] == pd2) {61System.out.println("test passed");62} else {63System.out.println("test failed");64throw new SecurityException("Test Failed");65}66}67}686970