Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/net/NetPermission.java
38829 views
/*1* Copyright (c) 1997, 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.net;2627import java.security.*;28import java.util.Enumeration;29import java.util.Hashtable;30import java.util.StringTokenizer;3132/**33* This class is for various network permissions.34* A NetPermission contains a name (also referred to as a "target name") but35* no actions list; you either have the named permission36* or you don't.37* <P>38* The target name is the name of the network permission (see below). The naming39* convention follows the hierarchical property naming convention.40* Also, an asterisk41* may appear at the end of the name, following a ".", or by itself, to42* signify a wildcard match. For example: "foo.*" and "*" signify a wildcard43* match, while "*foo" and "a*b" do not.44* <P>45* The following table lists all the possible NetPermission target names,46* and for each provides a description of what the permission allows47* and a discussion of the risks of granting code the permission.48*49* <table border=1 cellpadding=5 summary="Permission target name, what the permission allows, and associated risks">50* <tr>51* <th>Permission Target Name</th>52* <th>What the Permission Allows</th>53* <th>Risks of Allowing this Permission</th>54* </tr>55* <tr>56* <td>allowHttpTrace</td>57* <td>The ability to use the HTTP TRACE method in HttpURLConnection.</td>58* <td>Malicious code using HTTP TRACE could get access to security sensitive59* information in the HTTP headers (such as cookies) that it might not60* otherwise have access to.</td>61* </tr>62*63* <tr>64* <td>getCookieHandler</td>65* <td>The ability to get the cookie handler that processes highly66* security sensitive cookie information for an Http session.</td>67* <td>Malicious code can get a cookie handler to obtain access to68* highly security sensitive cookie information. Some web servers69* use cookies to save user private information such as access70* control information, or to track user browsing habit.</td>71* </tr>72*73* <tr>74* <td>getNetworkInformation</td>75* <td>The ability to retrieve all information about local network interfaces.</td>76* <td>Malicious code can read information about network hardware such as77* MAC addresses, which could be used to construct local IPv6 addresses.</td>78* </tr>79*80* <tr>81* <td>getProxySelector</td>82* <td>The ability to get the proxy selector used to make decisions83* on which proxies to use when making network connections.</td>84* <td>Malicious code can get a ProxySelector to discover proxy85* hosts and ports on internal networks, which could then become86* targets for attack.</td>87* </tr>88*89* <tr>90* <td>getResponseCache</td>91* <td>The ability to get the response cache that provides92* access to a local response cache.</td>93* <td>Malicious code getting access to the local response cache94* could access security sensitive information.</td>95* </tr>96*97* <tr>98* <td>requestPasswordAuthentication</td>99* <td>The ability100* to ask the authenticator registered with the system for101* a password</td>102* <td>Malicious code may steal this password.</td>103* </tr>104*105* <tr>106* <td>setCookieHandler</td>107* <td>The ability to set the cookie handler that processes highly108* security sensitive cookie information for an Http session.</td>109* <td>Malicious code can set a cookie handler to obtain access to110* highly security sensitive cookie information. Some web servers111* use cookies to save user private information such as access112* control information, or to track user browsing habit.</td>113* </tr>114*115* <tr>116* <td>setDefaultAuthenticator</td>117* <td>The ability to set the118* way authentication information is retrieved when119* a proxy or HTTP server asks for authentication</td>120* <td>Malicious121* code can set an authenticator that monitors and steals user122* authentication input as it retrieves the input from the user.</td>123* </tr>124*125* <tr>126* <td>setProxySelector</td>127* <td>The ability to set the proxy selector used to make decisions128* on which proxies to use when making network connections.</td>129* <td>Malicious code can set a ProxySelector that directs network130* traffic to an arbitrary network host.</td>131* </tr>132*133* <tr>134* <td>setResponseCache</td>135* <td>The ability to set the response cache that provides access to136* a local response cache.</td>137* <td>Malicious code getting access to the local response cache138* could access security sensitive information, or create false139* entries in the response cache.</td>140* </tr>141*142* <tr>143* <td>specifyStreamHandler</td>144* <td>The ability145* to specify a stream handler when constructing a URL</td>146* <td>Malicious code may create a URL with resources that it would147normally not have access to (like file:/foo/fum/), specifying a148stream handler that gets the actual bytes from someplace it does149have access to. Thus it might be able to trick the system into150creating a ProtectionDomain/CodeSource for a class even though151that class really didn't come from that location.</td>152* </tr>153*154* <tr>155* <th scope="row">setSocketImpl</th>156* <td>The ability to create a sub-class of Socket or ServerSocket with a157* user specified SocketImpl.</td>158* <td>Malicious user-defined SocketImpls can change the behavior of159* Socket and ServerSocket in surprising ways, by virtue of their160* ability to access the protected fields of SocketImpl.</td>161* </tr>162* </table>163*164* @see java.security.BasicPermission165* @see java.security.Permission166* @see java.security.Permissions167* @see java.security.PermissionCollection168* @see java.lang.SecurityManager169*170*171* @author Marianne Mueller172* @author Roland Schemers173*/174175public final class NetPermission extends BasicPermission {176private static final long serialVersionUID = -8343910153355041693L;177178/**179* Creates a new NetPermission with the specified name.180* The name is the symbolic name of the NetPermission, such as181* "setDefaultAuthenticator", etc. An asterisk182* may appear at the end of the name, following a ".", or by itself, to183* signify a wildcard match.184*185* @param name the name of the NetPermission.186*187* @throws NullPointerException if {@code name} is {@code null}.188* @throws IllegalArgumentException if {@code name} is empty.189*/190191public NetPermission(String name)192{193super(name);194}195196/**197* Creates a new NetPermission object with the specified name.198* The name is the symbolic name of the NetPermission, and the199* actions String is currently unused and should be null.200*201* @param name the name of the NetPermission.202* @param actions should be null.203*204* @throws NullPointerException if {@code name} is {@code null}.205* @throws IllegalArgumentException if {@code name} is empty.206*/207208public NetPermission(String name, String actions)209{210super(name, actions);211}212}213214215