Search in sources :

Example 36 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.

the class UpgradeOAuth2ProviderStep method findUpgradableProviders.

private void findUpgradableProviders() throws UpgradeException {
    try {
        final ServiceSchema serviceSchema = ssm.getOrganizationSchema();
        for (String realm : getRealmNames()) {
            final ServiceConfig serviceConfig = scm.getOrganizationConfig(realm, null);
            final Map<String, Set<String>> withDefaults = serviceConfig.getAttributesForRead();
            final Map<String, Set<String>> withoutDefaults = serviceConfig.getAttributesWithoutDefaultsForRead();
            final Map<String, Set<String>> withoutValidators = SMSUtils.removeValidators(withDefaults, serviceSchema);
            if (isProviderRelyingOnDefaults(withoutDefaults, withoutValidators)) {
                attributesToUpdate.put(realm, withoutValidators);
            } else if (shouldUpgradeClaims(withDefaults)) {
                attributesToUpdate.put(realm, withoutValidators);
            } else if (shouldUpgradeAlgorithmName(withoutDefaults)) {
                attributesToUpdate.put(realm, null);
            }
        }
    } catch (Exception e) {
        DEBUG.error("An error occurred while trying to look for upgradable OAuth2 Providers.", e);
        throw new UpgradeException("Unable to retrieve OAuth2 Providers.", e);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException)

Example 37 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.

the class UpgradeEntitlementsStep method perform.

@Override
public void perform() throws UpgradeException {
    try {
        ServiceConfig appType = getDefaultApplicationType();
        Map<String, Set<String>> attrs = new HashMap<String, Set<String>>();
        UpgradeProgress.reportStart("upgrade.apptype.start");
        attrs.put(SEARCH_INDEX_IMPL, asSet(NEW_SEARCH_IMPL));
        attrs.put(SAVE_INDEX_IMPL, asSet(NEW_SAVE_IMPL));
        appType.setAttributes(attrs);
        UpgradeProgress.reportEnd("upgrade.success");
        DEBUG.message("Entitlement service is now using the new TreeSearchIndex/TreeSaveIndex implementations");
        if (!upgradableConfigs.isEmpty()) {
            for (Map.Entry<String, Map<PolicyType, Set<String>>> entry : upgradableConfigs.entrySet()) {
                String realm = entry.getKey();
                Map<PolicyType, Set<String>> changes = entry.getValue();
                PolicyManager pm = new PolicyManager(getAdminToken(), realm);
                Set<String> referrals = changes.get(PolicyType.REFERRAL);
                //  all set up
                if (referrals != null) {
                    upgradeReferrals(pm, referrals);
                }
            }
            //the entitlements are upgraded regardless of the realms
            upgradeEntitlementIndexes();
        }
    } catch (Exception ex) {
        UpgradeProgress.reportEnd("upgrade.failed");
        DEBUG.error("An error occurred while upgrading entitlements data", ex);
        throw new UpgradeException(ex);
    }
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) HashSet(java.util.HashSet) Set(java.util.Set) CollectionUtils.asSet(org.forgerock.openam.utils.CollectionUtils.asSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 38 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.

the class UpgradeLegacySTSStep method populateToBeRemovedAgents.

private void populateToBeRemovedAgents(String realm) throws UpgradeException {
    try {
        ServiceConfig baseService = getOrganizationConfigForAgentService(realm);
        Set<String> subConfigNames = baseService.getSubConfigNames();
        for (String agentName : subConfigNames) {
            final ServiceConfig agentInstance = baseService.getSubConfig(agentName);
            if (TO_BE_REMOVED_SUB_SCHEMA_NAMES.contains(agentInstance.getSchemaID())) {
                agentsRequiringRemoval.add(new ToBeRemovedAgentState(agentName, realm, agentInstance.getSchemaID()));
            }
        }
    } catch (SMSException | SSOException e) {
        throw new UpgradeException("Could not determine the legacy-sts-related agents to remove for realm " + realm + ". Exception: " + e.getMessage());
    }
}
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 39 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.

the class UpgradeLegacySTSStep method determineDefaultLegacySTSSharedAgentRemoval.

private void determineDefaultLegacySTSSharedAgentRemoval() throws UpgradeException {
    try {
        ServiceConfig baseService = getOrganizationConfigForAgentService(ROOT_REALM);
        Set<String> subConfigNames = baseService.getSubConfigNames();
        if (subConfigNames.contains(LEGACY_STS_RELATED_SHARED_AGENT_NAME)) {
            final ServiceConfig agentInstance = baseService.getSubConfig(LEGACY_STS_RELATED_SHARED_AGENT_NAME);
            if (SHARED_AGENT_SCHEMA_ID.equals(agentInstance.getSchemaID())) {
                Map<String, Set<String>> attributes = agentInstance.getAttributesWithoutDefaultsForRead();
                if (attributes != null) {
                    Set<String> sharedSet = attributes.get(AGENTS_ALLOWED_TO_READ_ATTRIBUTE);
                    if ((sharedSet != null) && Sets.symmetricDifference(sharedSet, DEFAULT_STS_SHARED_AGENT_SHARE_SET).isEmpty()) {
                        removeDefaultLegacySTSSharedAgent = true;
                        agentsRequiringRemoval.add(new ToBeRemovedAgentState(LEGACY_STS_RELATED_SHARED_AGENT_NAME, ROOT_REALM, SHARED_AGENT_SCHEMA_ID));
                    }
                }
            }
        }
    } catch (SMSException | SSOException e) {
        throw new UpgradeException("Could not determine whether to remove the legacy-sts SharedAgent called " + LEGACY_STS_RELATED_SHARED_AGENT_NAME + " in the root realm. Exception: " + e.getMessage());
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) HashSet(java.util.HashSet) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 40 with ServiceConfig

use of com.sun.identity.sm.ServiceConfig 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)

Aggregations

ServiceConfig (com.sun.identity.sm.ServiceConfig)285 SMSException (com.sun.identity.sm.SMSException)180 Set (java.util.Set)144 SSOException (com.iplanet.sso.SSOException)143 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)124 HashSet (java.util.HashSet)119 Map (java.util.Map)101 HashMap (java.util.HashMap)96 SSOToken (com.iplanet.sso.SSOToken)52 Iterator (java.util.Iterator)41 IdRepoException (com.sun.identity.idm.IdRepoException)27 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)22 EntitlementException (com.sun.identity.entitlement.EntitlementException)19 LinkedHashSet (java.util.LinkedHashSet)18 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)17 CLIException (com.sun.identity.cli.CLIException)16 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)16 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)13 ServiceSchema (com.sun.identity.sm.ServiceSchema)12