|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.rt.installer; |
|
19 |
|
20 import com.nokia.mj.impl.installer.Installer; |
|
21 import com.nokia.mj.impl.installer.utils.Log; |
|
22 import com.nokia.mj.impl.rt.support.ApplicationInfo; |
|
23 import com.nokia.mj.impl.rt.support.ApplicationUtils; |
|
24 import com.nokia.mj.impl.security.midp.authorization.AccessControllerFactoryImpl; |
|
25 import com.nokia.mj.impl.security.midp.authorization.AccessControllerImpl; |
|
26 import com.nokia.mj.impl.storage.StorageSession; |
|
27 import com.nokia.mj.impl.utils.Uid; |
|
28 import com.nokia.mj.impl.utils.exception.UserCancelException; |
|
29 |
|
30 import java.security.Permission; |
|
31 import java.security.AccessControlException; |
|
32 import java.util.Hashtable; |
|
33 |
|
34 /** |
|
35 * @author Nokia Corporation |
|
36 * @version 1.0 |
|
37 */ |
|
38 public class ApplicationUtilsImpl extends ApplicationUtils |
|
39 { |
|
40 private AccessControllerImpl iAccessController = null; |
|
41 private StorageSession iStorageSession = null; |
|
42 private boolean iSilent = false; |
|
43 private Uid iSuiteUid = null; |
|
44 private String iSuiteName = null; |
|
45 private Hashtable iAppUidNameTable = null; |
|
46 |
|
47 public void init(StorageSession aStorageSession, boolean aSilent, |
|
48 Uid aSuiteUid, String aSuiteName, |
|
49 Hashtable aAppUidNameTable) |
|
50 { |
|
51 Log.log("ApplicationUtilsImpl.init"); |
|
52 iStorageSession = aStorageSession; |
|
53 iSuiteUid = aSuiteUid; |
|
54 iSuiteName = aSuiteName; |
|
55 iAppUidNameTable = aAppUidNameTable; |
|
56 iSilent = aSilent; |
|
57 } |
|
58 |
|
59 public void destroy() |
|
60 { |
|
61 Log.log("ApplicationUtilsImpl.destroy"); |
|
62 iStorageSession = null; |
|
63 iSuiteUid = null; |
|
64 iSuiteName = null; |
|
65 iAppUidNameTable = null; |
|
66 if (iAccessController != null) |
|
67 { |
|
68 iAccessController.destroy(); |
|
69 iAccessController = null; |
|
70 } |
|
71 } |
|
72 |
|
73 public static void doShutdownImpl() |
|
74 { |
|
75 Log.log("ApplicationUtilsImpl.doShutdownImpl"); |
|
76 // Send shutdown notification to all registered listeners. |
|
77 ((ApplicationUtilsImpl)sInstance).doShutdown(); |
|
78 } |
|
79 |
|
80 |
|
81 public void notifyExitCmd() |
|
82 { |
|
83 Log.log("ApplicationUtilsImpl.notifyExitCmd"); |
|
84 // Cancel installation/uninstallation. |
|
85 Installer.cancel(); |
|
86 } |
|
87 |
|
88 public void checkPermission(Permission aPermission) |
|
89 throws AccessControlException, NullPointerException |
|
90 { |
|
91 checkPermission(null, aPermission); |
|
92 } |
|
93 |
|
94 public void checkPermission(Uid aAppUid, Permission aPermission) |
|
95 throws AccessControlException, NullPointerException |
|
96 { |
|
97 if (aPermission == null) |
|
98 { |
|
99 throw new NullPointerException |
|
100 ("Check permission called with null Permission"); |
|
101 } |
|
102 |
|
103 if (iSuiteUid == null) |
|
104 { |
|
105 // ApplicationUtilsImpl has not been initialized for |
|
106 // permission check, do nothing. |
|
107 Log.log("ApplicationUtilsImpl.checkPermission: appUid: " + |
|
108 aAppUid + ", " + aPermission.toString() + |
|
109 ": skipping check"); |
|
110 return; |
|
111 } |
|
112 |
|
113 boolean userPromptAllowed = false; |
|
114 if (aPermission.toString().equals( |
|
115 "javax.microedition.io.PushRegistryPermission")) |
|
116 { |
|
117 // PushRegistryPermission is the only permission which |
|
118 // must be prompted from the user during installation. |
|
119 userPromptAllowed = true; |
|
120 } |
|
121 |
|
122 ApplicationInfoImpl appInfoImpl = |
|
123 (ApplicationInfoImpl)ApplicationInfo.getInstance(); |
|
124 String protectionDomain = appInfoImpl.getProtectionDomain(); |
|
125 if (!userPromptAllowed && |
|
126 (protectionDomain == null || |
|
127 protectionDomain.equals( |
|
128 ApplicationInfo.UNIDENTIFIED_THIRD_PARTY_DOMAIN))) |
|
129 { |
|
130 // If user prompting is not allowed (i.e. other than |
|
131 // PushRegistryPermission is being requested) and |
|
132 // application is untrusted, do not make any |
|
133 // security checks; security checks for untrusted |
|
134 // application will be made at the application runtime. |
|
135 Log.log("ApplicationUtilsImpl.checkPermission: appUid: " + |
|
136 aAppUid + ", " + aPermission.toString() + |
|
137 ": no check for untrusted app"); |
|
138 return; |
|
139 } |
|
140 |
|
141 if (iAccessController == null) |
|
142 { |
|
143 try |
|
144 { |
|
145 String appName = iSuiteName; |
|
146 if (aAppUid != null && iAppUidNameTable != null) |
|
147 { |
|
148 appName = (String)iAppUidNameTable.get(aAppUid); |
|
149 } |
|
150 iAccessController = |
|
151 AccessControllerFactoryImpl. |
|
152 getAccessController(iStorageSession, iSuiteUid, appName); |
|
153 } |
|
154 catch (Throwable t) |
|
155 { |
|
156 throw new AccessControlException |
|
157 ("Error creating AccessControllerFactory. Reason " + t); |
|
158 } |
|
159 if (iAccessController == null) |
|
160 { |
|
161 throw new AccessControlException("Error creating AccessController"); |
|
162 } |
|
163 } |
|
164 |
|
165 try |
|
166 { |
|
167 if (userPromptAllowed) |
|
168 { |
|
169 if (iSilent) |
|
170 { |
|
171 // Do not prompt the user in case of silent installation. |
|
172 int permissionResult = |
|
173 iAccessController.checkPermission(aPermission.toString()); |
|
174 Log.log("ApplicationUtilsImpl.checkPermission: appUid: " + |
|
175 aAppUid + ", " + aPermission.toString() + |
|
176 " result " + permissionResult); |
|
177 if (permissionResult == 0) |
|
178 { |
|
179 // Permission is denied. |
|
180 throw new AccessControlException( |
|
181 "Permission " + aPermission.toString() + " not allowed"); |
|
182 } |
|
183 } |
|
184 else |
|
185 { |
|
186 // Not a silent installation, display user prompt. |
|
187 iAccessController.checkPermission(aPermission); |
|
188 Log.log("ApplicationUtilsImpl.checkPermission: appUid: " + |
|
189 aAppUid + ", " + aPermission.toString() + " ok"); |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 // No user prompt allowed for this permission. |
|
195 int permissionResult = |
|
196 iAccessController.checkPermission(aPermission.toString()); |
|
197 Log.log("ApplicationUtilsImpl.checkPermission: appUid: " + |
|
198 aAppUid + ", " + aPermission.toString() + |
|
199 " result " + permissionResult); |
|
200 if (permissionResult <= 0) |
|
201 { |
|
202 // Permission is either denied or requires user prompt. |
|
203 throw new AccessControlException( |
|
204 "Permission " + aPermission.toString() + " not allowed"); |
|
205 } |
|
206 } |
|
207 } |
|
208 catch (UserCancelException uce) |
|
209 { |
|
210 Log.log("User cancelled security prompt"); |
|
211 // Cancel installation/uninstallation. |
|
212 Installer.cancel(); |
|
213 } |
|
214 catch (AccessControlException ace) |
|
215 { |
|
216 throw(ace); |
|
217 } |
|
218 catch (Throwable t) |
|
219 { |
|
220 Log.logError("Error during checkPermission", t); |
|
221 throw new AccessControlException |
|
222 ("Error in Security impl. Reason " + t); |
|
223 |
|
224 } |
|
225 } |
|
226 } |