for (Map.Entry<String, ComponentPermissions> entry : contextIdToPermissionsMap.entrySet()) {
String contextID = entry.getKey();
ComponentPermissions componentPermissions = entry.getValue();
PolicyConfiguration policyConfiguration = policyConfigurationFactory.getPolicyConfiguration(contextID, true);
contextIdToPolicyConfigurationMap.put(contextID, policyConfiguration);
policyConfiguration.addToExcludedPolicy(componentPermissions.getExcludedPermissions());
policyConfiguration.addToUncheckedPolicy(componentPermissions.getUncheckedPermissions());
for (Map.Entry<String, PermissionCollection> roleEntry : componentPermissions.getRolePermissions().entrySet()) {
String roleName = roleEntry.getKey();
PermissionCollection rolePermissions = roleEntry.getValue();
for (Enumeration permissions = rolePermissions.elements(); permissions.hasMoreElements();) {
Permission permission = (Permission) permissions.nextElement();
policyConfiguration.addToRole(roleName, permission);
}
}
}
if (principalRoleMapper != null) {
principalRoleMapper.install(contextIdToPermissionsMap.keySet());
}
//link everything together
for (PolicyConfiguration policyConfiguration : contextIdToPolicyConfigurationMap.values()) {
for (PolicyConfiguration policyConfiguration2 : contextIdToPolicyConfigurationMap.values()) {
if (policyConfiguration != policyConfiguration2) {
policyConfiguration.linkConfiguration(policyConfiguration2);
}
}
}
//commit
for (PolicyConfiguration policyConfiguration : contextIdToPolicyConfigurationMap.values()) {
policyConfiguration.commit();
}
//refresh policy
Policy policy = Policy.getPolicy();
policy.refresh();