use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class RemoveReferralsStep method enactRequiredPolicyModelChanges.
private void enactRequiredPolicyModelChanges(Application application, String sourceRealm, String destinationRealm) throws EntitlementException, UpgradeException {
PrivilegeManager policyManager = policyServiceFactory.get(destinationRealm, getAdminSubject());
List<Privilege> policies = policyManager.findAllPoliciesByApplication(application.getName());
if (policies.isEmpty()) {
// Only necessary to reinstate application if policies exist in the realm.
return;
}
try {
UpgradeProgress.reportStart(AUDIT_CLONING_APPLICATION_START, application.getName(), destinationRealm);
String resourceTypeId = application.getResourceTypeUuids().iterator().next();
String clonedResourceTypeId = instateAssociatedResourceType(resourceTypeId, sourceRealm, destinationRealm);
Application clonedApplication = cloneApplication(application, clonedResourceTypeId);
applicationService.saveApplication(getAdminSubject(), destinationRealm, clonedApplication);
for (Privilege policy : policies) {
policy.setResourceTypeUuid(clonedResourceTypeId);
policyManager.modify(policy);
}
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException | UpgradeException e) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw e;
}
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class UpgradeEntitlementSubConfigsStep method addMissingResourceTypeUUIDs.
/**
* Clears the resourceType UUIDs currently associated with an application, then replaces them with
* the new set of resourceType UUIDs defined.
*
* @throws UpgradeException If there was an error while updating the application.
*/
private void addMissingResourceTypeUUIDs() throws UpgradeException {
for (final Map.Entry<String, Set<String>> entry : changedResourceTypeUUIDs.entrySet()) {
final String name = entry.getKey();
final Set<String> resourceTypeUUIDs = entry.getValue();
try {
UpgradeProgress.reportStart(AUDIT_MODIFIED_UUID_START, name);
if (DEBUG.messageEnabled()) {
DEBUG.message("Modifying application " + name + ": adding resourceType UUIDs: " + resourceTypeUUIDs);
}
final Application application = getApplication(name);
application.addAllResourceTypeUuids(resourceTypeUUIDs);
entitlementService.storeApplication(application);
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException ee) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException(ee);
}
}
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class UpgradeEntitlementSubConfigsStep method addChangedCombiners.
/**
* Alter EntitlementCombiner references.
*
* @throws UpgradeException
*/
private void addChangedCombiners() throws UpgradeException {
for (final Map.Entry<String, String> entry : changedCombiners.entrySet()) {
final String name = entry.getKey();
final String combiner = entry.getValue();
try {
UpgradeProgress.reportStart(AUDIT_MODIFIED_COM_START, name);
if (DEBUG.messageEnabled()) {
DEBUG.message("Modifying application " + name + " ; setting combiner: " + combiner);
}
final Application application = getApplication(name);
application.setEntitlementCombinerName(EntitlementUtils.getEntitlementCombiner(combiner));
entitlementService.storeApplication(application);
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException ee) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException(ee);
}
}
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class UpgradeEntitlementSubConfigsStep method addChangedDescription.
/**
* Clears the description currently associated with an application, then replaces it with
* the new description defined.
*
* @throws UpgradeException If there was an error while updating the application.
*/
private void addChangedDescription() throws UpgradeException {
for (final Map.Entry<String, String> entry : changedDescriptions.entrySet()) {
final String name = entry.getKey();
final String description = entry.getValue();
try {
UpgradeProgress.reportStart(AUDIT_MODIFIED_DES_START, name);
if (DEBUG.messageEnabled()) {
DEBUG.message("Modifying application " + name + " ; adding description: " + description);
}
final Application application = getApplication(name);
application.setDescription(description);
entitlementService.storeApplication(application);
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException ee) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException(ee);
}
}
}
use of com.sun.identity.entitlement.Application in project OpenAM by OpenRock.
the class UpgradeEntitlementSubConfigsStep method initialize.
@Override
public void initialize() throws UpgradeException {
DEBUG.message("Initialising the upgrade entitlement sub-config step");
final Set<ApplicationType> existingApplicationTypes = entitlementService.getApplicationTypes();
final Set<String> existingResourceTypeUUIDs = getResourceTypeUUIDs(ROOT_REALM);
final Set<String> presentTypes = extract(existingApplicationTypes, new TypeNameExtractor());
final Set<String> presentApps = extract(entitlementService.getApplications(), new AppNameExtractor());
final Document entitlementDoc = getEntitlementXML();
final NodeList subConfigs = entitlementDoc.getElementsByTagName(SMSUtils.SUB_CONFIG);
for (int idx = 0; idx < subConfigs.getLength(); idx++) {
final Node subConfig = subConfigs.item(idx);
final String id = getNodeAttributeValue(subConfig, ID);
final String name = getNodeAttributeValue(subConfig, NAME);
if (APPLICATION_TYPE.equals(id)) {
captureMissingEntry(name, subConfig, presentTypes, missingApplicationTypes);
captureMissingActions(name, subConfig);
} else if (APPLICATION.equals(id)) {
captureMissingEntry(name, subConfig, presentApps, missingApps);
//app will be null if application needs to be created (see missing entries)
final Application app = getApplication(name);
final Map<String, Set<String>> subConfigAttrs = parseAttributeValuePairTags(subConfig);
captureDifferentSet(app == null ? null : app.getSubjects(), getSubjects(subConfigAttrs), changedSubjects, name);
captureDifferentSet(app == null ? null : app.getConditions(), getConditions(subConfigAttrs), changedConditions, name);
captureDifferentSet(app == null ? null : app.getResourceTypeUuids(), EntitlementUtils.getResourceTypeUUIDs(subConfigAttrs), changedResourceTypeUUIDs, name);
Set<String> configDescriptionSet = getDescription(subConfigAttrs);
String configDescription = null;
if (configDescriptionSet != null && !configDescriptionSet.isEmpty()) {
configDescription = configDescriptionSet.iterator().next();
}
captureDifferentString(app == null ? null : app.getDescription(), configDescription, changedDescriptions, name);
final EntitlementCombiner combiner = (app == null ? null : app.getEntitlementCombiner());
captureDifferentEntitlementCombiner(combiner == null ? null : combiner.getName(), getCombiner(subConfigAttrs), name);
} else if (RESOURCE_TYPE.equals(id)) {
// note that the name variable actually holds the UUID of the ResourceType
// the name is buried in the config.
//
captureMissingEntry(name, subConfig, existingResourceTypeUUIDs, missingResourceTypes);
}
}
}
Aggregations