Path: blob/master/test/jdk/sun/security/provider/PolicyFile/SelfWildcard.java
41153 views
/*1* Copyright (c) 2002, 2003, 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 451042426* @summary ${{self}} expansion fails for grants with wildcard principal names27*/2829import java.util.*;30import java.security.*;31import javax.security.auth.Subject.*;32import javax.security.auth.x500.*;3334public class SelfWildcard {3536private static final String SELF_ONE =37"javax.security.auth.x500.X500Principal \"CN=foo\"";38private static final String SELF_TWOTHREE =39"javax.security.auth.x500.X500Principal \"CN=foo\", " +40"javax.security.auth.x500.X500Principal \"CN=bar\"";41private static final String SELF_FOURFIVE =42"javax.security.auth.x500.X500Principal \"CN=foo\", " +43"javax.security.auth.x500.X500Principal \"CN=bar\", " +44"com.sun.security.auth.UnixPrincipal \"foobar\"";4546public static void main(String[] args) throws Exception {47if (System.getProperty("test.src") == null) {48System.setProperty("test.src", ".");49}50System.setProperty("java.security.policy",51"file:${test.src}/SelfWildcard.policy");5253Principal[] ps = {54new X500Principal("CN=foo"),55new X500Principal("CN=bar"),56new com.sun.security.auth.UnixPrincipal("foobar") };57ProtectionDomain pd = new ProtectionDomain58(new CodeSource(null, (java.security.cert.Certificate[]) null),59null, null, ps);60PermissionCollection perms = Policy.getPolicy().getPermissions(pd);61System.out.println("perms = " + perms);62System.out.println();6364Enumeration e = perms.elements();65while (e.hasMoreElements()) {66Permission p = (Permission)e.nextElement();67if (p instanceof UnresolvedPermission &&68p.toString().indexOf(SELF_ONE) < 0 &&69p.toString().indexOf(SELF_TWOTHREE) < 0 &&70p.toString().indexOf(SELF_FOURFIVE) < 0) {71throw new SecurityException("Test Failed");72}73}7475System.out.println("Test Succeeded");76}77}787980