J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 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 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * @test |
| 26 | * @bug 4510424 |
| 27 | * @summary ${{self}} expansion fails for grants with wildcard principal names |
| 28 | */ |
| 29 | |
| 30 | import java.util.*; |
| 31 | import java.security.*; |
| 32 | import javax.security.auth.Subject.*; |
| 33 | import javax.security.auth.x500.*; |
| 34 | |
| 35 | public class SelfWildcard { |
| 36 | |
| 37 | private static final String SELF_ONE = |
| 38 | "javax.security.auth.x500.X500Principal \"CN=foo\""; |
| 39 | private static final String SELF_TWOTHREE = |
| 40 | "javax.security.auth.x500.X500Principal \"CN=foo\", " + |
| 41 | "javax.security.auth.x500.X500Principal \"CN=bar\""; |
| 42 | private static final String SELF_FOURFIVE = |
| 43 | "javax.security.auth.x500.X500Principal \"CN=foo\", " + |
| 44 | "javax.security.auth.x500.X500Principal \"CN=bar\", " + |
| 45 | "com.sun.security.auth.UnixPrincipal \"foobar\""; |
| 46 | |
| 47 | public static void main(String[] args) throws Exception { |
| 48 | if (System.getProperty("test.src") == null) { |
| 49 | System.setProperty("test.src", "."); |
| 50 | } |
| 51 | System.setProperty("java.security.policy", |
| 52 | "file:${test.src}/SelfWildcard.policy"); |
| 53 | |
| 54 | Principal[] ps = { |
| 55 | new X500Principal("CN=foo"), |
| 56 | new X500Principal("CN=bar"), |
| 57 | new com.sun.security.auth.UnixPrincipal("foobar") }; |
| 58 | ProtectionDomain pd = new ProtectionDomain |
| 59 | (new CodeSource(null, (java.security.cert.Certificate[]) null), |
| 60 | null, null, ps); |
| 61 | PermissionCollection perms = Policy.getPolicy().getPermissions(pd); |
| 62 | System.out.println("perms = " + perms); |
| 63 | System.out.println(); |
| 64 | |
| 65 | Enumeration e = perms.elements(); |
| 66 | while (e.hasMoreElements()) { |
| 67 | Permission p = (Permission)e.nextElement(); |
| 68 | if (p instanceof UnresolvedPermission && |
| 69 | p.toString().indexOf(SELF_ONE) < 0 && |
| 70 | p.toString().indexOf(SELF_TWOTHREE) < 0 && |
| 71 | p.toString().indexOf(SELF_FOURFIVE) < 0) { |
| 72 | throw new SecurityException("Test Failed"); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | System.out.println("Test Succeeded"); |
| 77 | } |
| 78 | } |