Path: blob/master/test/jdk/sun/security/provider/PolicyFile/Alias.java
41153 views
/*1* Copyright (c) 2000, 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 433776126* @summary add principal "alias" grant syntax to policy file27*28* Note: the keystore password is "Alias.password".29* Note: this test also covers 4501853 as well.30*31* @run main/othervm/policy=Alias.policy Alias32*/3334import java.security.*;35import java.util.*;3637public class Alias {3839public static void main(String[] args) {4041Principal[] principals = new Principal[3];42principals[0] = new com.sun.security.auth.UnixPrincipal("unix");43principals[1] = new javax.security.auth.x500.X500Principal("cn=x509");44principals[2] = new javax.security.auth.x500.X500Principal45("emailaddress=duke@sun");4647java.net.URL url = null;48try {49url = new java.net.URL("http://alias");50} catch (java.net.MalformedURLException mue) {51System.out.println("test 1 failed");52throw new SecurityException(mue.getMessage());53}54CodeSource cs =55new CodeSource(url, (java.security.cert.Certificate[]) null);5657ProtectionDomain pd = new ProtectionDomain58(cs,59null,60null,61principals);6263PermissionCollection perms = Policy.getPolicy().getPermissions(pd);6465if (perms.implies(new SecurityPermission("ALIAS"))) {66System.out.println("test succeeded");67} else {68System.out.println("test 2 failed");69throw new SecurityException("test failed");70}71}72}737475