Path: blob/master/src/jdk.attach/share/classes/com/sun/tools/attach/AttachPermission.java
40948 views
/*1* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.attach;2627/**28* When a {@link java.lang.SecurityManager SecurityManager} set, this29* is the permission which will be checked when code invokes {@link30* VirtualMachine#attach VirtualMachine.attach} to attach to a target virtual31* machine.32* This permission is also checked when an {@link33* com.sun.tools.attach.spi.AttachProvider AttachProvider} is created.34*35* <p> An <code>AttachPermission</code> object contains a name (also referred36* to as a "target name") but no actions list; you either have the37* named permission or you don't.38* The following table provides a summary description of what the39* permission allows, and discusses the risks of granting code the40* permission.41*42* <table class="striped"><caption style="display:none">Table shows permission43* target name, what the permission allows, and associated risks</caption>44* <thead>45* <tr>46* <th scope="col">Permission Target Name</th>47* <th scope="col">What the Permission Allows</th>48* <th scope="col">Risks of Allowing this Permission</th>49* </tr>50* </thead>51* <tbody>52* <tr>53* <th scope="row">attachVirtualMachine</th>54* <td>Ability to attach to another Java virtual machine and load agents55* into that VM.56* </td>57* <td>This allows an attacker to control the target VM which can potentially58* cause it to misbehave.59* </td>60* </tr>61*62* <tr>63* <th scope="row">createAttachProvider</th>64* <td>Ability to create an <code>AttachProvider</code> instance.65* </td>66* <td>This allows an attacker to create an AttachProvider which can67* potentially be used to attach to other Java virtual machines.68* </td>69* </tr>70* </tbody>71*72* </table>7374* <p>75* Programmers do not normally create AttachPermission objects directly.76* Instead they are created by the security policy code based on reading77* the security policy file.78*79* @see com.sun.tools.attach.VirtualMachine80* @see com.sun.tools.attach.spi.AttachProvider81*/8283public final class AttachPermission extends java.security.BasicPermission {8485/** use serialVersionUID for interoperability */86static final long serialVersionUID = -4619447669752976181L;8788/**89* Constructs a new AttachPermission object.90*91* @param name Permission name. Must be either "attachVirtualMachine",92* or "createAttachProvider".93*94* @throws NullPointerException if name is <code>null</code>.95* @throws IllegalArgumentException if the name is invalid.96*/97public AttachPermission(String name) {98super(name);99if (!name.equals("attachVirtualMachine") && !name.equals("createAttachProvider")) {100throw new IllegalArgumentException("name: " + name);101}102}103104/**105* Constructs a new AttachPermission object.106*107* @param name Permission name. Must be either "attachVirtualMachine",108* or "createAttachProvider".109*110* @param actions Not used and should be <code>null</code>, or111* the empty string.112*113* @throws NullPointerException if name is <code>null</code>.114* @throws IllegalArgumentException if arguments are invalid.115*/116public AttachPermission(String name, String actions) {117super(name);118if (!name.equals("attachVirtualMachine") && !name.equals("createAttachProvider")) {119throw new IllegalArgumentException("name: " + name);120}121if (actions != null && actions.length() > 0) {122throw new IllegalArgumentException("actions: " + actions);123}124}125}126127128