Search in sources :

Example 36 with Application

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;
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) Application(com.sun.identity.entitlement.Application)

Example 37 with Application

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);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap) Application(com.sun.identity.entitlement.Application)

Example 38 with Application

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);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap) Application(com.sun.identity.entitlement.Application)

Example 39 with Application

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);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap) Application(com.sun.identity.entitlement.Application)

Example 40 with Application

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);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) ApplicationType(com.sun.identity.entitlement.ApplicationType) Application(com.sun.identity.entitlement.Application) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap) EntitlementCombiner(com.sun.identity.entitlement.EntitlementCombiner) DenyOverride(com.sun.identity.entitlement.DenyOverride)

Aggregations

Application (com.sun.identity.entitlement.Application)65 EntitlementException (com.sun.identity.entitlement.EntitlementException)37 Subject (javax.security.auth.Subject)29 ResourceResponse (org.forgerock.json.resource.ResourceResponse)22 Test (org.testng.annotations.Test)22 HashSet (java.util.HashSet)20 JsonValue (org.forgerock.json.JsonValue)18 Set (java.util.Set)16 ResourceException (org.forgerock.json.resource.ResourceException)16 RealmContext (org.forgerock.openam.rest.RealmContext)16 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)16 HashMap (java.util.HashMap)15 ClientContext (org.forgerock.services.context.ClientContext)13 Context (org.forgerock.services.context.Context)13 Matchers.anyString (org.mockito.Matchers.anyString)13 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)10 UpdateRequest (org.forgerock.json.resource.UpdateRequest)9 ApplicationWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper)9 Map (java.util.Map)8 BadRequestException (org.forgerock.json.resource.BadRequestException)7