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