Search in sources :

Example 31 with UpgradeException

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

the class SchemaResourceNamesStep method initialize.

@Override
public void initialize() throws UpgradeException {
    if (VersionUtils.isCurrentVersionLessThan(AM_13, true)) {
        Map<String, Document> serviceXmlContent = UpgradeServiceUtils.getServiceDefinitions(getAdminToken());
        serviceModifications = new HashMap<>();
        for (Map.Entry<String, Document> service : serviceXmlContent.entrySet()) {
            try {
                DEBUG.message("Finding resource names in {}", service.getKey());
                ServiceModifier modifier = new ServiceModifier();
                NodeList nodes = (NodeList) xpath.evaluate("//*[@" + RESOURCE_NAME + "]", service.getValue().getDocumentElement(), XPathConstants.NODESET);
                for (int i = 0; i < nodes.getLength(); i++) {
                    Element element = (Element) nodes.item(i);
                    ElementModifier target = buildPath(element, modifier);
                    target.resourceNameModifier = new ResourceNameModifier(element.getAttribute(RESOURCE_NAME));
                }
                if (!modifier.modifiers.isEmpty()) {
                    serviceModifications.put(service.getKey(), modifier);
                }
            } catch (XPathExpressionException e) {
                throw new UpgradeException(e);
            }
        }
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with UpgradeException

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

the class TwoStepVerificationSettingUpgrade method initialize.

@Override
public void initialize() throws UpgradeException {
    try {
        // Does the policy already exist...
        manager = new PolicyManager(getAdminToken(), HIDDEN_REALM);
        applicable = manager.getPolicyNames(EVALUATE_POLICY).isEmpty();
    } catch (SSOException ssoE) {
        throw new UpgradeException("Failed to identify existing privileges", ssoE);
    } catch (PolicyException pE) {
        throw new UpgradeException("Failed to identify existing privileges", pE);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) PolicyManager(com.sun.identity.policy.PolicyManager) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException)

Example 33 with UpgradeException

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

the class UpgradeOAuth2AuthModulesStep method perform.

@Override
public void perform() throws UpgradeException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, getAdminToken());
        for (Map.Entry<String, Set<String>> realm : affectedRealms.entrySet()) {
            ServiceConfig realmConfig = scm.getOrganizationConfig(realm.getKey(), null);
            for (String moduleName : realm.getValue()) {
                ServiceConfig moduleConfig = realmConfig.getSubConfig(moduleName);
                Map<String, Set<?>> attributes = getAttributes(moduleConfig);
                if (attributes.get(ACCOUNT_MAPPER_PROPERTY).contains(DEFAULT_ACCOUNT_MAPPER)) {
                    moduleConfig.replaceAttributeValues(ACCOUNT_MAPPER_PROPERTY, asSet(DEFAULT_ACCOUNT_MAPPER), asSet(JSON_MAPPER));
                }
                if (attributes.get(ATTRIBUTE_MAPPER_PROPERTY).contains(DEFAULT_ATTRIBUTE_MAPPER)) {
                    moduleConfig.replaceAttributeValues(ATTRIBUTE_MAPPER_PROPERTY, asSet(DEFAULT_ATTRIBUTE_MAPPER), asSet(JSON_MAPPER));
                }
                moduleCount++;
            }
        }
    } catch (Exception ex) {
        DEBUG.error("An error occurred while trying to update OAuth2 auth modules", ex);
        throw new UpgradeException("Unable to update OAuth2 modules", ex);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException)

Example 34 with UpgradeException

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

the class UpgradeOAuth2ClientStep method initialize.

@Override
public void initialize() throws UpgradeException {
    try {
        ServiceConfigManager scm = new ServiceConfigManager(IdConstants.AGENT_SERVICE, getAdminToken());
        for (String realm : getRealmNames()) {
            findUpgradableConfigs(realm, scm, AgentType.AGENT);
            findUpgradableConfigs(realm, scm, AgentType.GROUP);
        }
    } catch (Exception ex) {
        DEBUG.error("An error occurred while trying to look for upgradable OAuth2 client profiles", ex);
        throw new UpgradeException("Unable to retrieve modified OAuth2 clients");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 35 with UpgradeException

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

the class ServiceSchemaModifications method getAttributesModified.

private Set<AttributeSchemaImpl> getAttributesModified(Set<AttributeSchemaImpl> newAttrs, Set<AttributeSchemaImpl> existingAttrs) throws UpgradeException {
    Set<AttributeSchemaImpl> attrMods = new HashSet<AttributeSchemaImpl>();
    for (AttributeSchemaImpl newAttr : newAttrs) {
        // skip attributes that are not explicitly named for upgrade
        if (ServerUpgrade.getServiceHelper(serviceName) == null || !ServerUpgrade.getServiceHelper(serviceName).getAttributes().contains(newAttr.getName())) {
            continue;
        }
        for (AttributeSchemaImpl existingAttr : existingAttrs) {
            if (!existingAttr.getName().equals(newAttr.getName())) {
                continue;
            }
            try {
                UpgradeHelper helper = ServerUpgrade.getServiceHelper(serviceName);
                AttributeSchemaImpl upgradedAttr = helper.upgradeAttribute(existingAttr, newAttr);
                if (upgradedAttr != null) {
                    attrMods.add(upgradedAttr);
                }
            } catch (UpgradeException ue) {
                UpgradeUtils.debug.error("Unable to process upgrade helper", ue);
                throw ue;
            }
        }
    }
    return attrMods;
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) UpgradeHelper(org.forgerock.openam.upgrade.UpgradeHelper) 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