Search in sources :

Example 96 with ServiceConfigManager

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

the class UpgradeUtils method deleteService.

public static void deleteService(String serviceName, SSOToken adminToken) throws UpgradeException {
    String classMethod = "UpgradeUtils:deleteService : ";
    try {
        ServiceManager sm = new ServiceManager(adminToken);
        ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminToken);
        if (scm.getGlobalConfig(null) != null) {
            scm.removeGlobalConfiguration(null);
        }
        ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminToken);
        Set<String> versions = sm.getServiceVersions(serviceName);
        if (ssm.getPolicySchema() == null) {
            if (debug.messageEnabled()) {
                debug.message("Service has policy schema; matching policy schema will be removed");
            }
            deletePolicyRule(serviceName, adminToken);
        }
        for (String version : versions) {
            sm.removeService(serviceName, version);
        }
    } catch (SSOException ssoe) {
        debug.error(classMethod + ssoe.getMessage());
        throw new UpgradeException(ssoe);
    } catch (SMSException smse) {
        debug.error(classMethod + smse.getMessage());
        throw new UpgradeException(smse);
    } catch (AMException ame) {
        debug.error(classMethod + ame.getMessage());
        throw new UpgradeException(ame);
    }
}
Also used : SMSException(com.sun.identity.sm.SMSException) ServiceManager(com.sun.identity.sm.ServiceManager) AMException(com.iplanet.am.sdk.AMException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager)

Example 97 with ServiceConfigManager

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

the class UpgradeUtils method removeSubConfigAttributeDefaultValues.

/**
     * Removes attributes default values from service subconfiguration.
     *
     * @param serviceName name of the service
     * @param sunServiceID set of service identifiers
     * @param realm the realm name
     * @param subConfigName the service sub-configuration name.
     * @param attributeName name of the attribute
     * @param defaultValues a set of values to be removed
     */
public static void removeSubConfigAttributeDefaultValues(String serviceName, Set sunServiceID, String realm, String subConfigName, String attributeName, Set defaultValues) {
    String classMethod = "UpgradeUtils:removeSubConfigAttributeDefaultValues : ";
    try {
        ServiceConfigManager scm = getServiceConfigManager(serviceName);
        ServiceConfig sc = scm.getOrganizationConfig(realm, null);
        ServiceConfig subConfig = sc.getSubConfig(subConfigName);
        String serviceID = getSunServiceID(subConfig);
        if (debug.messageEnabled()) {
            debug.message(classMethod + "sunServiceID :" + sunServiceID);
            debug.message(classMethod + "serviceID :" + serviceID);
            debug.message(classMethod + "subConfigName :" + subConfigName);
            debug.message(classMethod + "Attribute Name :" + attributeName);
            debug.message(classMethod + "Default Values :" + defaultValues);
        }
        if (sunServiceID.contains(serviceID)) {
            Set valSet = getExistingValues(subConfig, attributeName, defaultValues);
            if (debug.messageEnabled()) {
                debug.message(classMethod + "Values to be removed" + valSet);
            }
            subConfig.removeAttributeValues(attributeName, valSet);
        }
    } catch (SSOException ssoe) {
        debug.error(classMethod + "Invalid SSOToken  : ", ssoe);
    } catch (SMSException sme) {
        debug.error(classMethod + "Error remove default values : ", sme);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 98 with ServiceConfigManager

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

the class UpgradeUtils method addAttributeToSubConfiguration.

/**
     * Adds attributes to service sub configuration.
     *
     * @param serviceName the service name
     * @param subConfigName the sub configuration name
     * @param attrValues Map of attributes key is the attribute name and
     *        value a set of attribute values.
     * @throws UpgradeException on error.
     */
public static void addAttributeToSubConfiguration(String serviceName, String subConfigName, Map attrValues) throws UpgradeException {
    String classMethod = "UpgradeUtils:addAttributeToSubConfiguration : ";
    try {
        ServiceConfigManager scm = getServiceConfigManager(serviceName);
        ServiceConfig sc = scm.getGlobalConfig(null);
        StringTokenizer st = new StringTokenizer(subConfigName, "/");
        int tokenCount = st.countTokens();
        for (int i = 1; i <= tokenCount; i++) {
            String scn = st.nextToken();
            sc = sc.getSubConfig(scn);
        }
        for (Iterator i = attrValues.keySet().iterator(); i.hasNext(); ) {
            String attrName = (String) i.next();
            sc.addAttribute(attrName, (Set) attrValues.get(attrName));
        }
    } catch (SMSException sme) {
        throw new UpgradeException("Unable to add attribute to subconfig");
    } catch (SSOException ssoe) {
        throw new UpgradeException("invalid SSOToken");
    } catch (Exception e) {
        debug.error(classMethod + "Error adding attribute to subconfig:", e);
    }
    if (debug.messageEnabled()) {
        debug.message(classMethod + "Added attributes " + attrValues + " to subconfig " + subConfigName + " in service " + serviceName);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Example 99 with ServiceConfigManager

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

the class UpgradeUtils method getOrgSubConfigs.

/**
     * Return sub configurations in a service.
     *
     * @param serviceName the service name.
     * @param serviceVersion the version of the service
     * @param realm the realm to retreive the sub configs from.
     * @return a set containing the org sub configurations.
     */
static Set getOrgSubConfigs(String serviceName, String serviceVersion, String realm) {
    String classMethod = "UpgradeUtils:getOrgSubConfigs : ";
    Set subConfigs;
    try {
        ServiceConfigManager scm = new ServiceConfigManager(ssoToken, serviceName, serviceVersion);
        ServiceConfig orgConfig = scm.getOrganizationConfig(realm, null);
        subConfigs = orgConfig.getSubConfigNames();
        if (debug.messageEnabled()) {
            debug.message(classMethod + "Org subConfigs : " + subConfigs);
        }
    } catch (Exception e) {
        if (debug.messageEnabled()) {
            debug.message(classMethod + "No organization subconfigs", e);
        }
        subConfigs = Collections.EMPTY_SET;
    }
    return subConfigs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) ByteString(org.forgerock.opendj.ldap.ByteString) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Example 100 with ServiceConfigManager

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

the class RemoveNetscapeLDAPStep method initialize.

@Override
public void initialize() throws UpgradeException {
    try {
        if (VersionUtils.isCurrentVersionLessThan(AM_13, true)) {
            for (String realm : getRealmNames()) {
                ServiceConfigManager scm = new ServiceConfigManager(IdConstants.REPO_SERVICE, getAdminToken());
                ServiceConfig sc = scm.getOrganizationConfig(realm, null);
                if (sc != null) {
                    Set<String> subConfigNames = sc.getSubConfigNames("*", NETSCAPE_LDAP_V3);
                    if (!subConfigNames.isEmpty()) {
                        Set<String> names = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
                        names.addAll(subConfigNames);
                        subSchemaIds.put(realm, names);
                    }
                }
            }
            ServiceSchemaManager ssm = new ServiceSchemaManager(IdConstants.REPO_SERVICE, getAdminToken());
            ServiceSchema orgSchema = ssm.getOrganizationSchema();
            if (orgSchema.getSubSchemaNames().contains(NETSCAPE_LDAP_V3)) {
                removeSubSchema = true;
            }
        }
    } catch (Exception ex) {
        DEBUG.error("Unable to identify old datastore configurations", ex);
        throw new UpgradeException("An error occured while trying to identify old datastore configurations");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ServiceSchema(com.sun.identity.sm.ServiceSchema) ServiceConfig(com.sun.identity.sm.ServiceConfig) TreeSet(java.util.TreeSet) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) UpgradeException(org.forgerock.openam.upgrade.UpgradeException)

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