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: package com.sun.mmedia;
025:
026: import com.sun.midp.security.Permissions;
027: import com.sun.midp.midlet.Scheduler;
028: import com.sun.midp.midlet.MIDletSuite;
029:
030: /**
031: * A Wrapper class for platform/product specific permission management.
032: * This file contains CLDC/MIDP speecific version of the class.
033: */
034: public final class PermissionAccessor {
035:
036: public static final int PERMISSION_SYSTEM = 0;
037:
038: public static final int PERMISSION_HTTP_READ = 1;
039: public static final int PERMISSION_HTTP_WRITE = 2;
040: public static final int PERMISSION_FILE_READ = 3;
041: public static final int PERMISSION_FILE_WRITE = 4;
042: public static final int PERMISSION_SOCKET_READ = 5;
043: public static final int PERMISSION_SOCKET_WRITE = 6;
044:
045: public static final int PERMISSION_IMAGE_CAPTURE = 7;
046: public static final int PERMISSION_VIDEO_CAPTURE = 8;
047: public static final int PERMISSION_AUDIO_CAPTURE = 9;
048:
049: public static final int PERMISSION_VIDEO_RECORDING = 10;
050: public static final int PERMISSION_AUDIO_RECORDING = 11;
051:
052: public static final int PERMISSION_VIDEO_SNAPSHOT = 12;
053:
054: public static final int PERMISSION_VIDEO_CAMERA_SHUTTER_FEEDBACK = 13;
055: public static final int PERMISSION_RADIO_TUNER_SET_PRESET = 14;
056:
057: private static final int mapPermissions[] = {
058: /* PERMISSION_SYSTEM */Permissions.MIDP,
059:
060: /* PERMISSION_HTTP_READ */Permissions.HTTP,
061: /* PERMISSION_HTTP_WRITE */Permissions.HTTP,
062: /* PERMISSION_FILE_READ */Permissions.FILE_CONNECTION_READ,
063: /* PERMISSION_FILE_WRITE */Permissions.FILE_CONNECTION_WRITE,
064: /* PERMISSION_SOCKET_READ */Permissions.TCP,
065: /* PERMISSION_SOCKET_WRITE */Permissions.TCP,
066:
067: /* PERMISSION_IMAGE_CAPTURE */Permissions.MM_IMAGE_CAPTURING,
068: /* PERMISSION_VIDEO_CAPTURE */Permissions.MM_RECORD,
069: /* PERMISSION_AUDIO_CAPTURE */Permissions.MM_RECORD,
070:
071: /* PERMISSION_VIDEO_RECORDING */Permissions.MM_RECORD,
072: /* PERMISSION_AUDIO_RECORDING */Permissions.MM_RECORD,
073:
074: /* PERMISSION_VIDEO_SNAPSHOT */Permissions.MM_IMAGE_CAPTURING,
075:
076: //ATTENTION: THE FOLLOWING AMMS PERMISSIONS ARE NOT DEFINED YET
077: /* PERMISSION_VIDEO_CAMERA_SHUTTER_FEEDBACK *///Permissions.AMMS_CAMERA_SHUTTERFEEDBACK,
078: /* PERMISSION_RADIO_TUNER_SET_PRESET *///Permissions.AMMS_TUNER_SETPRESET
079: };
080:
081: /**
082: * Method indended to be called by Players & Controls to check
083: * if user application has enough permissions to perform
084: * a secured operation ...
085: *
086: * @param thePermission - one of PERMISSION_* constants that
087: * define permissions in an product-independent form.
088: */
089: public static void checkPermissions(int thePermission)
090: throws SecurityException {
091: try {
092: /*
093: * Map between PermissionAccessor.* permission constants
094: * and Permissions.* ...
095: * Any incorrect permission constant will result in
096: * ArrayIndexOutOfBoundsException ->
097: * a SecurityException will be thrown !
098: */
099: int permission = mapPermissions[thePermission];
100:
101: MIDletSuite midletSuite = Scheduler.getScheduler()
102: .getMIDletSuite();
103: midletSuite.checkIfPermissionAllowed(permission);
104: } catch (SecurityException se) {
105: ///*DEBUG:*/ se.printStackTrace();
106: throw se;
107: } catch (Exception e) {
108: ///*DEBUG:*/ e.printStackTrace();
109: throw new SecurityException(
110: "Failed to check user permission");
111: }
112: }
113:
114: private static final String locatorTypes[] = { "capture://audio",
115: "capture://video", "capture://radio", "capture://",
116: "device://", "file://", "http://" };
117:
118: // inidicates that corresponding locator type needs no special permissions.
119: private static final int NEED_NO_PERMISSIONS = 0;
120: private static final int FAILED_PERMISSIONS = -1;
121:
122: private static final int mapLocatorPermissions[] = {
123: /* "capture://audio" */NEED_NO_PERMISSIONS,
124: /* "capture://video" */NEED_NO_PERMISSIONS,
125: /* "capture://radio" */NEED_NO_PERMISSIONS,
126: /* "capture://" */NEED_NO_PERMISSIONS,
127: /* "device://" */NEED_NO_PERMISSIONS,
128: /* "file://" */Permissions.FILE_CONNECTION_READ,
129: /* "http://" */Permissions.HTTP };
130:
131: /**
132: * Method indended to be called by Manager.createDataSource(locator)
133: * and checks if user application has enough permissions to use given type
134: * of locators to play media contents.
135: *
136: * @param locator - the URL to be used as media source for player
137: */
138: public static void checkLocatorPermissions(String locator)
139: throws SecurityException {
140: int permission = FAILED_PERMISSIONS;
141: try {
142: /*
143: * Find Locator type, and map this type to permission.
144: * Any incorrect locator will result in
145: * ArrayIndexOutOfBoundsException or NullPointerException ->
146: * a SecurityException will be thrown !
147: */
148: String locStr = locator.toLowerCase();
149: for (int i = 0; i < locatorTypes.length; ++i) {
150: if (locStr.startsWith(locatorTypes[i])) {
151: permission = mapLocatorPermissions[i];
152: if (permission == NEED_NO_PERMISSIONS)
153: return;
154: break;
155: }
156: }
157:
158: MIDletSuite midletSuite = Scheduler.getScheduler()
159: .getMIDletSuite();
160: midletSuite.checkIfPermissionAllowed(permission);
161: } catch (SecurityException se) {
162: ///*DEBUG:*/ se.printStackTrace();
163: throw se;
164: } catch (Exception e) {
165: ///*DEBUG:*/ e.printStackTrace();
166: throw new SecurityException(
167: "Failed to check locator permission");
168: }
169: }
170:
171: /**
172: * Method indended to be called by Manager.createPlayer(DataSource)
173: * and checks if user application has enough permissions to playback
174: * media of a given content-type using given type
175: * of locators.
176: *
177: * @param locator - the URL to be used as media source for player,
178: * can be null if DataSOurce has been created not from locator
179: * @param contentType - content-type boolean of the media
180: */
181: public static void checkContentTypePermissions(String locator,
182: String contentType) throws SecurityException {
183: /*
184: * THIS IS A STUB
185: */
186: }
187: }
|