Search in sources :

Example 96 with ServiceConfig

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

the class MigrateValidGotoSetting method perform.

@Override
public void perform() throws UpgradeException {
    try {
        if (!changes.isEmpty()) {
            final ServiceConfigManager validationService = new ServiceConfigManager(VALIDATION_SERVICE, getAdminToken());
            final ServiceConfigManager authService = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, getAdminToken());
            for (final Map.Entry<String, Set<String>> entry : changes.entrySet()) {
                final String realm = entry.getKey();
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("Starting to migrate goto domains for realm: " + realm);
                }
                UpgradeProgress.reportStart("upgrade.goto.migrate.start", realm);
                validationService.createOrganizationConfig(realm, getAttrMap(GOTO_RESOURCES, entry.getValue()));
                //The settings now are migrated, we should now clear up the legacy settings
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("Removing old goto domains from iPlanetAMAuthService");
                }
                final ServiceConfig organizationConfig = authService.getOrganizationConfig(realm, null);
                organizationConfig.setAttributes(getAttrMap(LEGACY_GOTO_DOMAINS_SETTING, Collections.EMPTY_SET));
                UpgradeProgress.reportEnd("upgrade.success");
            }
        }
        if (DEBUG.messageEnabled()) {
            DEBUG.message("Attempting to create the delegation policy in the hidden realm");
        }
        UpgradeProgress.reportStart("upgrade.goto.policy.start");
        final PolicyManager pm = new PolicyManager(getAdminToken(), HIDDEN_REALM);
        String policy = AMSetupServlet.readFile(DELEGATION_POLICY_FILE);
        policy = ServicesDefaultValues.tagSwap(policy, true);
        //Adding the delegation privileges to allow agent accounts to read the new validationService.
        PolicyUtils.createPolicies(pm, new ByteArrayInputStream(policy.getBytes()));
        if (DEBUG.messageEnabled()) {
            DEBUG.message("Delegation policy successfully created under the hidden realm");
        }
        UpgradeProgress.reportEnd("upgrade.success");
    } catch (final IOException ioe) {
        UpgradeProgress.reportEnd("upgrade.failed");
        throw new UpgradeException("An IO error occurred while reading the delegation policy", ioe);
    } catch (final PolicyException pe) {
        UpgradeProgress.reportEnd("upgrade.failed");
        throw new UpgradeException("An unexpected error occurred while importing the delegation policy", pe);
    } catch (final SMSException smse) {
        UpgradeProgress.reportEnd("upgrade.failed");
        throw new UpgradeException("An error occurred while migrating the valid goto domain setting", smse);
    } catch (final SSOException ssoe) {
        UpgradeProgress.reportEnd("upgrade.failed");
        throw new UpgradeException("An error occurred while migrating the valid goto domain setting", ssoe);
    }
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) Set(java.util.Set) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) IOException(java.io.IOException) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceConfig(com.sun.identity.sm.ServiceConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) PolicyException(com.sun.identity.policy.PolicyException) HashMap(java.util.HashMap) Map(java.util.Map) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 97 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 98 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 99 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 100 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)

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