Search in sources :

Example 66 with UpgradeException

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

the class UpgradeLegacySTSStep method perform.

@Override
public void perform() throws UpgradeException {
    try {
        UpgradeProgress.reportStart("upgrade.legacy.sts.start");
        removeAgentInstances(agentsRequiringRemoval);
        performDefaultLegacySTSSharedAgentRemoval();
        performAgentSubSchemaRemoval();
        UpgradeProgress.reportEnd("upgrade.success");
    } catch (Exception e) {
        DEBUG.error("Unexpected exception caught in UpgradeLegacySTSStep#perform: " + e.getMessage(), e);
        UpgradeProgress.reportEnd("upgrade.failed");
        throw new UpgradeException("Upgrade of Legacy STS failed: " + e.getMessage(), e);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 67 with UpgradeException

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

the class UpgradeLegacySTSStep method performAgentSubSchemaRemoval.

private void performAgentSubSchemaRemoval() throws UpgradeException {
    final String nullSubSchema = null;
    //I want to obtain the AgentService Schema, so a null SubSchema identifier is passed to getServiceSchema.
    final ServiceSchema serviceSchema = UpgradeUtils.getServiceSchema(IdConstants.AGENT_SERVICE, nullSubSchema, UpgradeUtils.SCHEMA_TYPE_ORGANIZATION, getAdminToken());
    if (serviceSchema == null) {
        throw new UpgradeException("Could not obtain ServiceSchema for AgentService. Legacy STS AgentService SubSchema elements cannot be removed.");
    }
    for (String subSchemaName : subSchemasRequiringRemoval) {
        UpgradeUtils.removeSubSchema(IdConstants.AGENT_SERVICE, subSchemaName, serviceSchema);
        removedSubSchemas.add(subSchemaName);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceSchema(com.sun.identity.sm.ServiceSchema)

Example 68 with UpgradeException

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

the class UpgradeLegacySTSStep method performDefaultLegacySTSSharedAgentRemoval.

private void performDefaultLegacySTSSharedAgentRemoval() throws UpgradeException {
    try {
        if (removeDefaultLegacySTSSharedAgent) {
            final ServiceConfig baseService = getOrganizationConfigForAgentService(ROOT_REALM);
            if (baseService != null) {
                baseService.removeSubConfig(LEGACY_STS_RELATED_SHARED_AGENT_NAME);
                removedAgents.add(new ToBeRemovedAgentState(LEGACY_STS_RELATED_SHARED_AGENT_NAME, ROOT_REALM, SHARED_AGENT_SCHEMA_ID));
            } else {
                errorMessages.add("When attempting to remove the shared agent associated with the legacy sts named " + LEGACY_STS_RELATED_SHARED_AGENT_NAME + " no ServiceConfig could be obtained. Removal failed.");
            }
        }
    } catch (SMSException | SSOException e) {
        String message = "Exception caught removing the shared agent associated with the legacy sts named " + LEGACY_STS_RELATED_SHARED_AGENT_NAME + ". Exception: " + e;
        DEBUG.error(message, e);
        throw new UpgradeException(message);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 69 with UpgradeException

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

the class PolicyConditionUpgrader method migrateSubjectConditions.

private void migrateSubjectConditions(Privilege privilege, MigrationReport migrationReport) throws UpgradeException, EntitlementException {
    if (privilege.getSubject() == null) {
        return;
    }
    if (privilege.getSubject() instanceof NoSubject) {
        return;
    }
    if (privilege.getSubject() instanceof LogicalSubject) {
        LogicalSubject logicalSubject = (LogicalSubject) privilege.getSubject();
        Set<EntitlementSubject> subjects = logicalSubject.getESubjects();
        Set<EntitlementSubject> migratedSubjects = new HashSet<EntitlementSubject>();
        for (EntitlementSubject subject : subjects) {
            if (subject instanceof NoSubject) {
                //pass this through directly
                migratedSubjects.add(subject);
            } else if (!(subject instanceof PolicySubject)) {
                //This should never happen due to check in initialise
                throw new UpgradeException("Cannot upgrade a subject condition that is not of PolicySubject type!");
            } else {
                migratedSubjects.add(migrateSubjectCondition((PolicySubject) subject, migrationReport));
            }
        }
        logicalSubject.setESubjects(migratedSubjects);
    } else if (privilege.getSubject() instanceof PolicySubject) {
        privilege.setSubject(migrateSubjectCondition((PolicySubject) privilege.getSubject(), migrationReport));
    } else {
        //This should never happen due to check in initialise
        throw new UpgradeException("Cannot upgrade a subject condition that is not of PolicySubject type!");
    }
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) NoSubject(com.sun.identity.entitlement.NoSubject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) HashSet(java.util.HashSet)

Example 70 with UpgradeException

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

the class UpgradeOAuth2AuthModulesStep method initialize.

@Override
public void initialize() throws UpgradeException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, getAdminToken());
        for (String realm : getRealmNames()) {
            ServiceConfig realmConfig = scm.getOrganizationConfig(realm, null);
            for (String moduleName : (Set<String>) realmConfig.getSubConfigNames()) {
                ServiceConfig moduleConfig = realmConfig.getSubConfig(moduleName);
                Map<String, Set<?>> attributes = getAttributes(moduleConfig);
                check(attributes, ACCOUNT_MAPPER_PROPERTY, DEFAULT_ACCOUNT_MAPPER, realm, moduleName);
                check(attributes, ATTRIBUTE_MAPPER_PROPERTY, DEFAULT_ATTRIBUTE_MAPPER, realm, moduleName);
            }
        }
    } catch (ServiceNotFoundException e) {
        // When upgrading from 9.5.x and before there is no OAuth2 auth modules, so we expect this exception in this case
        DEBUG.message("OAuth2 auth modules not found. Nothing to upgrade", e);
    } catch (Exception ex) {
        DEBUG.error("An error occurred while trying to look for upgradable OAuth2 auth modules", ex);
        throw new UpgradeException("Unable to retrieve OAuth2 auth modules", ex);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException)

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