001: /*
002: * @(#)SecurityConstants.java 1.12 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package sun.security.util;
028:
029: import java.io.FilePermission;
030: import java.lang.RuntimePermission;
031: import java.net.SocketPermission;
032: import java.net.NetPermission;
033: import java.security.SecurityPermission;
034: import java.security.AllPermission;
035: import java.security.BasicPermission;
036: import java.lang.reflect.Constructor;
037: import java.lang.reflect.InvocationTargetException;
038:
039: /* javax.security.auth.AuthPermission subsetted out
040: * of CDC
041: import javax.security.auth.AuthPermission;
042: */
043:
044: /*
045: * Note that there are two versions of this file, this subsetted
046: * version for CDC and another for the security optional package.
047: * Be sure you're editting the right one!
048: */
049:
050: /**
051: * Permission constants and string constants used to create permissions
052: * used throughout the JDK.
053: */
054: public final class SecurityConstants {
055: // Cannot create one of these
056: private SecurityConstants() {
057: }
058:
059: // Commonly used string constants for permission actions used by
060: // SecurityManager. Declare here for shortcut when checking permissions
061: // in FilePermssion, SocketPermission, and PropertyPermission.
062:
063: public static final String FILE_DELETE_ACTION = "delete";
064: public static final String FILE_EXECUTE_ACTION = "execute";
065: public static final String FILE_READ_ACTION = "read";
066: public static final String FILE_WRITE_ACTION = "write";
067:
068: public static final String SOCKET_RESOLVE_ACTION = "resolve";
069: public static final String SOCKET_CONNECT_ACTION = "connect";
070: public static final String SOCKET_LISTEN_ACTION = "listen";
071: public static final String SOCKET_ACCEPT_ACTION = "accept";
072: public static final String SOCKET_CONNECT_ACCEPT_ACTION = "connect,accept";
073:
074: public static final String PROPERTY_RW_ACTION = "read,write";
075: public static final String PROPERTY_READ_ACTION = "read";
076: public static final String PROPERTY_WRITE_ACTION = "write";
077:
078: // Permission constants used in the various checkPermission() calls in JDK.
079:
080: // java.lang.Class, java.lang.SecurityManager, java.lang.System,
081: // java.net.URLConnection, java.security.AllPermission, java.security.Policy,
082: // sun.security.provider.PolicyFile
083: public static final AllPermission ALL_PERMISSION = new AllPermission();
084:
085: // java.net.URL
086: public static final NetPermission SPECIFY_HANDLER_PERMISSION = new NetPermission(
087: "specifyStreamHandler");
088:
089: // java.lang.SecurityManager, sun.applet.AppletPanel, sun.misc.Launcher
090: public static final RuntimePermission CREATE_CLASSLOADER_PERMISSION = new RuntimePermission(
091: "createClassLoader");
092:
093: // java.lang.SecurityManager
094: public static final RuntimePermission CHECK_MEMBER_ACCESS_PERMISSION = new RuntimePermission(
095: "accessDeclaredMembers");
096:
097: // java.lang.SecurityManager, sun.applet.AppletSecurity
098: public static final RuntimePermission MODIFY_THREAD_PERMISSION = new RuntimePermission(
099: "modifyThread");
100:
101: // java.lang.SecurityManager, sun.applet.AppletSecurity
102: public static final RuntimePermission MODIFY_THREADGROUP_PERMISSION = new RuntimePermission(
103: "modifyThreadGroup");
104:
105: // java.lang.Class
106: public static final RuntimePermission GET_PD_PERMISSION = new RuntimePermission(
107: "getProtectionDomain");
108:
109: // java.lang.Class, java.lang.ClassLoader, java.lang.Thread
110: public static final RuntimePermission GET_CLASSLOADER_PERMISSION = new RuntimePermission(
111: "getClassLoader");
112:
113: // java.lang.Thread
114: public static final RuntimePermission STOP_THREAD_PERMISSION = new RuntimePermission(
115: "stopThread");
116:
117: // java.security.AccessControlContext
118: public static final SecurityPermission CREATE_ACC_PERMISSION = new SecurityPermission(
119: "createAccessControlContext");
120:
121: // java.security.AccessControlContext
122: public static final SecurityPermission GET_COMBINER_PERMISSION = new SecurityPermission(
123: "getDomainCombiner");
124:
125: // java.security.Policy, java.security.ProtectionDomain
126: public static final SecurityPermission GET_POLICY_PERMISSION = new SecurityPermission(
127: "getPolicy");
128:
129: // java.lang.SecurityManager
130: public static final SocketPermission LOCAL_LISTEN_PERMISSION = new SocketPermission(
131: "localhost:1024-", SOCKET_LISTEN_ACTION);
132:
133: /* javax.security.auth.AuthPermission subsetted out of CDC.
134: // javax.security.auth.Subject
135: public static final AuthPermission DO_AS_PERMISSION =
136: new AuthPermission("doAs");
137:
138: // javax.security.auth.Subject
139: public static final AuthPermission DO_AS_PRIVILEGED_PERMISSION =
140: new AuthPermission("doAsPrivileged");
141: */
142:
143: // Make this class more friendly for mTASK:
144: // To eagerly initialize topLevelWindowPermission,
145: // accessClipboardPermission and checkAwtEventQueuePermission,
146: // the private static method initAwtPerms() is now changed to
147: // be a static initializer.
148: //
149: // The static variable, isAwtPermInitialized is no longer in use.
150: //
151: //private static boolean isAwtPermInitialized = false;
152: private static BasicPermission topLevelWindowPermission;
153:
154: private static BasicPermission accessClipboardPermission;
155:
156: private static BasicPermission checkAwtEventQueuePermission;
157:
158: public static BasicPermission getTopLevelWindowPermission() {
159: //if (!isAwtPermInitialized)
160: // initAwtPerms();
161: return topLevelWindowPermission;
162: }
163:
164: public static BasicPermission getAccessClipboardPermission() {
165: //if (!isAwtPermInitialized)
166: // initAwtPerms();
167: return accessClipboardPermission;
168: }
169:
170: public static BasicPermission getCheckAwtEventQueuePermission() {
171: //if (!isAwtPermInitialized)
172: // initAwtPerms();
173: return checkAwtEventQueuePermission;
174: }
175:
176: // use reflection to find out whether AWT classes are available
177: static {
178: Constructor AwtPermissionCtor = null;
179: try {
180: AwtPermissionCtor = Class.forName("java.awt.AWTPermission")
181: .getConstructor(new Class[] { String.class });
182: } catch (ClassNotFoundException ce) {
183: // No AWT, so what are you playing with windows for?
184: //isAwtPermInitialized = true; // no longer need
185: //return;
186: } catch (NoSuchMethodException ne) {
187: throw new SecurityException(
188: "AWTPermission constructor changed");
189: }
190:
191: if (AwtPermissionCtor != null) {
192: try {
193: topLevelWindowPermission = (BasicPermission) AwtPermissionCtor
194: .newInstance(new Object[] { "showWindowWithoutWarningBanner" });
195: } catch (InstantiationException ie) {
196: } catch (IllegalAccessException iae) {
197: } catch (InvocationTargetException ite) {
198: }
199: try {
200: checkAwtEventQueuePermission = (BasicPermission) AwtPermissionCtor
201: .newInstance(new Object[] { "accessEventQueue" });
202: } catch (InstantiationException ie) {
203: } catch (IllegalAccessException iae) {
204: } catch (InvocationTargetException ite) {
205: }
206: try {
207: accessClipboardPermission = (BasicPermission) AwtPermissionCtor
208: .newInstance(new Object[] { "accessClipboard" });
209: } catch (InstantiationException ie) {
210: } catch (IllegalAccessException iae) {
211: } catch (InvocationTargetException ite) {
212: }
213:
214: //isAwtPermInitialized = true; // no longer need
215: //return;
216: }
217: }
218:
219: }
|