738 null, StorageAttribute.NULL_TYPE)); |
740 null, StorageAttribute.NULL_TYPE)); |
739 } |
741 } |
740 if (data.getRootHashValue() != null |
742 if (data.getRootHashValue() != null |
741 && data.getRootHashValue().length() > 0) |
743 && data.getRootHashValue().length() > 0) |
742 { |
744 { |
|
745 int rootHashLength = (data.getRootHashValue().length() > 8 |
|
746 ? 8 : data.getRootHashValue().length()); |
743 entry.addAttribute(new StorageAttribute( |
747 entry.addAttribute(new StorageAttribute( |
744 StorageNames.CERT_HASH, |
748 StorageNames.CERT_HASH, |
745 data.getRootHashValue())); |
749 data.getRootHashValue().substring(0, |
|
750 rootHashLength))); |
746 } |
751 } |
747 String validCerts = encodeValidatedChainIndexes( |
752 String validCerts = encodeValidatedChainIndexes( |
748 data.getValidatedChainIndexes()); |
753 data.getValidatedChainIndexes()); |
749 if (validCerts != null && validCerts.length() > 0) |
754 if (validCerts != null && validCerts.length() > 0) |
750 { |
755 { |
1240 break; |
1245 break; |
1241 } |
1246 } |
1242 } |
1247 } |
1243 catch (StorageException e) |
1248 catch (StorageException e) |
1244 {/* move on with defaults */} |
1249 {/* move on with defaults */} |
|
1250 } |
|
1251 |
|
1252 |
|
1253 private void updateGrantedPermissions(Uid newAppUID, Uid oldAppUID, Vector grantedPermissions) |
|
1254 { |
|
1255 // the vector containing the newGrantedPermissions |
|
1256 Vector newGrantedPermissions = new Vector(); |
|
1257 |
|
1258 // get the old permissions & settings |
|
1259 Vector oldPermissions = readGrantedPermissions(oldAppUID); |
|
1260 |
|
1261 // filter out the the brand new permissions |
|
1262 // (permissions which are not found among the old permissions) |
|
1263 if (oldPermissions != null) |
|
1264 { |
|
1265 int index=0; |
|
1266 while (index < grantedPermissions.size()) |
|
1267 { |
|
1268 // instead of calling Vector.removeElement(p) we will do the |
|
1269 // remove manually, since the search is to be based on |
|
1270 // the permission without the settings |
|
1271 PolicyBasedPermission p = (PolicyBasedPermission) |
|
1272 grantedPermissions.elementAt(index); |
|
1273 int status = removeElement(oldPermissions, p); |
|
1274 switch (status) |
|
1275 { |
|
1276 case NOT_FOUND: |
|
1277 index++; |
|
1278 break; |
|
1279 case REMOVED: |
|
1280 grantedPermissions.removeElementAt(index); |
|
1281 break; |
|
1282 default: |
|
1283 // different settings |
|
1284 UserSecuritySettings oldSettings |
|
1285 = ((PolicyBasedPermission)oldPermissions |
|
1286 .elementAt(status)).getUserSecuritySettings(); |
|
1287 UserSecuritySettings newSettings |
|
1288 = p.getUserSecuritySettings(); |
|
1289 if (oldSettings != null |
|
1290 && newSettings != null) |
|
1291 { |
|
1292 boolean activeSettings = false; |
|
1293 if (oldSettings.isActive() |
|
1294 || newSettings.isActive()) |
|
1295 { |
|
1296 activeSettings = true; |
|
1297 } |
|
1298 newGrantedPermissions.addElement( |
|
1299 new PolicyBasedPermissionImpl( |
|
1300 p.getName(), |
|
1301 p.getTarget(), |
|
1302 p.getActionList(), |
|
1303 p.getType(), |
|
1304 new UserSecuritySettingsImpl( |
|
1305 newSettings.getName(), |
|
1306 oldSettings.getCurrentInteractionMode(), |
|
1307 newSettings.getAllowedInteractionModes(), |
|
1308 oldSettings.getBlanketPrompt(), |
|
1309 activeSettings))); |
|
1310 } |
|
1311 else |
|
1312 { |
|
1313 newGrantedPermissions.addElement(p); |
|
1314 } |
|
1315 grantedPermissions.removeElementAt(index); |
|
1316 break; |
|
1317 } |
|
1318 } |
|
1319 } |
|
1320 // write what's left from the granted permissions |
|
1321 writeGrantedPermissions(newAppUID, null, grantedPermissions, true /* preserveSettings */); |
|
1322 for (int i=0; i<newGrantedPermissions.size(); i++) |
|
1323 { |
|
1324 grantedPermissions.addElement(newGrantedPermissions.elementAt(i)); |
|
1325 } |
|
1326 |
|
1327 // remove what's left from the old permissions |
|
1328 if (oldPermissions != null) |
|
1329 { |
|
1330 for (int i=0; i<oldPermissions.size(); i++) |
|
1331 { |
|
1332 PolicyBasedPermission p = (PolicyBasedPermission) |
|
1333 oldPermissions.elementAt(i); |
|
1334 StorageEntry removePermissionQuery = new StorageEntry(); |
|
1335 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1336 StorageAttribute.ID, |
|
1337 oldAppUID.getStringValue())); |
|
1338 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1339 StorageNames.CLASS, |
|
1340 p.getName())); |
|
1341 if (p.getTarget() != null |
|
1342 && p.getTarget().length() > 0) |
|
1343 { |
|
1344 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1345 StorageNames.NAME, |
|
1346 p.getTarget())); |
|
1347 } |
|
1348 if (p.getActionList() != null |
|
1349 && p.getActionList().length() > 0) |
|
1350 { |
|
1351 removePermissionQuery.addAttribute(new StorageAttribute( |
|
1352 StorageNames.ACTION, |
|
1353 p.getActionList())); |
|
1354 } |
|
1355 doStorageRemove(StorageNames.MIDP_PERMISSIONS_TABLE, |
|
1356 removePermissionQuery); |
|
1357 // remove the setting also if not used by some other permission |
|
1358 UserSecuritySettings settings = |
|
1359 p.getUserSecuritySettings(); |
|
1360 if (settings != null) |
|
1361 { |
|
1362 StorageEntry permissionsQuery = new StorageEntry(); |
|
1363 permissionsQuery.addAttribute(new StorageAttribute( |
|
1364 StorageAttribute.ID, |
|
1365 newAppUID.getStringValue())); |
|
1366 permissionsQuery.addAttribute(new StorageAttribute( |
|
1367 StorageNames.FUNCTION_GROUP, |
|
1368 settings.getName())); |
|
1369 StorageEntry[] permissions = doStorageSearch( |
|
1370 StorageNames.MIDP_PERMISSIONS_TABLE, permissionsQuery); |
|
1371 if (permissions == null || (permissions != null |
|
1372 && permissions.length == 0)) |
|
1373 { |
|
1374 // remove the orphaned settings from settings table |
|
1375 StorageEntry removeSettingsQuery = new StorageEntry(); |
|
1376 removeSettingsQuery.addAttribute(new StorageAttribute( |
|
1377 StorageAttribute.ID, |
|
1378 newAppUID.getStringValue())); |
|
1379 removeSettingsQuery.addAttribute(new StorageAttribute( |
|
1380 StorageNames.FUNCTION_GROUP, |
|
1381 settings.getName())); |
|
1382 doStorageRemove(StorageNames.MIDP_FUNC_GRP_SETTINGS_TABLE, |
|
1383 removeSettingsQuery); |
|
1384 } |
|
1385 } |
|
1386 } |
|
1387 } |
|
1388 // write the new permissions |
|
1389 writeGrantedPermissions(newAppUID, null, newGrantedPermissions, true /* preserveSettings */); |
1245 } |
1390 } |
1246 |
1391 |
1247 private AuthenticationStorageData readAuthenticationStorageData( |
1392 private AuthenticationStorageData readAuthenticationStorageData( |
1248 Uid appUID, String aAppName, String aAppVersion, |
1393 Uid appUID, String aAppName, String aAppVersion, |
1249 String aAppVendor, int readFilter) |
1394 String aAppVendor, int readFilter) |