Test4080522.java revision 2362
4545N/A/*
4545N/A * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
4545N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4545N/A *
4545N/A * This code is free software; you can redistribute it and/or modify it
4545N/A * under the terms of the GNU General Public License version 2 only, as
4545N/A * published by the Free Software Foundation.
4545N/A *
4545N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4545N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4545N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4545N/A * version 2 for more details (a copy is included in the LICENSE file that
4545N/A * accompanied this code).
4545N/A *
4545N/A * You should have received a copy of the GNU General Public License version
4545N/A * 2 along with this work; if not, write to the Free Software Foundation,
4545N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4545N/A *
4545N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4545N/A * or visit www.oracle.com if you need additional information or have any
4545N/A * questions.
4545N/A */
4545N/A
4545N/A/*
4545N/A * @test
4545N/A * @bug 4080522
4545N/A * @summary Tests security checks for calls on:
4545N/A * Beans.setDesignTime
4545N/A * Beans.setGuiAvailable
4545N/A * Introspector.setBeanInfoSearchPath
4545N/A * PropertyEditorManager.setEditorSearchPath
4545N/A * @author Graham Hamilton
4545N/A */
4545N/A
4545N/Aimport java.beans.Introspector;
4545N/Aimport java.beans.Beans;
4545N/Aimport java.beans.PropertyEditorManager;
4545N/A
4545N/Apublic class Test4080522 {
4545N/A public static void main(String[] args) {
4545N/A OurSecurityManager sm = new OurSecurityManager();
4545N/A String[] path = {"a", "b"};
4545N/A // with no security manager we shuld be able to do these calls OK
4545N/A test(path);
4545N/A // add our own security manager
4545N/A System.setSecurityManager(sm);
4545N/A // now each of the calls should raise an exception
4545N/A try {
4545N/A Beans.setDesignTime(true);
4545N/A throw new Error("Beans.setDesignTime should throw SecurityException");
4545N/A } catch (SecurityException exception) {
4545N/A // expected exception
4545N/A }
4545N/A try {
4545N/A Beans.setGuiAvailable(true);
4545N/A throw new Error("Beans.setGuiAvailable should throw SecurityException");
4545N/A } catch (SecurityException exception) {
4545N/A // expected exception
4545N/A }
4545N/A try {
4545N/A Introspector.setBeanInfoSearchPath(path);
4545N/A throw new Error("Introspector.setBeanInfoSearchPath should throw SecurityException");
4545N/A } catch (SecurityException exception) {
4545N/A // expected exception
4545N/A }
4545N/A try {
4545N/A PropertyEditorManager.setEditorSearchPath(path);
4545N/A throw new Error("PropertyEditorManager.setEditorSearchPath should throw SecurityException");
4545N/A } catch (SecurityException exception) {
4545N/A // expected exception
4545N/A }
4545N/A // now set the security manager to be friendly
4545N/A sm.friendly = true;
4545N/A // now the calls should be OK again.
4545N/A test(path);
4545N/A }
4545N/A
private static void test(String[] path) {
try {
Beans.setDesignTime(true);
Beans.setGuiAvailable(true);
Introspector.setBeanInfoSearchPath(path);
PropertyEditorManager.setEditorSearchPath(path);
} catch (SecurityException exception) {
throw new Error("unexpected security exception", exception);
}
}
private static class OurSecurityManager extends SecurityManager {
boolean friendly;
public void checkPropertiesAccess() {
if (!friendly) {
throw new SecurityException("No way");
}
}
}
}