Search in sources :

Example 6 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class UpgradeResourceTypeStep method createResourceType.

/**
     * Create the resource type for the given application if a suitable resource type does not already exist.
     * @param state The state object that contains the various parameters for creating the resource type.
     * @param realm The realm in which the application and resource type resides.
     * @return The resource type if it could be created or {@code null} if it could not.
     * @throws UpgradeException If the application types could not be read.
     */
private ResourceType createResourceType(ResourceTypeState state, String realm) throws UpgradeException {
    final Set<QueryFilter<SmsAttribute>> actionFilters = transformSet(state.actions, new Function<String, QueryFilter<SmsAttribute>, NeverThrowsException>() {

        @Override
        public QueryFilter<SmsAttribute> apply(String value) {
            return QueryFilter.equalTo(ResourceTypeSmsAttributes.ACTIONS, value);
        }
    });
    final Set<QueryFilter<SmsAttribute>> patternFilters = transformSet(state.patterns, new Function<String, QueryFilter<SmsAttribute>, NeverThrowsException>() {

        @Override
        public QueryFilter<SmsAttribute> apply(String value) {
            return QueryFilter.equalTo(ResourceTypeSmsAttributes.PATTERNS, value);
        }
    });
    final Set<ResourceType> resourceTypes;
    try {
        resourceTypes = resourceTypeService.getResourceTypes(QueryFilter.and(QueryFilter.and(actionFilters), QueryFilter.and(patternFilters)), getAdminSubject(), realm);
    } catch (EntitlementException e) {
        throw new UpgradeException("Failed to retrieve resource type for " + state.appName, e);
    }
    if (!resourceTypes.isEmpty()) {
        // Some matching resource types have been found, return the first one.
        return resourceTypes.iterator().next();
    }
    ResourceType resourceType = ResourceType.builder().setName(state.appName + RESOURCES_TYPE_NAME_SUFFIX).addActions(getActions(state.actions)).addPatterns(state.patterns).setDescription(RESOURCE_TYPE_DESCRIPTION + state.appName).generateUUID().build();
    saveResourceType(resourceType, realm);
    state.resourceTypeName = resourceType.getName();
    return resourceType;
}
Also used : NeverThrowsException(org.forgerock.util.promise.NeverThrowsException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) QueryFilter(org.forgerock.util.query.QueryFilter) ResourceType(org.forgerock.openam.entitlement.ResourceType)

Example 7 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class UpgradeResourceTypeStep method getApplicationTypeData.

private Map<String, Set<String>> getApplicationTypeData(String appTypeName) throws UpgradeException {
    try {
        ServiceConfig config = configManager.getGlobalConfig(null).getSubConfig("applicationTypes");
        if (config == null) {
            throw new UpgradeException("Expected sub config applicationTypes under service " + EntitlementUtils.SERVICE_NAME);
        }
        config = config.getSubConfig(appTypeName);
        if (config == null) {
            throw new UpgradeException("Expected to find application type " + appTypeName);
        }
        @SuppressWarnings("unchecked") Map<String, Set<String>> attributes = config.getAttributes();
        return attributes;
    } catch (SSOException | SMSException e) {
        throw new UpgradeException("Failed to retrieve application type data for " + appTypeName, e);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) CollectionUtils.transformSet(org.forgerock.openam.utils.CollectionUtils.transformSet) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 8 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class UpgradeResourceTypeStep method upgradeApplication.

/**
     * Add the resource type UUID to the application and persist it.
     * @param ec The EntitlementConfiguration for the realm in which the application resides.
     * @param appName Name of the application.
     * @param resourceTypeUUID The resource type associated with the application.
     * @throws UpgradeException If the application failed to persist.
     */
private void upgradeApplication(EntitlementConfiguration ec, String appName, String resourceTypeUUID) throws UpgradeException {
    try {
        UpgradeProgress.reportStart(AUDIT_MODIFIED_APP_UUID_START, appName);
        final Application application = ec.getApplication(appName);
        application.addAllResourceTypeUuids(Collections.singleton(resourceTypeUUID));
        ec.storeApplication(application);
        UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
    } catch (EntitlementException ee) {
        UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
        throw new UpgradeException("Failed to add resource type uuid to application " + appName, ee);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) Application(com.sun.identity.entitlement.Application)

Example 9 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class OldPolicyConditionMigrationUpgradeStep method addResourceType.

private void addResourceType(Privilege privilege, String realm) throws UpgradeException, EntitlementException {
    Application application = privilege.getEntitlement().getApplication(getAdminSubject(), realm);
    Set<String> resourceTypeUuids = application.getResourceTypeUuids();
    if (CollectionUtils.isNotEmpty(resourceTypeUuids)) {
        // UpgradeResourceTypeStep only creates one Resource Type for each application, so there should
        // only be one resource type associated with the application at this stage
        privilege.setResourceTypeUuid(application.getResourceTypeUuids().iterator().next());
    } else {
        DEBUG.error("Failed to modify privilege {} in realm {}! Associated application has no Resource Types.", privilege.getName(), realm);
        throw new UpgradeException("Failed to modify privilege!");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Application(com.sun.identity.entitlement.Application)

Example 10 with UpgradeException

use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.

the class PolicyConditionUpgrader method migrateEnvironmentConditions.

private void migrateEnvironmentConditions(Privilege privilege, MigrationReport migrationReport) throws UpgradeException, EntitlementException {
    if (privilege.getCondition() == null) {
        return;
    }
    if (privilege.getCondition() instanceof LogicalCondition) {
        LogicalCondition logicalCondition = (LogicalCondition) privilege.getCondition();
        Set<EntitlementCondition> conditions = logicalCondition.getEConditions();
        Set<EntitlementCondition> migratedConditions = new HashSet<EntitlementCondition>();
        for (EntitlementCondition condition : conditions) {
            if (!(condition instanceof PolicyCondition)) {
                //This should never happen due to check in initialise
                throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
            }
            migratedConditions.add(migrateEnvironmentCondition((PolicyCondition) condition, migrationReport));
        }
        logicalCondition.setEConditions(migratedConditions);
    } else if (privilege.getCondition() instanceof PolicyCondition) {
        privilege.setCondition(migrateEnvironmentCondition((PolicyCondition) privilege.getCondition(), migrationReport));
    } else {
        //This should never happen due to check in initialise
        throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) LogicalCondition(com.sun.identity.entitlement.LogicalCondition) HashSet(java.util.HashSet)

Aggregations

UpgradeException (org.forgerock.openam.upgrade.UpgradeException)81 SSOException (com.iplanet.sso.SSOException)29 HashMap (java.util.HashMap)27 SMSException (com.sun.identity.sm.SMSException)25 Set (java.util.Set)25 HashSet (java.util.HashSet)22 Map (java.util.Map)22 ServiceConfig (com.sun.identity.sm.ServiceConfig)21 EntitlementException (com.sun.identity.entitlement.EntitlementException)16 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)14 Application (com.sun.identity.entitlement.Application)10 IOException (java.io.IOException)10 PolicyManager (com.sun.identity.policy.PolicyManager)8 PolicyException (com.sun.identity.policy.PolicyException)6 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)6 EntitlementUtils.resourceTypeFromMap (org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)6 Node (org.w3c.dom.Node)5 ServiceSchema (com.sun.identity.sm.ServiceSchema)4 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 Properties (java.util.Properties)4