Search in sources :

Example 71 with UpgradeException

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

the class UpgradeOAuth2ClientStep method perform.

@Override
public void perform() throws UpgradeException {
    for (Map.Entry<String, Map<AgentType, Map<String, Set<String>>>> entry : upgradableConfigs.entrySet()) {
        String realm = entry.getKey();
        try {
            ServiceConfigManager scm = new ServiceConfigManager(IdConstants.AGENT_SERVICE, getAdminToken());
            for (Map.Entry<AgentType, Map<String, Set<String>>> changes : entry.getValue().entrySet()) {
                AgentType type = changes.getKey();
                ServiceConfig sc = scm.getOrganizationConfig(realm, type.instanceName);
                for (Map.Entry<String, Set<String>> subConfig : changes.getValue().entrySet()) {
                    UpgradeProgress.reportStart("upgrade.oauth2.start", subConfig.getKey());
                    ServiceConfig oauth2Config = sc.getSubConfig(subConfig.getKey());
                    Map<String, Set<String>> attrs = oauth2Config.getAttributesWithoutDefaults();
                    for (String attrName : subConfig.getValue()) {
                        if (CHANGED_PROPERTIES.contains(attrName)) {
                            Set<String> values = attrs.get(attrName);
                            // If single string scopes are included in the Scope(s) or Default Scope(s), then apend a pipe.
                            if (VersionUtils.isCurrentVersionLessThan(AM_13, true) && (SCOPES.equals(attrName) || DEFAULT_SCOPES.equals(attrName))) {
                                addScopesWithPipe(attrs, attrName, values);
                            }
                            String value = CollectionHelper.getMapAttr(attrs, attrName);
                            if (value != null) {
                                if (!pattern.matcher(value).matches()) {
                                    if (values != null) {
                                        attrs.put(attrName, convertValues(values));
                                    }
                                }
                            }
                        } else if (IDTOKEN_SIGNED_RESPONSE_ALG.equals(attrName)) {
                            String value = CollectionHelper.getMapAttr(attrs, attrName);
                            if (ALGORITHM_NAMES.containsKey(value)) {
                                attrs.put(attrName, Collections.singleton(ALGORITHM_NAMES.get(value)));
                            }
                        } else if (ADDED_LIFETIME_PROPERTIES.contains(attrName)) {
                            attrs.put(attrName, Collections.singleton("0"));
                        }
                    }
                    oauth2Config.setAttributes(attrs);
                    UpgradeProgress.reportEnd("upgrade.success");
                }
            }
        } catch (Exception ex) {
            UpgradeProgress.reportEnd("upgrade.failed");
            DEBUG.error("An error occurred while trying to upgrade an OAuth2 client", ex);
            throw new UpgradeException("Unable to upgrade OAuth2 client");
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 72 with UpgradeException

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

the class UpgradeOAuth2ProviderStep method persistDefaultsForProviders.

private void persistDefaultsForProviders() throws UpgradeException {
    try {
        for (Map.Entry<String, Map<String, Set<String>>> entry : attributesToUpdate.entrySet()) {
            final String realm = entry.getKey();
            UpgradeProgress.reportStart("upgrade.oauth2.provider.start", realm);
            final ServiceConfig serviceConfig = scm.getOrganizationConfig(realm, null);
            Map<String, Set<String>> attributes = entry.getValue();
            if (attributes == null) {
                attributes = serviceConfig.getAttributesWithoutDefaults();
            }
            renameAlgorithms(attributes);
            sortScopes(attributes);
            serviceConfig.setAttributes(attributes);
            UpgradeProgress.reportEnd("upgrade.success");
        }
    } catch (Exception e) {
        UpgradeProgress.reportEnd("upgrade.failed");
        DEBUG.error("An error occurred while trying to upgrade an OAuth2 Provider", e);
        throw new UpgradeException("Unable to upgrade OAuth2 Providers.", e);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) HashMap(java.util.HashMap) Map(java.util.Map) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException)

Example 73 with UpgradeException

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

the class UpgradeServiceUtils method getServiceDefinitions.

/**
     * Loads a DOM {@code Document} for each defined service.
     * @param token The admin token.
     * @return A map of service name to the service DOM models.
     * @throws UpgradeException When the service XML cannot be loaded.
     */
static Map<String, Document> getServiceDefinitions(SSOToken token) throws UpgradeException {
    List<String> serviceNames = new ArrayList<>();
    serviceNames.addAll(UpgradeUtils.getPropertyValues(SetupConstants.PROPERTY_FILENAME, SetupConstants.SERVICE_NAMES));
    Map<String, Document> newServiceDefinitions = new HashMap<>();
    String basedir = SystemProperties.get(SystemProperties.CONFIG_PATH);
    ServicesDefaultValues.setServiceConfigValues(getUpgradeHttpServletRequest(basedir, token));
    for (String serviceFileName : serviceNames) {
        boolean tagswap = true;
        if (serviceFileName.startsWith("*")) {
            serviceFileName = serviceFileName.substring(1);
            tagswap = false;
        }
        String strXML;
        try {
            strXML = IOUtils.readStream(UpgradeServiceUtils.class.getClassLoader().getResourceAsStream(serviceFileName));
        } catch (IOException ioe) {
            DEBUG.error("unable to load services file: " + serviceFileName, ioe);
            throw new UpgradeException(ioe);
        }
        if (tagswap) {
            strXML = ServicesDefaultValues.tagSwap(strXML, true);
        }
        Document serviceSchema = fetchDocumentSchema(strXML, token);
        newServiceDefinitions.put(UpgradeUtils.getServiceName(serviceSchema), serviceSchema);
    }
    return newServiceDefinitions;
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 74 with UpgradeException

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

the class UpgradeServiceUtils method setUserAndPassword.

private static void setUserAndPassword(IHttpServletRequest requestFromFile, String basedir) throws UpgradeException {
    try {
        BootstrapData bootStrap = new BootstrapData(basedir);
        Map<String, String> data = bootStrap.getDataAsMap(0);
        requestFromFile.addParameter(SetupConstants.CONFIG_VAR_DS_MGR_DN, data.get(BootstrapData.DS_MGR));
        requestFromFile.addParameter(SetupConstants.CONFIG_VAR_DS_MGR_PWD, JCECrypt.decode(data.get(BootstrapData.DS_PWD)));
    } catch (IOException ioe) {
        DEBUG.error("Unable to load directory user/password from bootstrap file", ioe);
        throw new UpgradeException("Unable to load bootstrap file: " + ioe.getMessage());
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) BootstrapData(com.sun.identity.setup.BootstrapData) IOException(java.io.IOException)

Example 75 with UpgradeException

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

the class UpgradeServiceUtils method getUpgradeHttpServletRequest.

private static IHttpServletRequest getUpgradeHttpServletRequest(String basedir, SSOToken token) throws UpgradeException {
    // need to reinitialize the tag swap property map with original install params
    IHttpServletRequest requestFromFile = new UpgradeHttpServletRequest(basedir);
    try {
        Properties foo = ServerConfiguration.getServerInstance(token, WebtopNaming.getLocalServer());
        requestFromFile.addParameter(SetupConstants.CONFIG_VAR_ENCRYPTION_KEY, foo.getProperty(Constants.ENC_PWD_PROPERTY));
        String dbOption = (String) requestFromFile.getParameterMap().get(SetupConstants.CONFIG_VAR_DATA_STORE);
        boolean embedded = dbOption.equals(SetupConstants.SMS_EMBED_DATASTORE);
        if (!embedded) {
            setUserAndPassword(requestFromFile, basedir);
        }
    } catch (Exception ex) {
        DEBUG.error("Unable to initialise services defaults", ex);
        throw new UpgradeException("Unable to initialise services defaults: " + ex.getMessage());
    }
    return requestFromFile;
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) IHttpServletRequest(com.sun.identity.setup.IHttpServletRequest) Properties(java.util.Properties) SystemProperties(com.iplanet.am.util.SystemProperties) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) IOException(java.io.IOException) UpgradeHttpServletRequest(org.forgerock.openam.upgrade.UpgradeHttpServletRequest)

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