0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.script.javascript;
0N/A
0N/Aimport java.util.*;
0N/Aimport sun.org.mozilla.javascript.internal.*;
0N/A
0N/A/**
0N/A * This class prevents script access to certain sensitive classes.
0N/A * Note that this class checks over and above SecurityManager. i.e., although
0N/A * a SecurityManager would pass, class shutter may still prevent access.
0N/A *
0N/A * @author A. Sundararajan
0N/A * @since 1.6
0N/A */
0N/Afinal class RhinoClassShutter implements ClassShutter {
0N/A private static Map<String, Boolean> protectedClasses;
0N/A private static RhinoClassShutter theInstance;
0N/A
0N/A private RhinoClassShutter() {
0N/A }
0N/A
0N/A static synchronized ClassShutter getInstance() {
0N/A if (theInstance == null) {
0N/A theInstance = new RhinoClassShutter();
0N/A protectedClasses = new HashMap<String, Boolean>();
0N/A
0N/A // For now, we just have AccessController. Allowing scripts
0N/A // to this class will allow it to execute doPrivileged in
0N/A // bootstrap context. We can add more classes for other reasons.
0N/A protectedClasses.put("java.security.AccessController", Boolean.TRUE);
0N/A }
0N/A return theInstance;
0N/A }
0N/A
0N/A public boolean visibleToScripts(String fullClassName) {
0N/A // first do the security check.
0N/A SecurityManager sm = System.getSecurityManager();
0N/A if (sm != null) {
0N/A int i = fullClassName.lastIndexOf(".");
0N/A if (i != -1) {
0N/A try {
0N/A sm.checkPackageAccess(fullClassName.substring(0, i));
0N/A } catch (SecurityException se) {
0N/A return false;
0N/A }
0N/A }
0N/A }
0N/A // now, check is it a protected class.
0N/A return protectedClasses.get(fullClassName) == null;
0N/A }
0N/A}