Showing the changes to java/pkg/java/nio/file/LinkPermission.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,107 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.nio.file; | ||
| 27 | |||
| 28 | import java.security.BasicPermission; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * The {@code Permission} class for link creation operations. | ||
| 32 | * | ||
| 33 | * <p> The following table provides a summary description of what the permission | ||
| 34 | * allows, and discusses the risks of granting code the permission. | ||
| 35 | * | ||
| 36 | * <table border=1 cellpadding=5 | ||
| 37 | * summary="Table shows permission target name, what the permission allows, and associated risks"> | ||
| 38 | * <tr> | ||
| 39 | * <th>Permission Target Name</th> | ||
| 40 | * <th>What the Permission Allows</th> | ||
| 41 | * <th>Risks of Allowing this Permission</th> | ||
| 42 | * </tr> | ||
| 43 | * <tr> | ||
| 44 | * <td>hard</td> | ||
| 45 | * <td> Ability to add an existing file to a directory. This is sometimes | ||
| 46 | * known as creating a link, or hard link. </td> | ||
| 47 | * <td> Extreme care should be taken when granting this permission. It allows | ||
| 48 | * linking to any file or directory in the file system thus allowing the | ||
| 49 | * attacker access to all files. </td> | ||
| 50 | * </tr> | ||
| 51 | * <tr> | ||
| 52 | * <td>symbolic</td> | ||
| 53 | * <td> Ability to create symbolic links. </td> | ||
| 54 | * <td> Extreme care should be taken when granting this permission. It allows | ||
| 55 | * linking to any file or directory in the file system thus allowing the | ||
| 56 | * attacker to access to all files. </td> | ||
| 57 | * </tr> | ||
| 58 | * </table> | ||
| 59 | * | ||
| 60 | * @since 1.7 | ||
| 61 | * | ||
| 62 | * @see Files#createLink | ||
| 63 | * @see Files#createSymbolicLink | ||
| 64 | */ | ||
| 65 | public final class LinkPermission extends BasicPermission { | ||
| 66 | static final long serialVersionUID = -1441492453772213220L; | ||
| 67 | |||
| 68 | private void checkName(String name) { | ||
| 69 | if (!name.equals("hard") && !name.equals("symbolic")) { | ||
| 70 | throw new IllegalArgumentException("name: " + name); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Constructs a {@code LinkPermission} with the specified name. | ||
| 76 | * | ||
| 77 | * @param name | ||
| 78 | * the name of the permission. It must be "hard" or "symbolic". | ||
| 79 | * | ||
| 80 | * @throws IllegalArgumentException | ||
| 81 | * if name is empty or invalid | ||
| 82 | */ | ||
| 83 | public LinkPermission(String name) { | ||
| 84 | super(name); | ||
| 85 | checkName(name); | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Constructs a {@code LinkPermission} with the specified name. | ||
| 90 | * | ||
| 91 | * @param name | ||
| 92 | * the name of the permission; must be "hard" or "symbolic". | ||
| 93 | * @param actions | ||
| 94 | * the actions for the permission; must be the empty string or | ||
| 95 | * {@code null} | ||
| 96 | * | ||
| 97 | * @throws IllegalArgumentException | ||
| 98 | * if name is empty or invalid, or actions is a non-empty string | ||
| 99 | */ | ||
| 100 | public LinkPermission(String name, String actions) { | ||
| 101 | super(name); | ||
| 102 | checkName(name); | ||
| 103 | if (actions != null && actions.length() > 0) { | ||
| 104 | throw new IllegalArgumentException("actions: " + actions); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||