1 /*
2  * Copyright (c) 2003, 2019, 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 sun.security.util;
27 
28 import java.lang.reflect.ReflectPermission;
29 import java.net.SocketPermission;
30 import java.net.NetPermission;
31 import java.security.Permission;
32 import java.security.SecurityPermission;
33 import java.security.AllPermission;
34 import sun.security.action.GetPropertyAction;
35 
36 /**
37  * Permission constants and string constants used to create permissions
38  * used throughout the JDK.
39  */
40 public final class SecurityConstants {
41     // Cannot create one of these
SecurityConstants()42     private SecurityConstants () {
43     }
44 
45     // Commonly used string constants for permission actions used by
46     // SecurityManager. Declare here for shortcut when checking permissions
47     // in FilePermission, SocketPermission, and PropertyPermission.
48 
49     public static final String FILE_DELETE_ACTION = "delete";
50     public static final String FILE_EXECUTE_ACTION = "execute";
51     public static final String FILE_READ_ACTION = "read";
52     public static final String FILE_WRITE_ACTION = "write";
53     public static final String FILE_READLINK_ACTION = "readlink";
54 
55     public static final String SOCKET_RESOLVE_ACTION = "resolve";
56     public static final String SOCKET_CONNECT_ACTION = "connect";
57     public static final String SOCKET_LISTEN_ACTION = "listen";
58     public static final String SOCKET_ACCEPT_ACTION = "accept";
59     public static final String SOCKET_CONNECT_ACCEPT_ACTION = "connect,accept";
60 
61     public static final String PROPERTY_RW_ACTION = "read,write";
62     public static final String PROPERTY_READ_ACTION = "read";
63     public static final String PROPERTY_WRITE_ACTION = "write";
64 
65     // Permission constants used in the various checkPermission() calls in JDK.
66 
67     // java.lang.Class, java.lang.SecurityManager, java.lang.System,
68     // java.net.URLConnection, java.security.AllPermission, java.security.Policy,
69     // sun.security.provider.PolicyFile
70     public static final AllPermission ALL_PERMISSION = new AllPermission();
71 
72     // java.net.URL
73     public static final NetPermission SPECIFY_HANDLER_PERMISSION =
74        new NetPermission("specifyStreamHandler");
75 
76     // java.net.ProxySelector
77     public static final NetPermission SET_PROXYSELECTOR_PERMISSION =
78        new NetPermission("setProxySelector");
79 
80     // java.net.ProxySelector
81     public static final NetPermission GET_PROXYSELECTOR_PERMISSION =
82        new NetPermission("getProxySelector");
83 
84     // java.net.CookieHandler
85     public static final NetPermission SET_COOKIEHANDLER_PERMISSION =
86        new NetPermission("setCookieHandler");
87 
88     // java.net.CookieHandler
89     public static final NetPermission GET_COOKIEHANDLER_PERMISSION =
90        new NetPermission("getCookieHandler");
91 
92     // java.net.ResponseCache
93     public static final NetPermission SET_RESPONSECACHE_PERMISSION =
94        new NetPermission("setResponseCache");
95 
96     // java.net.ResponseCache
97     public static final NetPermission GET_RESPONSECACHE_PERMISSION =
98        new NetPermission("getResponseCache");
99 
100     // java.net.ServerSocket, java.net.Socket
101     public static final NetPermission SET_SOCKETIMPL_PERMISSION =
102         new NetPermission("setSocketImpl");
103 
104     // java.lang.SecurityManager, sun.applet.AppletPanel
105     public static final RuntimePermission CREATE_CLASSLOADER_PERMISSION =
106         new RuntimePermission("createClassLoader");
107 
108     // java.lang.SecurityManager
109     public static final RuntimePermission CHECK_MEMBER_ACCESS_PERMISSION =
110         new RuntimePermission("accessDeclaredMembers");
111 
112     // java.lang.SecurityManager, sun.applet.AppletSecurity
113     public static final RuntimePermission MODIFY_THREAD_PERMISSION =
114         new RuntimePermission("modifyThread");
115 
116     // java.lang.SecurityManager, sun.applet.AppletSecurity
117     public static final RuntimePermission MODIFY_THREADGROUP_PERMISSION =
118         new RuntimePermission("modifyThreadGroup");
119 
120     // java.lang.Class
121     public static final RuntimePermission GET_PD_PERMISSION =
122         new RuntimePermission("getProtectionDomain");
123 
124     // java.lang.Class, java.lang.ClassLoader, java.lang.Thread
125     public static final RuntimePermission GET_CLASSLOADER_PERMISSION =
126         new RuntimePermission("getClassLoader");
127 
128     // java.lang.Thread
129     public static final RuntimePermission STOP_THREAD_PERMISSION =
130        new RuntimePermission("stopThread");
131 
132     // java.lang.Thread
133     public static final RuntimePermission GET_STACK_TRACE_PERMISSION =
134        new RuntimePermission("getStackTrace");
135 
136     // java.lang.Thread
137     public static final RuntimePermission SUBCLASS_IMPLEMENTATION_PERMISSION =
138         new RuntimePermission("enableContextClassLoaderOverride");
139 
140     // java.security.AccessControlContext
141     public static final SecurityPermission CREATE_ACC_PERMISSION =
142        new SecurityPermission("createAccessControlContext");
143 
144     // java.security.AccessControlContext
145     public static final SecurityPermission GET_COMBINER_PERMISSION =
146        new SecurityPermission("getDomainCombiner");
147 
148     // java.security.Policy, java.security.ProtectionDomain
149     public static final SecurityPermission GET_POLICY_PERMISSION =
150         new SecurityPermission ("getPolicy");
151 
152     // java.lang.SecurityManager
153     public static final SocketPermission LOCAL_LISTEN_PERMISSION =
154         new SocketPermission("localhost:0", SOCKET_LISTEN_ACTION);
155 
156     public static final String PROVIDER_VER =
157         GetPropertyAction.privilegedGetProperty("java.specification.version");
158 
159     // java.lang.reflect.AccessibleObject
160     public static final ReflectPermission ACCESS_PERMISSION =
161         new ReflectPermission("suppressAccessChecks");
162 
163     // sun.reflect.ReflectionFactory
164     public static final RuntimePermission REFLECTION_FACTORY_ACCESS_PERMISSION =
165         new RuntimePermission("reflectionFactoryAccess");
166 
167 }
168