src/java.desktop/share/classes/sun/applet/AppletSecurity.java
author mullan
Wed, 04 Apr 2018 11:26:10 -0400
changeset 49520 7a64b48586d8
parent 48027 ddbcfca4d51d
permissions -rw-r--r--
8193032: Remove terminally deprecated SecurityManager APIs Summary: Remove the checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess, and checkMemberAccess methods. Reviewed-by: alanb, mchung, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49520
7a64b48586d8 8193032: Remove terminally deprecated SecurityManager APIs
mullan
parents: 48027
diff changeset
     2
 * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.net.SocketPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.lang.reflect.*;
41596
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    43
import jdk.internal.misc.JavaNetURLClassLoaderAccess;
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    44
import jdk.internal.misc.JavaSecurityAccess;
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    45
import jdk.internal.misc.SharedSecrets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.awt.AWTSecurityManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.awt.AppContext;
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21278
diff changeset
    48
import sun.awt.AWTPermissions;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
48027
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
    51
import static java.lang.StackWalker.*;
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
    52
import static java.lang.StackWalker.Option.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
41596
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    54
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * This class defines an applet security policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
class AppletSecurity extends AWTSecurityManager {
41596
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    61
    private static final JavaNetURLClassLoaderAccess JNUCLA
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    62
            = SharedSecrets.getJavaNetURLClassLoaderAccess();
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
    63
    private static final JavaSecurityAccess JSA = SharedSecrets.getJavaSecurityAccess();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Construct and initialize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public AppletSecurity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // Cache to store known restricted packages
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
    73
    private HashSet<String> restrictedPackages = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Reset from Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public void reset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        // Clear cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        restrictedPackages.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
    83
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            public Object run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                // Enumerate system properties
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
    87
                Enumeration<?> e = System.getProperties().propertyNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                while (e.hasMoreElements())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    String name = (String) e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    if (name != null && name.startsWith("package.restrict.access."))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        String value = System.getProperty(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                        if (value != null && value.equalsIgnoreCase("true"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                            String pkg = name.substring(24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                            // Cache restricted packages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                            restrictedPackages.add(pkg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
48027
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   111
    private static final StackWalker walker =
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   112
        AccessController.doPrivileged(
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   113
            (PrivilegedAction<StackWalker>) () ->
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   114
                StackWalker.getInstance(RETAIN_CLASS_REFERENCE));
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   115
    /**
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   116
     * Returns the class loader of the most recently executing method from
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   117
     * a class defined using a non-system class loader. A non-system
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   118
     * class loader is defined as being a class loader that is not equal to
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   119
     * the system class loader (as returned
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   120
     * by {@link ClassLoader#getSystemClassLoader}) or one of its ancestors.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   121
     * <p>
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   122
     * This method will return
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   123
     * <code>null</code> in the following three cases:
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   124
     * <ol>
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   125
     *   <li>All methods on the execution stack are from classes
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   126
     *   defined using the system class loader or one of its ancestors.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   127
     *
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   128
     *   <li>All methods on the execution stack up to the first
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   129
     *   "privileged" caller
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   130
     *   (see {@link java.security.AccessController#doPrivileged})
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   131
     *   are from classes
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   132
     *   defined using the system class loader or one of its ancestors.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   133
     *
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   134
     *   <li> A call to <code>checkPermission</code> with
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   135
     *   <code>java.security.AllPermission</code> does not
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   136
     *   result in a SecurityException.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   137
     * </ol>
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   138
     *
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   139
     * NOTE: This is an implementation of the SecurityManager.currentClassLoader
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   140
     * method that uses StackWalker. SecurityManager.currentClassLoader
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   141
     * has been removed from SE. This is a temporary workaround which is
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   142
     * only needed while applets are still supported.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   143
     *
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   144
     * @return  the class loader of the most recent occurrence on the stack
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   145
     *          of a method from a class defined using a non-system class
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   146
     *          loader.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   147
     */
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   148
    private static ClassLoader currentClassLoader() {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   149
        StackFrame f =
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   150
            walker.walk(s -> s.takeWhile(AppletSecurity::isNonPrivileged)
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   151
                              .filter(AppletSecurity::isNonSystemFrame)
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   152
                              .findFirst())
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   153
                  .orElse(null);
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   154
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   155
        SecurityManager sm = System.getSecurityManager();
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   156
        if (f != null && sm != null) {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   157
            try {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   158
                sm.checkPermission(new AllPermission());
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   159
            } catch (SecurityException se) {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   160
                return f.getDeclaringClass().getClassLoader();
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   161
            }
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   162
        }
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   163
        return null;
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   164
    }
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   165
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   166
    /**
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   167
     * Returns true if the StackFrame is not AccessController.doPrivileged.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   168
     */
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   169
    private static boolean isNonPrivileged(StackFrame f) {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   170
        // possibly other doPrivileged variants
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   171
        Class<?> c = f.getDeclaringClass();
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   172
        return c == AccessController.class &&
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   173
               f.getMethodName().equals("doPrivileged");
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   174
    }
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   175
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   176
    /**
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   177
     * Returns true if the StackFrame is not from a class defined by the
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   178
     * system class loader or one of its ancestors.
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   179
     */
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   180
    private static boolean isNonSystemFrame(StackFrame f) {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   181
        ClassLoader loader = ClassLoader.getSystemClassLoader();
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   182
        ClassLoader ld = f.getDeclaringClass().getClassLoader();
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   183
        if (ld == null || ld == loader) return false;
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   184
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   185
        while ((loader = loader.getParent()) != null) {
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   186
            if (ld == loader)
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   187
                return false;
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   188
        }
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   189
        return true;
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   190
    }
ddbcfca4d51d 8186535: Remove deprecated pre-1.2 SecurityManager methods and fields
mullan
parents: 47216
diff changeset
   191
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * get the current (first) instance of an AppletClassLoader on the stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private AppletClassLoader currentAppletClassLoader()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // try currentClassLoader first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        ClassLoader loader = currentClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if ((loader == null) || (loader instanceof AppletClassLoader))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            return (AppletClassLoader)loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // if that fails, get all the classes on the stack and check them.
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   204
        Class<?>[] context = getClassContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        for (int i = 0; i < context.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            loader = context[i].getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (loader instanceof AppletClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                return (AppletClassLoader)loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * fix bug # 6433620 the logic here is : try to find URLClassLoader from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * class context, check its AccessControlContext to see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * AppletClassLoader is in stack when it's created. for this kind of
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19807
diff changeset
   215
         * URLClassLoader, return the AppContext associated with the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * AppletClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for (int i = 0; i < context.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            final ClassLoader currentLoader = context[i].getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (currentLoader instanceof URLClassLoader) {
41596
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
   222
                URLClassLoader ld = (URLClassLoader)currentLoader;
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   223
                loader = AccessController.doPrivileged(
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   224
                    new PrivilegedAction<ClassLoader>() {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   225
                        public ClassLoader run() {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   226
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   227
                            AccessControlContext acc = null;
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   228
                            ProtectionDomain[] pds = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   230
                            try {
41596
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
   231
                                acc = JNUCLA.getAccessControlContext(ld);
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   232
                                if (acc == null) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   233
                                    return null;
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   234
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
41596
a6382b6ba29d 8165271: Fix use of reflection to gain access to private fields
ddehaven
parents: 36511
diff changeset
   236
                                pds = JSA.getProtectDomains(acc);
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   237
                                if (pds == null) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   238
                                    return null;
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   239
                                }
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   240
                            } catch (Exception e) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   241
                                throw new UnsupportedOperationException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   244
                            for (int i=0; i<pds.length; i++) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   245
                                ClassLoader cl = pds[i].getClassLoader();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   247
                                if (cl instanceof AppletClassLoader) {
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   248
                                        return cl;
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   249
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            }
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   251
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   252
                            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        }
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   254
                    });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                if (loader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    return (AppletClassLoader) loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        // if that fails, try the context class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        loader = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (loader instanceof AppletClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return (AppletClassLoader)loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // no AppletClassLoaders on the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return (AppletClassLoader)null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns true if this threadgroup is in the applet's own thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * group. This will return false if there is no current class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    protected boolean inThreadGroup(ThreadGroup g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (currentAppletClassLoader() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return getThreadGroup().parentOf(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Returns true of the threadgroup of thread is in the applet's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * own threadgroup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    protected boolean inThreadGroup(Thread thread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return inThreadGroup(thread.getThreadGroup());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Applets are not allowed to manipulate threads outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * applet thread groups. However a terminated thread no longer belongs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * to any group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public void checkAccess(Thread t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        /* When multiple applets is reloaded simultaneously, there will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * multiple invocations to this method from plugin's SecurityManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * This method should not be synchronized to avoid deadlock when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * a page with multiple applets is reloaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if ((t.getState() != Thread.State.TERMINATED) && !inThreadGroup(t)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            checkPermission(SecurityConstants.MODIFY_THREAD_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private boolean inThreadGroupCheck = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * Applets are not allowed to manipulate thread groups outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * applet thread groups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public synchronized void checkAccess(ThreadGroup g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (inThreadGroupCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // if we are in a recursive check, it is because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            // inThreadGroup is calling appletLoader.getThreadGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            // in that case, only do the super check, as appletLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            // has a begin/endPrivileged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            checkPermission(SecurityConstants.MODIFY_THREADGROUP_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                inThreadGroupCheck = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                if (!inThreadGroup(g)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    checkPermission(SecurityConstants.MODIFY_THREADGROUP_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                inThreadGroupCheck = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30948
diff changeset
   334
     * Throws a {@code SecurityException} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * calling thread is not allowed to access the package specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30948
diff changeset
   338
     * This method is used by the {@code loadClass} method of class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * loaders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <p>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30948
diff changeset
   341
     * The {@code checkPackageAccess} method for class
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30948
diff changeset
   342
     * {@code SecurityManager}  calls
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30948
diff changeset
   343
     * {@code checkPermission} with the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 30948
diff changeset
   344
     * {@code RuntimePermission("accessClassInPackage."+ pkgname)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 28231
diff changeset
   347
     * @param      pkgname   the package name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @exception  SecurityException  if the caller does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *             permission to access the specified package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public void checkPackageAccess(final String pkgname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        // first see if the VM-wide policy allows access to this package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        super.checkPackageAccess(pkgname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // now check the list of restricted packages
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   358
        for (Iterator<String> iter = restrictedPackages.iterator(); iter.hasNext();)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        {
25768
b10ec9701a7e 8042872: Fix raw and unchecked warnings in sun.applet
henryjen
parents: 24865
diff changeset
   360
            String pkg = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // Prevent matching "sun" and "sunir" even if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            // starts with similar beginning characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if (pkgname.equals(pkg) || pkgname.startsWith(pkg + "."))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                checkPermission(new java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                            ("accessClassInPackage." + pkgname));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Returns the thread group of the applet. We consult the classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * if there is one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public ThreadGroup getThreadGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        /* If any applet code is on the execution stack, we return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
           that applet's ThreadGroup.  Otherwise, we use the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
           behavior. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        AppletClassLoader appletLoader = currentAppletClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        ThreadGroup loaderGroup = (appletLoader == null) ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                          : appletLoader.getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (loaderGroup != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return loaderGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return super.getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    } // getThreadGroup()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      * Get the AppContext corresponding to the current context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      * The default implementation returns null, but this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
      * may be overridden by various SecurityManagers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      * (e.g. AppletSecurity) to index AppContext objects by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      * calling context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
      * @return  the AppContext corresponding to the current context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
      * @see     sun.awt.AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
      * @see     java.lang.SecurityManager
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   401
      * @since   1.2.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public AppContext getAppContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        AppletClassLoader appletLoader = currentAppletClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (appletLoader == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            AppContext context =  appletLoader.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            // context == null when some thread in applet thread group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            // has not been destroyed in AppContext.dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                throw new SecurityException("Applet classloader has invalid AppContext");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
} // class AppletSecurity