jdk/src/java.base/share/classes/java/lang/SecurityManager.java
author simonis
Fri, 14 Aug 2015 10:35:45 +0200
changeset 32209 24bb680a1609
parent 31180 316a8c3e572a
child 37363 329dba26ffd2
permissions -rw-r--r--
8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX Reviewed-by: rriggs, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31180
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
     2
 * Copyright (c) 1995, 2015, 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: 3956
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: 3956
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: 3956
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
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 java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.FileDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.PropertyPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.RuntimePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.SocketPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.NetPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16039
diff changeset
    41
import sun.reflect.CallerSensitive;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The security manager is a class that allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * applications to implement a security policy. It allows an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * application to determine, before performing a possibly unsafe or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * sensitive operation, what the operation is and whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * it is being attempted in a security context that allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * operation to be performed. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * application can allow or disallow the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The <code>SecurityManager</code> class contains many methods with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * names that begin with the word <code>check</code>. These methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * are called by various methods in the Java libraries before those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * methods perform certain potentially sensitive operations. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * invocation of such a <code>check</code> method typically looks like this:
21330
7b073d91ba9e 8027062: Fix lint and doclint issues in java.lang.{ClassLoader, ClassValue, SecurityManager}
darcy
parents: 19807
diff changeset
    58
 * <blockquote><pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *         security.check<i>XXX</i>(argument, &nbsp;.&nbsp;.&nbsp;.&nbsp;);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The security manager is thereby given an opportunity to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * completion of the operation by throwing an exception. A security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * manager routine simply returns if the operation is permitted, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * throws a <code>SecurityException</code> if the operation is not
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
    69
 * permitted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The current security manager is set by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>setSecurityManager</code> method in class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <code>System</code>. The current security manager is obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * by the <code>getSecurityManager</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * The special method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * {@link SecurityManager#checkPermission(java.security.Permission)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * determines whether an access request indicated by a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * permission should be granted or denied. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * default implementation calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   AccessController.checkPermission(perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * If a requested access is allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <code>checkPermission</code> returns quietly. If denied, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>SecurityException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * As of Java 2 SDK v1.2, the default implementation of each of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <code>check</code> methods in <code>SecurityManager</code> is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * call the <code>SecurityManager checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * to determine if the calling thread has permission to perform the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * Note that the <code>checkPermission</code> method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * just a single permission argument always performs security checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * within the context of the currently executing thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Sometimes a security check that should be made within a given context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * will actually need to be done from within a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <i>different</i> context (for example, from within a worker thread).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * The {@link SecurityManager#getSecurityContext getSecurityContext} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * and the {@link SecurityManager#checkPermission(java.security.Permission,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * java.lang.Object) checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * method that includes a context argument are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * for this situation. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <code>getSecurityContext</code> method returns a "snapshot"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * of the current calling context. (The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * returns an AccessControlContext object.) A sample call is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *   Object context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *   SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *   if (sm != null) context = sm.getSecurityContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * The <code>checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * that takes a context object in addition to a permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * makes access decisions based on that context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * rather than on that of the current execution thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * Code within a different context can thus call that method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * passing the permission and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * previously-saved context object. A sample call, using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * SecurityManager <code>sm</code> obtained as in the previous example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * is the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *   if (sm != null) sm.checkPermission(permission, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <p>Permissions fall into these categories: File, Socket, Net,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * Security, Runtime, Property, AWT, Reflect, and Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * The classes managing these various
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * permission categories are <code>java.io.FilePermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <code>java.net.SocketPermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <code>java.net.NetPermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <code>java.security.SecurityPermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <code>java.lang.RuntimePermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <code>java.util.PropertyPermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <code>java.awt.AWTPermission</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <code>java.lang.reflect.ReflectPermission</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <code>java.io.SerializablePermission</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <p>All but the first two (FilePermission and SocketPermission) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * subclasses of <code>java.security.BasicPermission</code>, which itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * is an abstract subclass of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * top-level class for permissions, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <code>java.security.Permission</code>. BasicPermission defines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * functionality needed for all permissions that contain a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * that follows the hierarchical property naming convention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * (for example, "exitVM", "setFactory", "queuePrintJob", etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * An asterisk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * may appear at the end of the name, following a ".", or by itself, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * signify a wildcard match. For example: "a.*" or "*" is valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * "*a" or "a*b" is not valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <p>FilePermission and SocketPermission are subclasses of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * top-level class for permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * (<code>java.security.Permission</code>). Classes like these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * that have a more complicated name syntax than that used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * BasicPermission subclass directly from Permission rather than from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * BasicPermission. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * for a <code>java.io.FilePermission</code> object, the permission name is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * the path name of a file (or directory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * <p>Some of the permission classes have an "actions" list that tells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * the actions that are permitted for the object.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * for a <code>java.io.FilePermission</code> object, the actions list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * (such as "read, write") specifies which actions are granted for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * specified file (or for files in the specified directory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <p>Other permission classes are for "named" permissions -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * ones that contain a name but no actions list; you either have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * named permission or you don't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <p>Note: There is also a <code>java.security.AllPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * permission that implies all permissions. It exists to simplify the work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * of system administrators who might need to perform multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * tasks that require all (or numerous) permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * See <a href ="../../../technotes/guides/security/permissions.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * Permissions in the JDK</a> for permission-related information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * This document includes, for example, a table listing the various SecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * <code>check</code> methods and the permission(s) the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * implementation of each such method requires.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * It also contains a table of all the version 1.2 methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * that require permissions, and for each such method tells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * which permission it requires.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * For more information about <code>SecurityManager</code> changes made in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * the JDK and advice regarding porting of 1.1-style security managers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * see the <a href="../../../technotes/guides/security/index.html">security documentation</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * @author  Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * @author  Roland Schemers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * @see     java.lang.ClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * @see     java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * @see     java.lang.System#getSecurityManager() getSecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * @see     java.lang.System#setSecurityManager(java.lang.SecurityManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *  setSecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * @see     java.security.AccessController AccessController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * @see     java.security.AccessControlContext AccessControlContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * @see     java.security.AccessControlException AccessControlException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * @see     java.security.Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * @see     java.security.BasicPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * @see     java.io.FilePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * @see     java.net.SocketPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * @see     java.util.PropertyPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * @see     java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * @see     java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * @see     java.security.Policy Policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * @see     java.security.SecurityPermission SecurityPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * @see     java.security.ProtectionDomain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   219
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
class SecurityManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * This field is <code>true</code> if there is a security check in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * progress; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    protected boolean inCheck;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Have we been initialized. Effective against finalizer attacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private boolean initialized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * returns true if the current context has been granted AllPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
   244
    private boolean hasAllPermission() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            checkPermission(SecurityConstants.ALL_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Tests if there is a security check in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the value of the <code>inCheck</code> field. This field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *          should contain <code>true</code> if a security check is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *          in progress,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see     java.lang.SecurityManager#inCheck
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public boolean getInCheck() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return inCheck;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Constructs a new <code>SecurityManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <p> If there is a security manager already installed, this method first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * calls the security manager's <code>checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * with the <code>RuntimePermission("createSecurityManager")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * permission to ensure the calling thread has permission to create a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * This may result in throwing a <code>SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @exception  java.lang.SecurityException if a security manager already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *             exists and its <code>checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *             doesn't allow creation of a new security manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see        java.lang.System#getSecurityManager()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public SecurityManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        synchronized(SecurityManager.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                // ask the currently installed security manager if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                // can create a new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                sm.checkPermission(new RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                                   ("createSecurityManager"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Returns the current execution stack as an array of classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * The length of the array is the number of methods on the execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * stack. The element at index <code>0</code> is the class of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * currently executing method, the element at index <code>1</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * the class of that method's caller, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return  the execution stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
22116
49bb2cb8cb51 8027063: SecurityManger.getClassContext returns a raw type
darcy
parents: 22060
diff changeset
   310
    protected native Class<?>[] getClassContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Returns the class loader of the most recently executing method from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * a class defined using a non-system class loader. A non-system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * class loader is defined as being a class loader that is not equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * the system class loader (as returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * by {@link ClassLoader#getSystemClassLoader}) or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * This method will return
21330
7b073d91ba9e 8027062: Fix lint and doclint issues in java.lang.{ClassLoader, ClassValue, SecurityManager}
darcy
parents: 19807
diff changeset
   320
     * <code>null</code> in the following three cases:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *   <li>All methods on the execution stack are from classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *   defined using the system class loader or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *   <li>All methods on the execution stack up to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *   "privileged" caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *   (see {@link java.security.AccessController#doPrivileged})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *   are from classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *   defined using the system class loader or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *   <li> A call to <code>checkPermission</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *   <code>java.security.AllPermission</code> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *   result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return  the class loader of the most recent occurrence on the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *          of a method from a class defined using a non-system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see  java.lang.ClassLoader#getSystemClassLoader() getSystemClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see  #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    @Deprecated
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
   349
    protected ClassLoader currentClassLoader() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        ClassLoader cl = currentClassLoader0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if ((cl != null) && hasAllPermission())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            cl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    private native ClassLoader currentClassLoader0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Returns the class of the most recently executing method from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * a class defined using a non-system class loader. A non-system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * class loader is defined as being a class loader that is not equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * the system class loader (as returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * by {@link ClassLoader#getSystemClassLoader}) or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * This method will return
21330
7b073d91ba9e 8027062: Fix lint and doclint issues in java.lang.{ClassLoader, ClassValue, SecurityManager}
darcy
parents: 19807
diff changeset
   366
     * <code>null</code> in the following three cases:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *   <li>All methods on the execution stack are from classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *   defined using the system class loader or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *   <li>All methods on the execution stack up to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *   "privileged" caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *   (see {@link java.security.AccessController#doPrivileged})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *   are from classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *   defined using the system class loader or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *   <li> A call to <code>checkPermission</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *   <code>java.security.AllPermission</code> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *   result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @return  the class  of the most recent occurrence on the stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *          of a method from a class defined using a non-system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *          loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see  java.lang.ClassLoader#getSystemClassLoader() getSystemClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see  #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    protected Class<?> currentLoadedClass() {
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 5506
diff changeset
   396
        Class<?> c = currentLoadedClass0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if ((c != null) && hasAllPermission())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Returns the stack depth of the specified class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @param   name   the fully qualified name of the class to search for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @return  the depth on the stack frame of the first occurrence of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *          method from a class with the specified name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *          <code>-1</code> if such a frame cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    protected native int classDepth(String name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Returns the stack depth of the most recently executing method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * from a class defined using a non-system class loader.  A non-system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * class loader is defined as being a class loader that is not equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * the system class loader (as returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * by {@link ClassLoader#getSystemClassLoader}) or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * This method will return
21330
7b073d91ba9e 8027062: Fix lint and doclint issues in java.lang.{ClassLoader, ClassValue, SecurityManager}
darcy
parents: 19807
diff changeset
   425
     * -1 in the following three cases:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *   <li>All methods on the execution stack are from classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *   defined using the system class loader or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *   <li>All methods on the execution stack up to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *   "privileged" caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *   (see {@link java.security.AccessController#doPrivileged})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *   are from classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *   defined using the system class loader or one of its ancestors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *   <li> A call to <code>checkPermission</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *   <code>java.security.AllPermission</code> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *   result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @return the depth on the stack frame of the most recent occurrence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *          a method from a class defined using a non-system class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see   java.lang.ClassLoader#getSystemClassLoader() getSystemClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see   #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    @Deprecated
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
   453
    protected int classLoaderDepth() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        int depth = classLoaderDepth0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (depth != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (hasAllPermission())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                depth = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                depth--; // make sure we don't include ourself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    private native int classLoaderDepth0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * Tests if a method from a class with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *         name is on the execution stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @param  name   the fully qualified name of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return <code>true</code> if a method from a class with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *         name is on the execution stack; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    protected boolean inClass(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return classDepth(name) >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Basically, tests if a method from a class defined using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *          class loader is on the execution stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @return  <code>true</code> if a call to <code>currentClassLoader</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *          has a non-null return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @deprecated This type of security checking is not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *  It is recommended that the <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *  call be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @see        #currentClassLoader() currentClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    protected boolean inClassLoader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return currentClassLoader() != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Creates an object that encapsulates the current execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * environment. The result of this method is used, for example, by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * three-argument <code>checkConnect</code> method and by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * two-argument <code>checkRead</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * These methods are needed because a trusted method may be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * on to read a file or open a socket on behalf of another method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * The trusted method needs to determine if the other (possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * untrusted) method would be allowed to perform the operation on its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * <p> The default implementation of this method is to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * an <code>AccessControlContext</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @return  an implementation-dependent object that encapsulates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *          sufficient information about the current execution environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *          to perform some security checks later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @see     java.lang.SecurityManager#checkConnect(java.lang.String, int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *   java.lang.Object) checkConnect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @see     java.lang.SecurityManager#checkRead(java.lang.String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *   java.lang.Object) checkRead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @see     java.security.AccessControlContext AccessControlContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public Object getSecurityContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Throws a <code>SecurityException</code> if the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * access, specified by the given permission, is not permitted based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * on the security policy currently in effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * This method calls <code>AccessController.checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * with the given permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @param     perm   the requested permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @exception SecurityException if access is not permitted based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *            the current security policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @exception NullPointerException if the permission argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *            <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @since     1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public void checkPermission(Permission perm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        java.security.AccessController.checkPermission(perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * specified security context is denied access to the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * specified by the given permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * The context must be a security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * context returned by a previous call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * <code>getSecurityContext</code> and the access control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * decision is based upon the configured security policy for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * that security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * If <code>context</code> is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * <code>AccessControlContext</code> then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <code>AccessControlContext.checkPermission</code> method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * invoked with the specified permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * If <code>context</code> is not an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <code>AccessControlContext</code> then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <code>SecurityException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @param      perm      the specified permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @param      context   a system-dependent security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @exception  SecurityException  if the specified security context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *             is not an instance of <code>AccessControlContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *             (e.g., is <code>null</code>), or is denied access to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *             resource specified by the given permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @exception  NullPointerException if the permission argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see        java.lang.SecurityManager#getSecurityContext()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @see java.security.AccessControlContext#checkPermission(java.security.Permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public void checkPermission(Permission perm, Object context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        if (context instanceof AccessControlContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            ((AccessControlContext)context).checkPermission(perm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            throw new SecurityException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * calling thread is not allowed to create a new class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * <code>RuntimePermission("createClassLoader")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <code>super.checkCreateClassLoader</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @exception SecurityException if the calling thread does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *             have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *             to create a new class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @see        java.lang.ClassLoader#ClassLoader()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public void checkCreateClassLoader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        checkPermission(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * reference to the root thread group, used for the checkAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private static ThreadGroup rootGroup = getRootGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    private static ThreadGroup getRootGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        ThreadGroup root =  Thread.currentThread().getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        while (root.getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            root = root.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * calling thread is not allowed to modify the thread argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * This method is invoked for the current security manager by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <code>stop</code>, <code>suspend</code>, <code>resume</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <code>setPriority</code>, <code>setName</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <code>setDaemon</code> methods of class <code>Thread</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * If the thread argument is a system thread (belongs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * the thread group with a <code>null</code> parent) then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * this method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <code>RuntimePermission("modifyThread")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * If the thread argument is <i>not</i> a system thread,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * this method just returns silently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Applications that want a stricter policy should override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * method. If this method is overridden, the method that overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * it should additionally check to see if the calling thread has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * <code>RuntimePermission("modifyThread")</code> permission, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * if so, return silently. This is to ensure that code granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * that permission (such as the JDK itself) is allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * manipulate any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * If this method is overridden, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * <code>super.checkAccess</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * be called by the first statement in the overridden method, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * equivalent security check should be placed in the overridden method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @param      t   the thread to be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *             permission to modify the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @exception  NullPointerException if the thread argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @see        java.lang.Thread#resume() resume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @see        java.lang.Thread#setDaemon(boolean) setDaemon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @see        java.lang.Thread#setName(java.lang.String) setName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @see        java.lang.Thread#setPriority(int) setPriority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see        java.lang.Thread#stop() stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @see        java.lang.Thread#suspend() suspend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public void checkAccess(Thread t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if (t == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            throw new NullPointerException("thread can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        if (t.getThreadGroup() == rootGroup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            checkPermission(SecurityConstants.MODIFY_THREAD_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            // just return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * calling thread is not allowed to modify the thread group argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * This method is invoked for the current security manager when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * new child thread or child thread group is created, and by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <code>setDaemon</code>, <code>setMaxPriority</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <code>stop</code>, <code>suspend</code>, <code>resume</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * <code>destroy</code> methods of class <code>ThreadGroup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * If the thread group argument is the system thread group (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * has a <code>null</code> parent) then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * this method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * <code>RuntimePermission("modifyThreadGroup")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * If the thread group argument is <i>not</i> the system thread group,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * this method just returns silently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Applications that want a stricter policy should override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * method. If this method is overridden, the method that overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * it should additionally check to see if the calling thread has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <code>RuntimePermission("modifyThreadGroup")</code> permission, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * if so, return silently. This is to ensure that code granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * that permission (such as the JDK itself) is allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * manipulate any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * If this method is overridden, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <code>super.checkAccess</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * be called by the first statement in the overridden method, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * equivalent security check should be placed in the overridden method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @param      g   the thread group to be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *             permission to modify the thread group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @exception  NullPointerException if the thread group argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @see        java.lang.ThreadGroup#destroy() destroy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @see        java.lang.ThreadGroup#resume() resume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @see        java.lang.ThreadGroup#setDaemon(boolean) setDaemon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @see        java.lang.ThreadGroup#setMaxPriority(int) setMaxPriority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @see        java.lang.ThreadGroup#stop() stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @see        java.lang.ThreadGroup#suspend() suspend
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    public void checkAccess(ThreadGroup g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (g == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            throw new NullPointerException("thread group can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        if (g == rootGroup) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            checkPermission(SecurityConstants.MODIFY_THREADGROUP_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            // just return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * calling thread is not allowed to cause the Java Virtual Machine to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * halt with the specified status code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * This method is invoked for the current security manager by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * <code>exit</code> method of class <code>Runtime</code>. A status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * of <code>0</code> indicates success; other values indicate various
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * <code>RuntimePermission("exitVM."+status)</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * <code>super.checkExit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @param      status   the exit status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @exception SecurityException if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *              permission to halt the Java Virtual Machine with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *              the specified status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @see        java.lang.Runtime#exit(int) exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    public void checkExit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        checkPermission(new RuntimePermission("exitVM."+status));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * calling thread is not allowed to create a subprocess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * This method is invoked for the current security manager by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * <code>exec</code> methods of class <code>Runtime</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * <code>FilePermission(cmd,"execute")</code> permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * if cmd is an absolute path, otherwise it calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * <code>checkPermission</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * <code>FilePermission("&lt;&lt;ALL FILES&gt;&gt;","execute")</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * <code>super.checkExec</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @param      cmd   the specified system command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @exception  SecurityException if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     *             permission to create a subprocess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @exception  NullPointerException if the <code>cmd</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @see     java.lang.Runtime#exec(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @see     java.lang.Runtime#exec(java.lang.String, java.lang.String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @see     java.lang.Runtime#exec(java.lang.String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @see     java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @see     #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    public void checkExec(String cmd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        File f = new File(cmd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (f.isAbsolute()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            checkPermission(new FilePermission(cmd,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                SecurityConstants.FILE_EXECUTE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            checkPermission(new FilePermission("<<ALL FILES>>",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                SecurityConstants.FILE_EXECUTE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * calling thread is not allowed to dynamic link the library code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * specified by the string argument file. The argument is either a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * simple library name or a complete filename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * This method is invoked for the current security manager by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * methods <code>load</code> and <code>loadLibrary</code> of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * <code>Runtime</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * <code>RuntimePermission("loadLibrary."+lib)</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * <code>super.checkLink</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @param      lib   the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @exception  SecurityException if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *             permission to dynamically link the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @exception  NullPointerException if the <code>lib</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @see        java.lang.Runtime#load(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @see        java.lang.Runtime#loadLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    public void checkLink(String lib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        if (lib == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            throw new NullPointerException("library can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        checkPermission(new RuntimePermission("loadLibrary."+lib));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * calling thread is not allowed to read from the specified file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <code>RuntimePermission("readFileDescriptor")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * <code>super.checkRead</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @param      fd   the system-dependent file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *             permission to access the specified file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @exception  NullPointerException if the file descriptor argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @see        java.io.FileDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    public void checkRead(FileDescriptor fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        if (fd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            throw new NullPointerException("file descriptor can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        checkPermission(new RuntimePermission("readFileDescriptor"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * calling thread is not allowed to read the file specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * <code>FilePermission(file,"read")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * <code>super.checkRead</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @param      file   the system-dependent file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @exception  SecurityException if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *             permission to access the specified file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @exception  NullPointerException if the <code>file</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    public void checkRead(String file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        checkPermission(new FilePermission(file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            SecurityConstants.FILE_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * specified security context is not allowed to read the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * specified by the string argument. The context must be a security
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * context returned by a previous call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * <code>getSecurityContext</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * <p> If <code>context</code> is an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * <code>AccessControlContext</code> then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <code>AccessControlContext.checkPermission</code> method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * be invoked with the <code>FilePermission(file,"read")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * <p> If <code>context</code> is not an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * <code>AccessControlContext</code> then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * <code>SecurityException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * <code>super.checkRead</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @param      file      the system-dependent filename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * @param      context   a system-dependent security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @exception  SecurityException  if the specified security context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *             is not an instance of <code>AccessControlContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *             (e.g., is <code>null</code>), or does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *             to read the specified file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @exception  NullPointerException if the <code>file</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @see        java.lang.SecurityManager#getSecurityContext()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @see        java.security.AccessControlContext#checkPermission(java.security.Permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public void checkRead(String file, Object context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        checkPermission(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            new FilePermission(file, SecurityConstants.FILE_READ_ACTION),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * calling thread is not allowed to write to the specified file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * <code>RuntimePermission("writeFileDescriptor")</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * <code>super.checkWrite</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @param      fd   the system-dependent file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @exception SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     *             permission to access the specified file descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @exception  NullPointerException if the file descriptor argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @see        java.io.FileDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    public void checkWrite(FileDescriptor fd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (fd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            throw new NullPointerException("file descriptor can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        checkPermission(new RuntimePermission("writeFileDescriptor"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * calling thread is not allowed to write to the file specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * the string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * <code>FilePermission(file,"write")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * <code>super.checkWrite</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @param      file   the system-dependent filename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @exception  SecurityException  if the calling thread does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     *             have permission to access the specified file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * @exception  NullPointerException if the <code>file</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    public void checkWrite(String file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        checkPermission(new FilePermission(file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            SecurityConstants.FILE_WRITE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * calling thread is not allowed to delete the specified file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * This method is invoked for the current security manager by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * <code>delete</code> method of class <code>File</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * <code>FilePermission(file,"delete")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * <code>super.checkDelete</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @param      file   the system-dependent filename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @exception  SecurityException if the calling thread does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *             have permission to delete the file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @exception  NullPointerException if the <code>file</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * @see        java.io.File#delete()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public void checkDelete(String file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        checkPermission(new FilePermission(file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            SecurityConstants.FILE_DELETE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * calling thread is not allowed to open a socket connection to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * specified host and port number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * A port number of <code>-1</code> indicates that the calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * method is attempting to determine the IP address of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * host name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * <code>SocketPermission(host+":"+port,"connect")</code> permission if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * the port is not equal to -1. If the port is equal to -1, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * it calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * <code>SocketPermission(host,"resolve")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * <code>super.checkConnect</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * @param      host   the host name port to connect to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @param      port   the protocol port to connect to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *             permission to open a socket connection to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     *               <code>host</code> and <code>port</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @exception  NullPointerException if the <code>host</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    public void checkConnect(String host, int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        if (host == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            throw new NullPointerException("host can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        if (!host.startsWith("[") && host.indexOf(':') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            host = "[" + host + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        if (port == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            checkPermission(new SocketPermission(host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                SecurityConstants.SOCKET_RESOLVE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            checkPermission(new SocketPermission(host+":"+port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                SecurityConstants.SOCKET_CONNECT_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * specified security context is not allowed to open a socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * connection to the specified host and port number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * A port number of <code>-1</code> indicates that the calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * method is attempting to determine the IP address of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * host name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * <p> If <code>context</code> is not an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * <code>AccessControlContext</code> then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * <code>SecurityException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * Otherwise, the port number is checked. If it is not equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * to -1, the <code>context</code>'s <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * method is called with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * <code>SocketPermission(host+":"+port,"connect")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * If the port is equal to -1, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * the <code>context</code>'s <code>checkPermission</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * is called with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * <code>SocketPermission(host,"resolve")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * <code>super.checkConnect</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @param      host      the host name port to connect to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @param      port      the protocol port to connect to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @param      context   a system-dependent security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @exception  SecurityException if the specified security context
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     *             is not an instance of <code>AccessControlContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     *             (e.g., is <code>null</code>), or does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     *             to open a socket connection to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     *             <code>host</code> and <code>port</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * @exception  NullPointerException if the <code>host</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * @see        java.lang.SecurityManager#getSecurityContext()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @see        java.security.AccessControlContext#checkPermission(java.security.Permission)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    public void checkConnect(String host, int port, Object context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (host == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            throw new NullPointerException("host can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        if (!host.startsWith("[") && host.indexOf(':') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            host = "[" + host + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (port == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            checkPermission(new SocketPermission(host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                SecurityConstants.SOCKET_RESOLVE_ACTION),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            checkPermission(new SocketPermission(host+":"+port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                SecurityConstants.SOCKET_CONNECT_ACTION),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * calling thread is not allowed to wait for a connection request on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * the specified local port number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * <p>
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 21330
diff changeset
  1109
     * This method calls <code>checkPermission</code> with the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * <code>SocketPermission("localhost:"+port,"listen")</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * <code>super.checkListen</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @param      port   the local port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *             permission to listen on the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    public void checkListen(int port) {
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 21330
diff changeset
  1123
        checkPermission(new SocketPermission("localhost:"+port,
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 21330
diff changeset
  1124
            SecurityConstants.SOCKET_LISTEN_ACTION));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * calling thread is not permitted to accept a socket connection from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * the specified host and port number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * This method is invoked for the current security manager by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * <code>accept</code> method of class <code>ServerSocket</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * <code>SocketPermission(host+":"+port,"accept")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * <code>super.checkAccept</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @param      host   the host name of the socket connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @param      port   the port number of the socket connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *             permission to accept the connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @exception  NullPointerException if the <code>host</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @see        java.net.ServerSocket#accept()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    public void checkAccept(String host, int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        if (host == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            throw new NullPointerException("host can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        if (!host.startsWith("[") && host.indexOf(':') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            host = "[" + host + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        checkPermission(new SocketPermission(host+":"+port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            SecurityConstants.SOCKET_ACCEPT_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * calling thread is not allowed to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * (join/leave/send/receive) IP multicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * <code>java.net.SocketPermission(maddr.getHostAddress(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * "accept,connect")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * <code>super.checkMulticast</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @param      maddr  Internet group address to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @exception  SecurityException  if the calling thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *  use (join/leave/send/receive) IP multicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @exception  NullPointerException if the address argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *             <code>null</code>.
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1182
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    public void checkMulticast(InetAddress maddr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        String host = maddr.getHostAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        if (!host.startsWith("[") && host.indexOf(':') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            host = "[" + host + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        checkPermission(new SocketPermission(host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * calling thread is not allowed to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * (join/leave/send/receive) IP multicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * <code>java.net.SocketPermission(maddr.getHostAddress(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * "accept,connect")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * <code>super.checkMulticast</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @param      maddr  Internet group address to be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @param      ttl        value in use, if it is multicast send.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * Note: this particular implementation does not use the ttl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * @exception  SecurityException  if the calling thread is not allowed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     *  use (join/leave/send/receive) IP multicast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * @exception  NullPointerException if the address argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *             <code>null</code>.
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1216
     * @since      1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * @deprecated Use #checkPermission(java.security.Permission) instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    public void checkMulticast(InetAddress maddr, byte ttl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        String host = maddr.getHostAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if (!host.startsWith("[") && host.indexOf(':') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            host = "[" + host + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        checkPermission(new SocketPermission(host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * calling thread is not allowed to access or modify the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * This method is used by the <code>getProperties</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * <code>setProperties</code> methods of class <code>System</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * <code>PropertyPermission("*", "read,write")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * <code>super.checkPropertiesAccess</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *             permission to access or modify the system properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * @see        java.lang.System#getProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @see        java.lang.System#setProperties(java.util.Properties)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    public void checkPropertiesAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        checkPermission(new PropertyPermission("*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            SecurityConstants.PROPERTY_RW_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * calling thread is not allowed to access the system property with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * the specified <code>key</code> name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * This method is used by the <code>getProperty</code> method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * class <code>System</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * <code>PropertyPermission(key, "read")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * <code>super.checkPropertyAccess</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * @param      key   a system property key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     *             permission to access the specified system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * @exception  NullPointerException if the <code>key</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * @exception  IllegalArgumentException if <code>key</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * @see        java.lang.System#getProperty(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    public void checkPropertyAccess(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        checkPermission(new PropertyPermission(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            SecurityConstants.PROPERTY_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    /**
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1290
     * Returns {@code true} if the calling thread has {@code AllPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     *
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1292
     * @param      window   not used except to check if it is {@code null}.
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1293
     * @return     {@code true} if the calling thread has {@code AllPermission}.
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1294
     * @exception  NullPointerException if the {@code window} argument is
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1295
     *             {@code null}.
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1296
     * @deprecated This method was originally used to check if the calling thread
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1297
     *             was trusted to bring up a top-level window. The method has been
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1298
     *             obsoleted and code should instead use {@link #checkPermission}
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1299
     *             to check {@code AWTPermission("showWindowWithoutWarningBanner")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 18766
diff changeset
  1302
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    public boolean checkTopLevelWindow(Object window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        if (window == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            throw new NullPointerException("window can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1307
        return hasAllPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     * calling thread is not allowed to initiate a print job request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * This method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * <code>RuntimePermission("queuePrintJob")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * <code>super.checkPrintJobAccess</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *             permission to initiate a print job request.
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1325
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    public void checkPrintJobAccess() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        checkPermission(new RuntimePermission("queuePrintJob"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    /**
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1333
     * Throws {@code SecurityException} if the calling thread does
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1334
     * not have {@code AllPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1336
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * @exception  SecurityException  if the calling thread does not have
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1338
     *             {@code AllPermission}
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1339
     * @deprecated This method was originally used to check if the calling
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1340
     *             thread could access the system clipboard. The method has been
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1341
     *             obsoleted and code should instead use {@link #checkPermission}
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1342
     *             to check {@code AWTPermission("accessClipboard")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     */
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 18766
diff changeset
  1345
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    public void checkSystemClipboardAccess() {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1347
        checkPermission(SecurityConstants.ALL_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    /**
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1351
     * Throws {@code SecurityException} if the calling thread does
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1352
     * not have {@code AllPermission}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1354
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @exception  SecurityException  if the calling thread does not have
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1356
     *             {@code AllPermission}
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1357
     * @deprecated This method was originally used to check if the calling
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1358
     *             thread could access the AWT event queue. The method has been
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1359
     *             obsoleted and code should instead use {@link #checkPermission}
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1360
     *             to check {@code AWTPermission("accessEventQueue")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     */
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 18766
diff changeset
  1363
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    public void checkAwtEventQueueAccess() {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21330
diff changeset
  1365
        checkPermission(SecurityConstants.ALL_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * We have an initial invalid bit (initially false) for the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * variables which tell if the cache is valid.  If the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * java.security.Security property changes via setProperty(), the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * Security class uses reflection to change the variable and thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * invalidate the cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * Locking is handled by synchronization to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * packageAccessLock/packageDefinitionLock objects.  They are only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * used in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * Note that cache invalidation as a result of the property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * happens without using these locks, so there may be a delay between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * when a thread updates the property and when other threads updates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * the cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    private static boolean packageAccessValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    private static String[] packageAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    private static final Object packageAccessLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    private static boolean packageDefinitionValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    private static String[] packageDefinition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    private static final Object packageDefinitionLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    private static String[] getPackages(String p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        String packages[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        if (p != null && !p.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            java.util.StringTokenizer tok =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                new java.util.StringTokenizer(p, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            int n = tok.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                packages = new String[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                while (tok.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    String s = tok.nextToken().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                    packages[i++] = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        if (packages == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            packages = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        return packages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * calling thread is not allowed to access the package specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * This method is used by the <code>loadClass</code> method of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * loaders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * This method first gets a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * restricted packages by obtaining a comma-separated list from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * <code>java.security.Security.getProperty("package.access")</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * and checks to see if <code>pkg</code> starts with or equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * any of the restricted packages. If it does, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * <code>checkPermission</code> gets called with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     * <code>RuntimePermission("accessClassInPackage."+pkg)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * If this method is overridden, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * <code>super.checkPackageAccess</code> should be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * as the first line in the overridden method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * @param      pkg   the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     *             permission to access the specified package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * @exception  NullPointerException if the package name argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     *  loadClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * @see        java.security.Security#getProperty getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    public void checkPackageAccess(String pkg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        if (pkg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            throw new NullPointerException("package name can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
31180
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1450
        String[] restrictedPkgs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        synchronized (packageAccessLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
             * Do we need to update our property array?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            if (!packageAccessValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                String tmpPropertyStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                    AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
  1458
                        new PrivilegedAction<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                            public String run() {
31180
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1460
                                return Security.getProperty("package.access");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                packageAccess = getPackages(tmpPropertyStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                packageAccessValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            // Using a snapshot of packageAccess -- don't care if static field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            // changes afterwards; array contents won't change.
31180
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1470
            restrictedPkgs = packageAccess;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
         * Traverse the list of packages, check for any matches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
         */
31180
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1476
        final int plen = pkg.length();
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1477
        for (String restrictedPkg : restrictedPkgs) {
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1478
            final int rlast = restrictedPkg.length() - 1;
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1479
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1480
            // Optimizations:
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1481
            //
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1482
            // If rlast >= plen then restrictedPkg is longer than pkg by at
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1483
            // least one char. This means pkg cannot start with restrictedPkg,
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1484
            // since restrictedPkg will be longer than pkg.
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1485
            //
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1486
            // Similarly if rlast != plen, then pkg + "." cannot be the same
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1487
            // as restrictedPkg, since pkg + "." will have a different length
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1488
            // than restrictedPkg.
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1489
            //
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1490
            if (rlast < plen && pkg.startsWith(restrictedPkg) ||
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1491
                // The following test is equivalent to
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1492
                // restrictedPkg.equals(pkg + ".") but is noticeably more
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1493
                // efficient:
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1494
                rlast == plen && restrictedPkg.startsWith(pkg) &&
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1495
                restrictedPkg.charAt(rlast) == '.')
316a8c3e572a 8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents: 29986
diff changeset
  1496
            {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                checkPermission(
22581
e868cde95050 8032779: Update code in java.lang to use newer language features
psandoz
parents: 22342
diff changeset
  1498
                    new RuntimePermission("accessClassInPackage." + pkg));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                break;  // No need to continue; only need to check this once
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * calling thread is not allowed to define classes in the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * specified by the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * This method is used by the <code>loadClass</code> method of some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * class loaders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * This method first gets a list of restricted packages by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * obtaining a comma-separated list from a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * <code>java.security.Security.getProperty("package.definition")</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * and checks to see if <code>pkg</code> starts with or equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * any of the restricted packages. If it does, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     * <code>checkPermission</code> gets called with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * <code>RuntimePermission("defineClassInPackage."+pkg)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * If this method is overridden, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * <code>super.checkPackageDefinition</code> should be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * as the first line in the overridden method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     * @param      pkg   the package name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
     *             permission to define classes in the specified package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
     * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
     * @see        java.security.Security#getProperty getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    public void checkPackageDefinition(String pkg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        if (pkg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
            throw new NullPointerException("package name can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        String[] pkgs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        synchronized (packageDefinitionLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
             * Do we need to update our property array?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            if (!packageDefinitionValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                String tmpPropertyStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                    AccessController.doPrivileged(
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
  1545
                        new PrivilegedAction<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                                return java.security.Security.getProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                                    "package.definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                packageDefinition = getPackages(tmpPropertyStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                packageDefinitionValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            // Using a snapshot of packageDefinition -- don't care if static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            // field changes afterwards; array contents won't change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            pkgs = packageDefinition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
         * Traverse the list of packages, check for any matches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
         */
22581
e868cde95050 8032779: Update code in java.lang to use newer language features
psandoz
parents: 22342
diff changeset
  1563
        for (String restrictedPkg : pkgs) {
e868cde95050 8032779: Update code in java.lang to use newer language features
psandoz
parents: 22342
diff changeset
  1564
            if (pkg.startsWith(restrictedPkg) || restrictedPkg.equals(pkg + ".")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                checkPermission(
22581
e868cde95050 8032779: Update code in java.lang to use newer language features
psandoz
parents: 22342
diff changeset
  1566
                    new RuntimePermission("defineClassInPackage." + pkg));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                break; // No need to continue; only need to check this once
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * calling thread is not allowed to set the socket factory used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * <code>ServerSocket</code> or <code>Socket</code>, or the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * handler factory used by <code>URL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * This method calls <code>checkPermission</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * <code>RuntimePermission("setFactory")</code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * <code>super.checkSetFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * @exception  SecurityException  if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     *             permission to specify a socket factory or a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     *             handler factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * @see        java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory) setSocketFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) setSocketImplFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * @see        java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory) setURLStreamHandlerFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    public void checkSetFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        checkPermission(new RuntimePermission("setFactory"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * Throws a <code>SecurityException</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * calling thread is not allowed to access members.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * The default policy is to allow access to PUBLIC members, as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * as access to classes that have the same class loader as the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * In all other cases, this method calls <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * with the <code>RuntimePermission("accessDeclaredMembers")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * </code> permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * If this method is overridden, then a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * <code>super.checkMemberAccess</code> cannot be made,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * as the default implementation of <code>checkMemberAccess</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * relies on the code being checked being at a stack depth of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * 4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * @param clazz the class that reflection is to be performed on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * @param which type of access, PUBLIC or DECLARED.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * @exception  SecurityException if the caller does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     *             permission to access members.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     * @exception  NullPointerException if the <code>clazz</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     *             <code>null</code>.
18766
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1623
     *
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1624
     * @deprecated This method relies on the caller being at a stack depth
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1625
     *             of 4 which is error-prone and cannot be enforced by the runtime.
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1626
     *             Users of this method should instead invoke {@link #checkPermission}
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1627
     *             directly.  This method will be changed in a future release
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1628
     *             to check the permission {@code java.security.AllPermission}.
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1629
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * @see java.lang.reflect.Member
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1631
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     */
18766
28c62f5e9a47 8007035: deprecate public void SecurityManager.checkMemberAccess(Class<?> clazz, int which)
mchung
parents: 16906
diff changeset
  1634
    @Deprecated
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16039
diff changeset
  1635
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
    public void checkMemberAccess(Class<?> clazz, int which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            throw new NullPointerException("class can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        if (which != Member.PUBLIC) {
21330
7b073d91ba9e 8027062: Fix lint and doclint issues in java.lang.{ClassLoader, ClassValue, SecurityManager}
darcy
parents: 19807
diff changeset
  1641
            Class<?> stack[] = getClassContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
             * stack depth of 4 should be the caller of one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
             * methods in java.lang.Class that invoke checkMember
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
             * access. The stack should look like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
             * someCaller                        [3]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
             * java.lang.Class.someReflectionAPI [2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
             * java.lang.Class.checkMemberAccess [1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
             * SecurityManager.checkMemberAccess [0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            if ((stack.length<4) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                (stack[3].getClassLoader() != clazz.getClassLoader())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * Determines whether the permission with the specified permission target
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * name should be granted or denied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
     * <p> If the requested permission is allowed, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * quietly. If denied, a SecurityException is raised.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * <p> This method creates a <code>SecurityPermission</code> object for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * the given permission target name and calls <code>checkPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * <p> See the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * <code>{@link java.security.SecurityPermission}</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * a list of possible permission target names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * <p> If you override this method, then you should make a call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * <code>super.checkSecurityAccess</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * at the point the overridden method would normally throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     * @param target the target name of the <code>SecurityPermission</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
     * @exception SecurityException if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
     * permission for the requested access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
     * @exception NullPointerException if <code>target</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
     * @exception IllegalArgumentException if <code>target</code> is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1687
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     * @see        #checkPermission(java.security.Permission) checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    public void checkSecurityAccess(String target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        checkPermission(new SecurityPermission(target));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 5506
diff changeset
  1694
    private native Class<?> currentLoadedClass0();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * Returns the thread group into which to instantiate any new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * thread being created at the time this is being called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * By default, it returns the thread group of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * thread. This should be overridden by a specific security
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     * manager to return the appropriate thread group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * @return  ThreadGroup that new threads are instantiated into
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
  1704
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * @see     java.lang.ThreadGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
    public ThreadGroup getThreadGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        return Thread.currentThread().getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
}