001: /*
002: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.midp.jump.installer;
026:
027: import com.sun.midp.midlet.MIDletSuite;
028: import com.sun.midp.security.Permissions;
029: import com.sun.midp.security.SecurityToken;
030:
031: import com.sun.midp.installer.InternalMIDletSuiteImpl;
032:
033: /**
034: * A proxy for InternalMIDletSuiteImpl to bypass the security check.
035: * Used by the JUMP exective to bypass NullPointerException
036: * thrown at various ams secuirty check code through MIDletStateHandler like
037: * listed below. See JumpInit.init() for the code that
038: * sets MIDletStateHandler.java's MIDletSuite field value.
039: *
040: * MIDletStateHandler midletStateHandler =
041: * MIDletStateHandler.getMidletStateHandler();
042: * MIDletSuite midletSuite = midletStateHandler.getMIDletSuite();
043: * midletSuite.checkIfPermissionAllowed(Permissions.AMS);
044: *
045: * This is a temporary fix until the security architecture in ams s replaced
046: * with more CDC centric AccessController syntax.
047: **/
048: public class TrustedMIDletSuiteInfo implements MIDletSuite {
049:
050: MIDletSuite suite;
051:
052: public TrustedMIDletSuiteInfo() {
053: suite = InternalMIDletSuiteImpl.create("executive", 0);
054: }
055:
056: public void checkIfPermissionAllowed(int permission) {
057: return; // trusted, don't throw SecurityException.
058: }
059:
060: /**
061: * Get a property of the suite. A property is an attribute from
062: * either the application descriptor or JAR Manifest.
063: *
064: * @param key the name of the property
065: * @return A string with the value of the property.
066: * <code>null</code> is returned if no value is available for
067: * the key.
068: */
069: public String getProperty(String key) {
070: return suite.getProperty(key);
071: }
072:
073: /**
074: * Gets push setting for interrupting other MIDlets.
075: * Reuses the Permissions.
076: *
077: * @return push setting for interrupting MIDlets the value
078: * will be permission level from {@link Permissions}
079: */
080: public byte getPushInterruptSetting() {
081: return suite.getPushInterruptSetting();
082: }
083:
084: /**
085: * Gets push options for this suite.
086: *
087: * @return push options are defined in {@link PushRegistryImpl}
088: */
089: public int getPushOptions() {
090: return suite.getPushOptions();
091: }
092:
093: /**
094: * Gets list of permissions for this suite.
095: *
096: * @return array of permissions from {@link Permissions}
097: */
098: public byte[] getPermissions() {
099: return suite.getPermissions();
100: }
101:
102: /**
103: * Replace or add a property to the suite for this run only.
104: *
105: * @param token token with the AMS permission set to allowed,
106: * can be null to use the suite's permission
107: * @param key the name of the property
108: * @param value the value of the property
109: *
110: * @exception SecurityException if the caller's token does not have
111: * internal AMS permission
112: */
113: public void setTempProperty(SecurityToken token, String key,
114: String value) {
115: suite.setTempProperty(token, key, value);
116: }
117:
118: /**
119: * Get the name of a MIDlet to display to the user.
120: *
121: * @param className classname of a MIDlet in the suite
122: *
123: * @return name to display to the user
124: */
125: public String getMIDletName(String className) {
126: return suite.getMIDletName(className);
127: }
128:
129: /**
130: * Check to see the suite has the ALLOW level for specific permission.
131: * This is used for by internal APIs that only provide access to
132: * trusted system applications.
133: * <p>
134: * Only trust this method if the object has been obtained from the
135: * Scheduler of the suite.
136: *
137: * @param permission permission ID from
138: * {@link com.sun.midp.security.Permissions}
139: *
140: * @exception SecurityException if the suite is not
141: * allowed to perform the specified action.
142: */
143: //public void checkIfPermissionAllowed(int permission);
144: /**
145: * Check for permission and throw an exception if not allowed.
146: * May block to ask the user a question.
147: *
148: * @param permission ID of the permission to check for,
149: * the ID must be from
150: * {@link com.sun.midp.security.Permissions}
151: * @param resource string to insert into the question, can be null if
152: * no %2 in the question
153: *
154: * @exception SecurityException if the permission is not
155: * allowed by this token
156: * @exception InterruptedException if another thread interrupts the
157: * calling thread while this method is waiting to preempt the
158: * display.
159: */
160: public void checkForPermission(int permission, String resource)
161: throws InterruptedException {
162: suite.checkForPermission(permission, resource);
163: }
164:
165: /**
166: * Checks for permission and throw an exception if not allowed.
167: * May block to ask the user a question.
168: *
169: * @param permission ID of the permission to check for,
170: * the ID must be from
171: * {@link com.sun.midp.security.Permissions}
172: * @param resource string to insert into the question, can be null if
173: * no %2 in the question
174: * @param extraValue string to insert into the question,
175: * can be null if no %3 in the question
176: *
177: * @exception SecurityException if the permission is not
178: * allowed by this token
179: * @exception InterruptedException if another thread interrupts the
180: * calling thread while this method is waiting to preempt the
181: * display.
182: */
183: public void checkForPermission(int permission, String resource,
184: String extraValue) throws InterruptedException {
185: suite.checkForPermission(permission, resource, extraValue);
186: }
187:
188: /**
189: * Get the status of the specified permission.
190: * If no API on the device defines the specific permission
191: * requested then it must be reported as denied.
192: * If the status of the permission is not known because it might
193: * require a user interaction then it should be reported as unknown.
194: *
195: * @param permission to check if denied, allowed, or unknown.
196: * @return 0 if the permission is denied; 1 if the permission is allowed;
197: * -1 if the status is unknown
198: */
199: public int checkPermission(String permission) {
200: return suite.checkPermission(permission);
201: }
202:
203: /**
204: * Gets the unique ID of the suite.
205: *
206: * @return suite ID
207: */
208: public int getID() {
209: return suite.getID();
210: }
211:
212: /**
213: * Ask the user want to interrupt the current MIDlet with
214: * a new MIDlet that has received network data.
215: *
216: * @param connection connection to place in the permission question or
217: * null for alarm
218: *
219: * @return true if the use wants interrupt the current MIDlet, else false
220: */
221: public boolean permissionToInterrupt(String connection) {
222: return suite.permissionToInterrupt(connection);
223: }
224:
225: /**
226: * Indicates if the named MIDlet is registered in the suite
227: * with MIDlet-<n> record in the manifest or
228: * application descriptor.
229: * @param midletClassName class name of the MIDlet to be checked
230: *
231: * @return true if the MIDlet is registered
232: */
233: public boolean isRegistered(String midletClassName) {
234: return suite.isRegistered(midletClassName);
235: }
236:
237: /**
238: * Indicates if this suite is trusted.
239: * (not to be confused with a domain named "trusted",
240: * this is used for extra checks beyond permission checking)
241: *
242: * @return true if the suite is trusted false if not
243: */
244: public boolean isTrusted() {
245: return suite.isTrusted();
246: }
247:
248: /**
249: * Check whether the suite classes are preverified and
250: * the suite content hasn't been changed since installation
251: *
252: * @return true if no more verification needed, false otherwise
253: */
254: public boolean isVerified() {
255: return suite.isVerified();
256: }
257:
258: /**
259: * Determine if the a MIDlet from this suite can be run. Note that
260: * disable suites can still have their settings changed and their
261: * install info displayed.
262: *
263: * @return true if suite is enabled, false otherwise
264: */
265: public boolean isEnabled() {
266: return suite.isEnabled();
267: }
268:
269: /**
270: * Close the opened MIDletSuite
271: */
272: public void close() {
273: suite.close();
274: }
275: }
|