Search in sources :

Example 6 with ServiceConfigManager

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

the class AuthenticatedSharedAgents method getOrgConfig.

// Returns the organization configuration of the 'default' group
// from AgentService.
private ServiceConfig getOrgConfig(SSOToken token, String realmName) {
    if (debug.messageEnabled()) {
        debug.message("AuthenticatedSharedAgents.getOrgConfig() called. ");
    }
    ServiceConfig orgConfigCache = null;
    try {
        // Check in cache first
        if ((realmCache != null) && (!realmCache.isEmpty()) && (realmCache.containsKey(realmName))) {
            orgConfigCache = (ServiceConfig) realmCache.get(realmName);
            if (orgConfigCache.isValid()) {
                debug.message("AuthenticatedSharedAgents.getOrgConfig() found in cache.");
                return (orgConfigCache);
            }
        }
        if (scm == null) {
            scm = new ServiceConfigManager(token, agentserviceName, version);
        }
        orgConfigCache = scm.getOrganizationConfig(realmName, null);
        // Update the realm cache.
        updateRealmCache(realmName, orgConfigCache);
    } catch (SMSException smse) {
        if (debug.warningEnabled()) {
            debug.warning("AuthenticatedSharedAgents.getOrgConfig(): " + "Unable to get organization config due to " + smse);
        }
    } catch (SSOException ssoe) {
        if (debug.warningEnabled()) {
            debug.warning("AuthenticatedSharedAgents.getOrgConfig(): " + "Unable to get organization config due to " + ssoe);
        }
    }
    return (orgConfigCache);
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 7 with ServiceConfigManager

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

the class ScriptingSchemaStep method perform.

@Override
public void perform() throws UpgradeException {
    try {
        ServiceConfigManager configManager = new ServiceConfigManager(SCRIPTING_SERVICE_NAME, getAdminToken());
        ServiceConfig globalConfig = configManager.getGlobalConfig(null);
        upgradeEngineConfiguration(globalConfig);
        upgradeScriptConfiguration(globalConfig);
    } catch (SMSException | SSOException e) {
        UpgradeProgress.reportEnd("upgrade.failed");
        DEBUG.error("An error occurred while trying to upgrade the Scripting global settings", e);
        throw new UpgradeException("Unable to upgrade Scripting global settings", e);
    }
}
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) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 8 with ServiceConfigManager

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

the class ResourceTypeServiceConfig method getOrgConfig.

/**
     * Get the organization configuration for the sunEntitlementService service.
     * @param subject The subject used to retrieve the SSO token.
     * @param realm The realm from which to retrieve it.
     * @return The organization configuration, which is guaranteed to not be null.
     * @throws SMSException If the sub configuration could not be read.
     * @throws SSOException If the Admin token could not be found.
     */
ServiceConfig getOrgConfig(Subject subject, String realm) throws SMSException, SSOException {
    final SSOToken token = getSSOToken(subject);
    if (token == null) {
        throw new SSOException("Could not find Admin token.");
    }
    ServiceConfig orgConfig = new ServiceConfigManager(SERVICE_NAME, token).getOrganizationConfig(realm, null);
    if (orgConfig == null) {
        throw new SMSException("Configuration '" + SERVICE_NAME + "' in realm '" + realm + "' could not be retrieved.");
    }
    return orgConfig;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 9 with ServiceConfigManager

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

the class MigrateValidGotoSetting method initialize.

@Override
public void initialize() throws UpgradeException {
    try {
        final PolicyManager pm = new PolicyManager(getAdminToken(), HIDDEN_REALM);
        if (pm.getPolicyNames(DELEGATION_POLICY_NAME).isEmpty()) {
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Unable to find the delegation policy in the hidden realm, looking for existing goto" + " domain values.");
            }
            //The delegation policy is not defined yet in the configuration, we need to migrate the goto domains.
            final ServiceConfigManager scm = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, getAdminToken());
            for (final String realm : getRealmNames()) {
                if (DEBUG.messageEnabled()) {
                    DEBUG.message("Looking for valid goto URLs in realm " + realm);
                }
                final ServiceConfig organizationConfig = scm.getOrganizationConfig(realm, null);
                final Map<String, Set<String>> attrs = organizationConfig.getAttributesWithoutDefaults();
                final Set<String> validDomains = attrs.get(LEGACY_GOTO_DOMAINS_SETTING);
                if (validDomains != null && !validDomains.isEmpty()) {
                    changes.put(realm, validDomains);
                }
            }
            if (DEBUG.messageEnabled()) {
                DEBUG.message("Found the following existing goto URL domains in realms: " + changes);
            }
        } else {
            delegationPolicyFound = true;
        }
    } catch (final NameNotFoundException nnfe) {
        throw new UpgradeException("Unable to find hidden realm", nnfe);
    } catch (final PolicyException pe) {
        throw new UpgradeException("Unexpected error occurred while retrieving policies from the hidden realm", pe);
    } catch (final SMSException smse) {
        throw new UpgradeException("An error occurred while checking for old valid goto domains", smse);
    } catch (final SSOException ssoe) {
        throw new UpgradeException("An error occurred while checking for old valid goto domains", ssoe);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) PolicyManager(com.sun.identity.policy.PolicyManager) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 10 with ServiceConfigManager

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

Aggregations

ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)163 ServiceConfig (com.sun.identity.sm.ServiceConfig)123 SMSException (com.sun.identity.sm.SMSException)116 SSOException (com.iplanet.sso.SSOException)107 SSOToken (com.iplanet.sso.SSOToken)53 Set (java.util.Set)50 Map (java.util.Map)31 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)28 CLIException (com.sun.identity.cli.CLIException)17 Iterator (java.util.Iterator)16 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)15 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)13 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)12 ByteString (org.forgerock.opendj.ldap.ByteString)12 JsonValue (org.forgerock.json.JsonValue)10 IOException (java.io.IOException)9 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)9 IOutput (com.sun.identity.cli.IOutput)8 PolicyException (com.sun.identity.policy.PolicyException)7