Path: blob/master/src/java.base/share/classes/java/nio/file/LinkPermission.java
41159 views
/*1* Copyright (c) 2007, 2019, 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 java.nio.file;2627import java.security.BasicPermission;2829/**30* The {@code Permission} class for link creation operations.31*32* <p> The following table provides a summary description of what the permission33* allows, and discusses the risks of granting code the permission.34*35* <table class="striped">36* <caption style="display:none">Table shows permission target name, what the permission allows, and associated risks</caption>37* <thead>38* <tr>39* <th scope="col">Permission Target Name</th>40* <th scope="col">What the Permission Allows</th>41* <th scope="col">Risks of Allowing this Permission</th>42* </tr>43* </thead>44* <tbody>45* <tr>46* <th scope="row">hard</th>47* <td> Ability to add an existing file to a directory. This is sometimes48* known as creating a link, or hard link. </td>49* <td> Extreme care should be taken when granting this permission. It allows50* linking to any file or directory in the file system thus allowing the51* attacker access to all files. </td>52* </tr>53* <tr>54* <th scope="row">symbolic</th>55* <td> Ability to create symbolic links. </td>56* <td> Extreme care should be taken when granting this permission. It allows57* linking to any file or directory in the file system thus allowing the58* attacker to access to all files. </td>59* </tr>60* </tbody>61* </table>62*63* @since 1.764*65* @see Files#createLink66* @see Files#createSymbolicLink67*/68public final class LinkPermission extends BasicPermission {69@java.io.Serial70static final long serialVersionUID = -1441492453772213220L;7172private void checkName(String name) {73if (!name.equals("hard") && !name.equals("symbolic")) {74throw new IllegalArgumentException("name: " + name);75}76}7778/**79* Constructs a {@code LinkPermission} with the specified name.80*81* @param name82* the name of the permission. It must be "hard" or "symbolic".83*84* @throws IllegalArgumentException85* if name is empty or invalid86*/87public LinkPermission(String name) {88super(name);89checkName(name);90}9192/**93* Constructs a {@code LinkPermission} with the specified name.94*95* @param name96* the name of the permission; must be "hard" or "symbolic".97* @param actions98* the actions for the permission; must be the empty string or99* {@code null}100*101* @throws IllegalArgumentException102* if name is empty or invalid, or actions is a non-empty string103*/104public LinkPermission(String name, String actions) {105super(name);106checkName(name);107if (actions != null && !actions.isEmpty()) {108throw new IllegalArgumentException("actions: " + actions);109}110}111}112113114