1 /* 2 * Copyright (c) 2003, 2013, 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.net.SocketPermission; 29 import java.net.NetPermission; 30 import java.security.AccessController; 31 import java.security.PrivilegedAction; 32 import java.security.Permission; 33 import java.security.BasicPermission; 34 import java.security.SecurityPermission; 35 import java.security.AllPermission; 36 37 /** 38 * Permission constants and string constants used to create permissions 39 * used throughout the JDK. 40 */ 41 public final class SecurityConstants { 42 // Cannot create one of these SecurityConstants()43 private SecurityConstants () { 44 } 45 46 // Commonly used string constants for permission actions used by 47 // SecurityManager. Declare here for shortcut when checking permissions 48 // in FilePermission, SocketPermission, and PropertyPermission. 49 50 public static final String FILE_DELETE_ACTION = "delete"; 51 public static final String FILE_EXECUTE_ACTION = "execute"; 52 public static final String FILE_READ_ACTION = "read"; 53 public static final String FILE_WRITE_ACTION = "write"; 54 public static final String FILE_READLINK_ACTION = "readlink"; 55 56 public static final String SOCKET_RESOLVE_ACTION = "resolve"; 57 public static final String SOCKET_CONNECT_ACTION = "connect"; 58 public static final String SOCKET_LISTEN_ACTION = "listen"; 59 public static final String SOCKET_ACCEPT_ACTION = "accept"; 60 public static final String SOCKET_CONNECT_ACCEPT_ACTION = "connect,accept"; 61 62 public static final String PROPERTY_RW_ACTION = "read,write"; 63 public static final String PROPERTY_READ_ACTION = "read"; 64 public static final String PROPERTY_WRITE_ACTION = "write"; 65 66 // Permission constants used in the various checkPermission() calls in JDK. 67 68 // java.lang.Class, java.lang.SecurityManager, java.lang.System, 69 // java.net.URLConnection, java.security.AllPermission, java.security.Policy, 70 // sun.security.provider.PolicyFile 71 public static final AllPermission ALL_PERMISSION = new AllPermission(); 72 73 /** 74 * AWT Permissions used in the JDK. 75 */ 76 // BEGIN Android-removed 77 /* 78 public static class AWT { 79 private AWT() { } 80 81 // The class name of the factory to create java.awt.AWTPermission objects. 82 private static final String AWTFactory = "sun.awt.AWTPermissionFactory"; 83 84 // The PermissionFactory to create AWT permissions (or null if AWT is 85 // not present) 86 private static final PermissionFactory<?> factory = permissionFactory(); 87 88 private static PermissionFactory<?> permissionFactory() { 89 Class<?> c; 90 try { 91 c = Class.forName(AWTFactory, false, AWT.class.getClassLoader()); 92 } catch (ClassNotFoundException e) { 93 // not available 94 return null; 95 } 96 // AWT present 97 try { 98 return (PermissionFactory<?>)c.newInstance(); 99 } catch (ReflectiveOperationException x) { 100 throw new InternalError(x); 101 } 102 } 103 104 private static Permission newAWTPermission(String name) { 105 return (factory == null) ? null : factory.newPermission(name); 106 } 107 108 // java.lang.SecurityManager 109 public static final Permission TOPLEVEL_WINDOW_PERMISSION = 110 newAWTPermission("showWindowWithoutWarningBanner"); 111 112 // java.lang.SecurityManager 113 public static final Permission ACCESS_CLIPBOARD_PERMISSION = 114 newAWTPermission("accessClipboard"); 115 116 // java.lang.SecurityManager 117 public static final Permission CHECK_AWT_EVENTQUEUE_PERMISSION = 118 newAWTPermission("accessEventQueue"); 119 120 // java.awt.Dialog 121 public static final Permission TOOLKIT_MODALITY_PERMISSION = 122 newAWTPermission("toolkitModality"); 123 124 // java.awt.Robot 125 public static final Permission READ_DISPLAY_PIXELS_PERMISSION = 126 newAWTPermission("readDisplayPixels"); 127 128 // java.awt.Robot 129 public static final Permission CREATE_ROBOT_PERMISSION = 130 newAWTPermission("createRobot"); 131 132 // java.awt.MouseInfo 133 public static final Permission WATCH_MOUSE_PERMISSION = 134 newAWTPermission("watchMousePointer"); 135 136 // java.awt.Window 137 public static final Permission SET_WINDOW_ALWAYS_ON_TOP_PERMISSION = 138 newAWTPermission("setWindowAlwaysOnTop"); 139 140 // java.awt.Toolkit 141 public static final Permission ALL_AWT_EVENTS_PERMISSION = 142 newAWTPermission("listenToAllAWTEvents"); 143 144 // java.awt.SystemTray 145 public static final Permission ACCESS_SYSTEM_TRAY_PERMISSION = 146 newAWTPermission("accessSystemTray"); 147 } 148 */ 149 // END Android-removed 150 151 // java.net.URL 152 public static final NetPermission SPECIFY_HANDLER_PERMISSION = 153 new NetPermission("specifyStreamHandler"); 154 155 // java.net.ProxySelector 156 public static final NetPermission SET_PROXYSELECTOR_PERMISSION = 157 new NetPermission("setProxySelector"); 158 159 // java.net.ProxySelector 160 public static final NetPermission GET_PROXYSELECTOR_PERMISSION = 161 new NetPermission("getProxySelector"); 162 163 // java.net.CookieHandler 164 public static final NetPermission SET_COOKIEHANDLER_PERMISSION = 165 new NetPermission("setCookieHandler"); 166 167 // java.net.CookieHandler 168 public static final NetPermission GET_COOKIEHANDLER_PERMISSION = 169 new NetPermission("getCookieHandler"); 170 171 // java.net.ResponseCache 172 public static final NetPermission SET_RESPONSECACHE_PERMISSION = 173 new NetPermission("setResponseCache"); 174 175 // java.net.ResponseCache 176 public static final NetPermission GET_RESPONSECACHE_PERMISSION = 177 new NetPermission("getResponseCache"); 178 179 // java.lang.SecurityManager, sun.applet.AppletPanel, sun.misc.Launcher 180 public static final RuntimePermission CREATE_CLASSLOADER_PERMISSION = 181 new RuntimePermission("createClassLoader"); 182 183 // java.lang.SecurityManager 184 public static final RuntimePermission CHECK_MEMBER_ACCESS_PERMISSION = 185 new RuntimePermission("accessDeclaredMembers"); 186 187 // java.lang.SecurityManager, sun.applet.AppletSecurity 188 public static final RuntimePermission MODIFY_THREAD_PERMISSION = 189 new RuntimePermission("modifyThread"); 190 191 // java.lang.SecurityManager, sun.applet.AppletSecurity 192 public static final RuntimePermission MODIFY_THREADGROUP_PERMISSION = 193 new RuntimePermission("modifyThreadGroup"); 194 195 // java.lang.Class 196 public static final RuntimePermission GET_PD_PERMISSION = 197 new RuntimePermission("getProtectionDomain"); 198 199 // java.lang.Class, java.lang.ClassLoader, java.lang.Thread 200 public static final RuntimePermission GET_CLASSLOADER_PERMISSION = 201 new RuntimePermission("getClassLoader"); 202 203 // java.lang.Thread 204 public static final RuntimePermission STOP_THREAD_PERMISSION = 205 new RuntimePermission("stopThread"); 206 207 // java.lang.Thread 208 public static final RuntimePermission GET_STACK_TRACE_PERMISSION = 209 new RuntimePermission("getStackTrace"); 210 211 // java.security.AccessControlContext 212 public static final SecurityPermission CREATE_ACC_PERMISSION = 213 new SecurityPermission("createAccessControlContext"); 214 215 // java.security.AccessControlContext 216 public static final SecurityPermission GET_COMBINER_PERMISSION = 217 new SecurityPermission("getDomainCombiner"); 218 219 // java.security.Policy, java.security.ProtectionDomain 220 public static final SecurityPermission GET_POLICY_PERMISSION = 221 new SecurityPermission ("getPolicy"); 222 223 // java.lang.SecurityManager 224 public static final SocketPermission LOCAL_LISTEN_PERMISSION = 225 new SocketPermission("localhost:0", SOCKET_LISTEN_ACTION); 226 } 227