src/jdk.attach/share/classes/com/sun/tools/attach/AttachPermission.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46896 jdk/src/jdk.attach/share/classes/com/sun/tools/attach/AttachPermission.java@161d696f4ff4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45130
469dceb426cc 8179631: Fix Html5 errors in java.management, jdk.management, jdk.jdi and jdk.attach
ksrini
parents: 34894
diff changeset
     2
 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.attach;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * When a {@link java.lang.SecurityManager SecurityManager} set, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * is the permission which will be checked when code invokes {@link
46896
161d696f4ff4 8168677: Typo in API docs for com.sun.tools.attach
hseigel
parents: 46048
diff changeset
    31
 * VirtualMachine#attach VirtualMachine.attach} to attach to a target virtual
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This permission is also checked when an {@link
30797
9cf3d0361db4 8040147: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    34
 * com.sun.tools.attach.spi.AttachProvider AttachProvider} is created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p> An <code>AttachPermission</code> object contains a name (also referred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * to as a "target name") but no actions list; you either have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * named permission or you don't.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The following table provides a summary description of what the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * permission allows, and discusses the risks of granting code the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * permission.
30797
9cf3d0361db4 8040147: minor cleanup for docs
avstepan
parents: 25859
diff changeset
    42
 *
45130
469dceb426cc 8179631: Fix Html5 errors in java.management, jdk.management, jdk.jdi and jdk.attach
ksrini
parents: 34894
diff changeset
    43
 * <table class="striped"><caption style="display:none">Table shows permission
469dceb426cc 8179631: Fix Html5 errors in java.management, jdk.management, jdk.jdi and jdk.attach
ksrini
parents: 34894
diff changeset
    44
 * target name, what the permission allows, and associated risks</caption>
46048
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    45
 * <thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <tr>
46048
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    47
 * <th scope="col">Permission Target Name</th>
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    48
 * <th scope="col">What the Permission Allows</th>
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    49
 * <th scope="col">Risks of Allowing this Permission</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * </tr>
46048
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    51
 * </thead>
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    52
 * <tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <tr>
46048
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    54
 *   <th scope="row">attachVirtualMachine</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *   <td>Ability to attach to another Java virtual machine and load agents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *       into that VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   <td>This allows an attacker to control the target VM which can potentially
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *       cause it to misbehave.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *   </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <tr>
46048
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    64
 *   <th scope="row">createAttachProvider</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   <td>Ability to create an <code>AttachProvider</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *   <td>This allows an attacker to create an AttachProvider which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *       potentially be used to attach to other Java virtual machines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </tr>
46048
00b5dc9d9be5 8185588: jdk.attach API has accessibility issues
jjg
parents: 45130
diff changeset
    71
 * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Programmers do not normally create AttachPermission objects directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Instead they are created by the security policy code based on reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * the security policy file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see com.sun.tools.attach.VirtualMachine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see com.sun.tools.attach.spi.AttachProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public final class AttachPermission extends java.security.BasicPermission {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /** use serialVersionUID for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    static final long serialVersionUID = -4619447669752976181L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Constructs a new AttachPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param name Permission name. Must be either "attachVirtualMachine",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *             or "createAttachProvider".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @throws NullPointerException if name is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @throws IllegalArgumentException if the name is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public AttachPermission(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (!name.equals("attachVirtualMachine") && !name.equals("createAttachProvider")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            throw new IllegalArgumentException("name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Constructs a new AttachPermission object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param name Permission name.   Must be either "attachVirtualMachine",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *             or "createAttachProvider".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param actions Not used and should be <code>null</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *                the empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @throws NullPointerException if name is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @throws IllegalArgumentException if arguments are invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public AttachPermission(String name, String actions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (!name.equals("attachVirtualMachine") && !name.equals("createAttachProvider")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new IllegalArgumentException("name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (actions != null && actions.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new IllegalArgumentException("actions: " + actions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}