Path: blob/master/test/jdk/java/security/ProtectionDomain/RecursionDebug.java
41149 views
/*1* Copyright (c) 2003, 2004, 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 -Djava.security.debug=domain RecursionDebug29*/3031import java.security.*;32import java.net.*;3334public class RecursionDebug {3536// non bootclasspath SecurityManager37public static class RecursionSM extends SecurityManager {38public void checkPermission(Permission p) {39super.checkPermission(p);40}41}4243public static void main(String[] args) throws Exception {4445// trigger security check to make sure policy is set46try {47System.getProperty("foo.bar");48} catch (Exception e) {49// fall thru50}5152// static perms53Permissions staticPerms = new Permissions();54staticPerms.add(new java.util.PropertyPermission("static.foo", "read"));5556ProtectionDomain pd = new ProtectionDomain57(new CodeSource58(new URL("http://foo"),59(java.security.cert.Certificate[])null),60staticPerms,61null,62null);6364// test with SecurityManager on the bootclasspath, debug turned on65//66// merging should have occured - check for policy merged.foo permission6768if (pd.toString().indexOf("merged.foo") < 0) {69throw new Exception("Test with bootclass SecurityManager failed");70}7172// test with SecurityManager not on bootclasspath, debug turned on73//74// merging should not have occured, and there should be no recursion7576ProtectionDomain pd2 = new ProtectionDomain77(new CodeSource78(new URL("http://bar"),79(java.security.cert.Certificate[])null),80staticPerms,81null,82null);8384System.setSecurityManager(new RecursionDebug.RecursionSM());85if (pd2.toString().indexOf("merged.foo") >= 0) {86throw new Exception87("Test with custom non-bootclass SecurityManager failed");88}8990System.setSecurityManager(null);91}92}939495