Path: blob/master/test/jdk/java/beans/Beans/Test4080522.java
41152 views
/*1* Copyright (c) 1998, 2010, 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 408052226* @summary Tests security checks for calls on:27* Beans.setDesignTime28* Beans.setGuiAvailable29* Introspector.setBeanInfoSearchPath30* PropertyEditorManager.setEditorSearchPath31* @run main/othervm -Djava.security.manager=allow Test408052232* @author Graham Hamilton33*/3435import java.beans.Introspector;36import java.beans.Beans;37import java.beans.PropertyEditorManager;3839public class Test4080522 {40public static void main(String[] args) {41OurSecurityManager sm = new OurSecurityManager();42String[] path = {"a", "b"};43// with no security manager we shuld be able to do these calls OK44test(path);45// add our own security manager46System.setSecurityManager(sm);47// now each of the calls should raise an exception48try {49Beans.setDesignTime(true);50throw new Error("Beans.setDesignTime should throw SecurityException");51} catch (SecurityException exception) {52// expected exception53}54try {55Beans.setGuiAvailable(true);56throw new Error("Beans.setGuiAvailable should throw SecurityException");57} catch (SecurityException exception) {58// expected exception59}60try {61Introspector.setBeanInfoSearchPath(path);62throw new Error("Introspector.setBeanInfoSearchPath should throw SecurityException");63} catch (SecurityException exception) {64// expected exception65}66try {67PropertyEditorManager.setEditorSearchPath(path);68throw new Error("PropertyEditorManager.setEditorSearchPath should throw SecurityException");69} catch (SecurityException exception) {70// expected exception71}72// now set the security manager to be friendly73sm.friendly = true;74// now the calls should be OK again.75test(path);76}7778private static void test(String[] path) {79try {80Beans.setDesignTime(true);81Beans.setGuiAvailable(true);82Introspector.setBeanInfoSearchPath(path);83PropertyEditorManager.setEditorSearchPath(path);84} catch (SecurityException exception) {85throw new Error("unexpected security exception", exception);86}87}8889private static class OurSecurityManager extends SecurityManager {90boolean friendly;9192public void checkPropertiesAccess() {93if (!friendly) {94throw new SecurityException("No way");95}96}97}98}99100101