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: public class CdcAccessControlContext extends
37: AccessControlContextAdapter {
38:
39: /** Reference to the current MIDlet suite. */
40: private MIDletSuite midletSuite;
41:
42: /**
43: * Initializes the context for a MIDlet suite.
44: *
45: * @param suite current MIDlet suite
46: */
47: public CdcAccessControlContext(MIDletSuite suite) {
48: midletSuite = suite;
49: }
50:
51: /**
52: * Checks for permission and throw an exception if not allowed.
53: * May block to ask the user a question.
54: * <p>
55: * If the permission check failed because an InterruptedException was
56: * thrown, this method will throw a InterruptedSecurityException.
57: *
58: * @param permission ID of the permission to check for,
59: * the ID must be from
60: * {@link com.sun.midp.security.Permissions}
61: * @param resource string to insert into the question, can be null if
62: * no %2 in the question
63: * @param extraValue string to insert into the question,
64: * can be null if no %3 in the question
65: *
66: * @param name name of the requested permission
67: *
68: * @exception SecurityException if the specified permission
69: * is not permitted, based on the current security policy
70: * @exception InterruptedException if another thread interrupts the
71: * calling thread while this method is waiting to preempt the
72: * display.
73: */
74: public void checkPermissionImpl(String name, String resource,
75: String extraValue) throws SecurityException,
76: InterruptedException {
77: int permissionId;
78:
79: if (AccessController.TRUSTED_APP_PERMISSION_NAME.equals(name)) {
80: // This is really just a trusted suite check.
81: if (midletSuite.isTrusted()) {
82: return;
83: }
84:
85: throw new SecurityException("suite not trusted");
86: }
87:
88: permissionId = Permissions.getId(name);
89:
90: if (permissionId == Permissions.AMS
91: || permissionId == Permissions.MIDP) {
92: // These permission checks cannot block
93: midletSuite.checkIfPermissionAllowed(permissionId);
94: } else {
95: midletSuite.checkForPermission(permissionId, resource,
96: extraValue);
97: }
98: }
99: }
|