Path: blob/master/test/jdk/java/security/ProtectionDomain/Recursion.java
41149 views
/*1* Copyright (c) 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 494761826* @summary Recursion problem in security manager and policy code27*28* @run main/othervm/policy=Recursion.policy Recursion29*/3031import java.net.*;32import java.security.*;3334public class Recursion {3536public static void main(String[] args) throws Exception {3738// trigger security check to make sure policy is set39try {40System.getProperty("foo.bar");41} catch (Exception e) {42// fall thru43}4445// static perms46Permissions staticPerms = new Permissions();47staticPerms.add(new java.util.PropertyPermission("static.foo", "read"));4849ProtectionDomain pd = new ProtectionDomain50(new CodeSource51(new URL("http://foo"),52(java.security.cert.Certificate[])null),53staticPerms,54null,55null);5657// test with no SecurityManager58//59// merging should have occured - check for policy merged.foo permission6061System.setSecurityManager(null);62if (pd.toString().indexOf("merged.foo") < 0) {63throw new Exception("Test without SecurityManager failed");64}6566// test with SecurityManager on the bootclasspath, debug turned off,67// getPolicyPermission granted68//69// merging should have occured - check for policy merged.foo permission7071ProtectionDomain pd2 = new ProtectionDomain72(new CodeSource73(new URL("http://bar"),74(java.security.cert.Certificate[])null),75staticPerms,76null,77null);7879System.setSecurityManager(new SecurityManager());80if (pd2.toString().indexOf("merged.foo") < 0) {81throw new Exception("Test with bootclass SecurityManager failed");82}83}84}858687