01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.main;
28:
29: import com.sun.j2me.security.AccessControlContextAdapter;
30: import com.sun.j2me.security.AccessController;
31:
32: import com.sun.midp.midlet.MIDletSuite;
33:
34: import com.sun.midp.security.Permissions;
35:
36: class CldcAccessControlContext extends AccessControlContextAdapter {
37:
38: /** Reference to the current MIDlet suite. */
39: private MIDletSuite midletSuite;
40:
41: /**
42: * Initializes the context for a MIDlet suite.
43: *
44: * @param suite current MIDlet suite
45: */
46: CldcAccessControlContext(MIDletSuite suite) {
47: midletSuite = suite;
48: }
49:
50: /**
51: * Checks for permission and throw an exception if not allowed.
52: * May block to ask the user a question.
53: * <p>
54: * If the permission check failed because an InterruptedException was
55: * thrown, this method will throw a InterruptedSecurityException.
56: *
57: * @param permission ID of the permission to check for,
58: * the ID must be from
59: * {@link com.sun.midp.security.Permissions}
60: * @param resource string to insert into the question, can be null if
61: * no %2 in the question
62: * @param extraValue string to insert into the question,
63: * can be null if no %3 in the question
64: *
65: * @param name name of the requested permission
66: *
67: * @exception SecurityException if the specified permission
68: * is not permitted, based on the current security policy
69: * @exception InterruptedException if another thread interrupts the
70: * calling thread while this method is waiting to preempt the
71: * display.
72: */
73: public void checkPermissionImpl(String name, String resource,
74: String extraValue) throws SecurityException,
75: InterruptedException {
76: int permissionId;
77:
78: if (AccessController.TRUSTED_APP_PERMISSION_NAME.equals(name)) {
79: // This is really just a trusted suite check.
80: if (midletSuite.isTrusted()) {
81: return;
82: }
83:
84: throw new SecurityException("suite not trusted");
85: }
86:
87: permissionId = Permissions.getId(name);
88:
89: if (permissionId == Permissions.AMS
90: || permissionId == Permissions.MIDP) {
91: // These permission checks cannot block
92: midletSuite.checkIfPermissionAllowed(permissionId);
93: } else {
94: midletSuite.checkForPermission(permissionId, resource,
95: extraValue);
96: }
97: }
98: }
|