Search in sources :

Example 26 with ConfigurationException

use of com.sun.identity.plugin.configuration.ConfigurationException in project OpenAM by OpenRock.

the class AuthnSvcService method setValues.

/**
     * Reads values from service schema.
     */
private static void setValues() {
    Map attrMap = null;
    try {
        attrMap = ci.getConfiguration(null, null);
    } catch (ConfigurationException ce) {
        AuthnSvcUtils.debug.error("AuthnSvcService.setValues:", ce);
        return;
    }
    handlers.clear();
    Set values = (Set) attrMap.get(MECHANISM_HANDLER_LIST_ATTR);
    for (Iterator iter = values.iterator(); iter.hasNext(); ) {
        String value = (String) iter.next();
        StringTokenizer stz = new StringTokenizer(value, "|");
        String key = null;
        String class_ = null;
        while (stz.hasMoreTokens()) {
            String token = stz.nextToken();
            if (token.startsWith("key=")) {
                key = token.substring(4);
            } else if (token.startsWith("class=")) {
                class_ = token.substring(6);
            }
        }
        if (key != null && class_ != null) {
            try {
                handlers.put(key, (MechanismHandler) Class.forName(class_).newInstance());
            } catch (Throwable t) {
                AuthnSvcUtils.debug.error("AuthnSvcService.setValues class = " + class_, t);
            }
        } else {
            if (AuthnSvcUtils.debug.warningEnabled()) {
                AuthnSvcUtils.debug.warning("AuthnSvcService.setValues: Invalid syntax " + "for Mechanism Handler List: " + value);
            }
        }
    }
    values = (Set) attrMap.get(PLAIN_MECHANISM_AUTH_MODULE);
    if ((values == null) || (values.isEmpty())) {
        plainMechanismAuthModule = null;
    } else {
        plainMechanismAuthModule = (String) values.iterator().next();
    }
    values = (Set) attrMap.get(CRAMMD5_MECHANISM_AUTH_MODULE);
    if ((values == null) || (values.isEmpty())) {
        cramMD5MechanismAuthModule = null;
    } else {
        cramMD5MechanismAuthModule = (String) values.iterator().next();
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 27 with ConfigurationException

use of com.sun.identity.plugin.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ConfigurationInstanceImpl method init.

/**
     * Initializer.
     * @param componentName Name of the components, e.g. SAML1, SAML2, ID-FF
     * @param session FM Session object.
     * @exception ConfigurationException if could not initialize the instance.
     */
public void init(String componentName, Object session) throws ConfigurationException {
    String serviceName = (String) serviceNameMap.get(componentName);
    if (serviceName == null) {
        throw new ConfigurationException(RESOURCE_BUNDLE, "componentNameUnsupported", null);
    }
    if ((session != null) && (session instanceof SSOToken)) {
        ssoToken = (SSOToken) session;
    }
    try {
        SSOToken adminToken = getSSOToken();
        ssm = new ServiceSchemaManager(serviceName, adminToken);
        ServiceSchema oss = ssm.getOrganizationSchema();
        if (oss != null) {
            hasOrgSchema = true;
            Set subSchemaNames = oss.getSubSchemaNames();
            if ((subSchemaNames != null) && (subSchemaNames.size() == 1)) {
                subConfigId = (String) subSchemaNames.iterator().next();
            }
        }
        scm = new ServiceConfigManager(serviceName, adminToken);
    } catch (SMSException smsex) {
        debug.error("ConfigurationInstanceImpl.init:", smsex);
        throw new ConfigurationException(smsex);
    } catch (SSOException ssoex) {
        debug.error("ConfigurationInstanceImpl.init:", ssoex);
        throw new ConfigurationException(ssoex);
    }
    this.componentName = componentName;
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) ServiceSchemaManager(com.sun.identity.sm.ServiceSchemaManager) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 28 with ConfigurationException

use of com.sun.identity.plugin.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ConfigurationInstanceImpl method getConfiguration.

/**
     * Returns Configurations.
     * @param realm the name of organization at which the configuration resides.
     * @param configName configuration instance name. e.g. "/sp".
     *     The configName could be null or empty string, which means the default
     *     configuration for this components. 
     * @return Map of key/value pairs, key is the attribute name, value is
     *     a Set of attribute values or null if service configuration doesn't
     *     doesn't exist. If the configName parameter is null or empty, and OrganizationalConfig state is present,
     *     this state will be merged with the GlobalConfig attributes, with the OrganizationConfig attributes
     *     over-writing the GlobalConfig attributes, in case GlobalConfig and OrganizationConfig attributes share the
     *     same key.
     * @exception ConfigurationException if an error occurred while getting
     *     service configuration.
     */
public Map getConfiguration(String realm, String configName) throws ConfigurationException {
    if (debug.messageEnabled()) {
        debug.message("ConfigurationInstanceImpl.getConfiguration: " + "componentName = " + componentName + ", realm = " + realm + ", configName = " + configName);
    }
    try {
        if (hasOrgSchema) {
            ServiceConfig organizationConfig = null;
            organizationConfig = scm.getOrganizationConfig(realm, null);
            if (organizationConfig == null) {
                return null;
            }
            if ((configName == null) || (configName.length() == 0)) {
                Map organizationAttributes = organizationConfig.getAttributes();
                ServiceConfig globalConfig = scm.getGlobalConfig(configName);
                if (globalConfig != null) {
                    Map mergedAttributes = globalConfig.getAttributes();
                    mergedAttributes.putAll(organizationAttributes);
                    return mergedAttributes;
                }
                return organizationAttributes;
            } else {
                if (subConfigId == null) {
                    if (debug.messageEnabled()) {
                        debug.message("ConfigurationInstanceImpl." + "getConfiguration: sub configuraton not " + "supported.");
                    }
                    String[] data = { componentName };
                    throw new ConfigurationException(RESOURCE_BUNDLE, "noSubConfig", data);
                }
                organizationConfig = organizationConfig.getSubConfig(configName);
                if (organizationConfig == null) {
                    return null;
                }
                return organizationConfig.getAttributes();
            }
        } else {
            if ((realm != null) && (!realm.equals("/"))) {
                if (debug.messageEnabled()) {
                    debug.message("ConfigurationInstanceImpl." + "getConfiguration: organization configuraton not " + "supported.");
                }
                String[] data = { componentName };
                throw new ConfigurationException(RESOURCE_BUNDLE, "noOrgConfig", data);
            }
            ServiceSchema ss = ssm.getGlobalSchema();
            if (ss == null) {
                if (debug.messageEnabled()) {
                    debug.message("ConfigurationInstanceImpl." + "getConfiguration: configuraton not " + "supported.");
                }
                String[] data = { componentName };
                throw new ConfigurationException(RESOURCE_BUNDLE, "noConfig", data);
            }
            Map retMap = ss.getAttributeDefaults();
            if (componentName.equals("PLATFORM")) {
                SSOToken token = getSSOToken();
                retMap.put(Constants.PLATFORM_LIST, ServerConfiguration.getServerInfo(token));
                retMap.put(Constants.SITE_LIST, SiteConfiguration.getSiteInfo(token));
            }
            return retMap;
        }
    } catch (SMSException smsex) {
        debug.error("ConfigurationInstanceImpl.getConfiguration:", smsex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedGetConfig", data);
    } catch (SSOException ssoex) {
        debug.error("ConfigurationInstanceImpl.getConfiguration:", ssoex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedGetConfig", data);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) SSOToken(com.iplanet.sso.SSOToken) ServiceConfig(com.sun.identity.sm.ServiceConfig) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with ConfigurationException

use of com.sun.identity.plugin.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ConfigurationInstanceImpl method createConfiguration.

/**
     * Creates Configurations.
     * @param realm the name of organization at which the configuration resides.
     * @param configName service configuration name. e.g. "/sp"
     *     The configName could be null or empty string, which means the
     *     default configuration for this components.
     * @param avPairs Map of key/value pairs to be set in the service
     *     configuration, key is the attribute name, value is
     *     a Set of attribute values. 
     * @exception ConfigurationException if could not create service 
     *     configuration.
     */
public void createConfiguration(String realm, String configName, Map avPairs) throws ConfigurationException {
    if (debug.messageEnabled()) {
        debug.message("ConfigurationInstanceImpl.createConfiguration: " + "componentName = " + componentName + ", realm = " + realm + ", configName = " + configName + ", avPairs = " + avPairs);
    }
    try {
        if (hasOrgSchema) {
            ServiceConfig sc = null;
            sc = scm.getOrganizationConfig(realm, null);
            if ((configName == null) || (configName.length() == 0)) {
                scm.createOrganizationConfig(realm, avPairs);
            } else {
                if (subConfigId == null) {
                    if (debug.messageEnabled()) {
                        debug.message("ConfigurationInstanceImpl." + "createConfiguration: sub configuraton not " + "supported.");
                    }
                    String[] data = { componentName };
                    throw new ConfigurationException(RESOURCE_BUNDLE, "noSubConfig", data);
                }
                if (sc == null) {
                    sc = scm.createOrganizationConfig(realm, null);
                } else if (sc.getSubConfigNames().contains(configName)) {
                    String[] data = { componentName, realm, configName };
                    throw new ConfigurationException(RESOURCE_BUNDLE, "configExist", data);
                }
                sc.addSubConfig(configName, subConfigId, SUBCONFIG_PRIORITY, avPairs);
            }
        } else {
            if (debug.messageEnabled()) {
                debug.message("ConfigurationInstanceImpl." + "createConfiguration: configuraton creation not " + "supported.");
            }
            String[] data = { componentName };
            throw new ConfigurationException(RESOURCE_BUNDLE, "noConfigCreation", data);
        }
    } catch (SMSException smsex) {
        debug.error("ConfigurationInstanceImpl.createConfiguration:", smsex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedCreateConfig", data);
    } catch (SSOException ssoex) {
        debug.error("ConfigurationInstanceImpl.createConfiguration:", ssoex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedCreateConfig", data);
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 30 with ConfigurationException

use of com.sun.identity.plugin.configuration.ConfigurationException in project OpenAM by OpenRock.

the class ConfigurationInstanceImpl method setConfiguration.

/**
     * Sets Configurations.
     * @param realm the name of organization at which the configuration resides.
     * @param configName configuration instance name. e.g. "/sp"
     *     The configName could be null or empty string, which means the default
     *     configuration for this components.
     * @param avPairs Map of key/value pairs to be set in the service
     *     configuration, key is the attribute name, value is
     *     a Set of attribute values. 
     * @exception ConfigurationException if could not set service configuration
     *     or service configuration doesn't exist.
     */
public void setConfiguration(String realm, String configName, Map avPairs) throws ConfigurationException {
    if (debug.messageEnabled()) {
        debug.message("ConfigurationInstanceImpl.setConfiguration: " + "componentName = " + componentName + ", realm = " + realm + ", configName = " + configName + ", avPairs = " + avPairs);
    }
    try {
        if (hasOrgSchema) {
            ServiceConfig sc = null;
            sc = scm.getOrganizationConfig(realm, null);
            if (sc == null) {
                String[] data = { componentName, realm };
                throw new ConfigurationException(RESOURCE_BUNDLE, "configNotExist", data);
            }
            if ((configName == null) || (configName.length() == 0)) {
                sc.setAttributes(avPairs);
            } else {
                if (subConfigId == null) {
                    if (debug.messageEnabled()) {
                        debug.message("ConfigurationInstanceImpl." + "setConfiguration: sub configuraton not " + "supported.");
                    }
                    String[] data = { componentName };
                    throw new ConfigurationException(RESOURCE_BUNDLE, "noSubConfig", data);
                }
                sc = sc.getSubConfig(configName);
                if (sc == null) {
                    String[] data = { componentName, realm };
                    throw new ConfigurationException(RESOURCE_BUNDLE, "configNotExist", data);
                }
                sc.setAttributes(avPairs);
            }
        } else {
            if ((realm != null) && (!realm.equals("/"))) {
                if (debug.messageEnabled()) {
                    debug.message("ConfigurationInstanceImpl." + "setConfiguration: organization configuraton not " + "supported.");
                }
                String[] data = { componentName };
                throw new ConfigurationException(RESOURCE_BUNDLE, "noOrgConfig", data);
            }
            ServiceSchema ss = ssm.getGlobalSchema();
            if (ss == null) {
                if (debug.messageEnabled()) {
                    debug.message("ConfigurationInstanceImpl." + "setConfiguration: configuraton not " + "supported.");
                }
                String[] data = { componentName };
                throw new ConfigurationException(RESOURCE_BUNDLE, "noConfig", data);
            }
            ss.setAttributeDefaults(avPairs);
        }
    } catch (SMSException smsex) {
        debug.error("ConfigurationInstanceImpl.setConfiguration:", smsex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedSetConfig", data);
    } catch (SSOException ssoex) {
        debug.error("ConfigurationInstanceImpl.setConfiguration:", ssoex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedSetConfig", data);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) ServiceConfig(com.sun.identity.sm.ServiceConfig) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Aggregations

ConfigurationException (com.sun.identity.plugin.configuration.ConfigurationException)59 Set (java.util.Set)38 Map (java.util.Map)35 HashSet (java.util.HashSet)31 JAXBException (javax.xml.bind.JAXBException)19 Iterator (java.util.Iterator)18 HashMap (java.util.HashMap)14 ArrayList (java.util.ArrayList)13 List (java.util.List)9 EntityConfigElement (com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)6 SSOException (com.iplanet.sso.SSOException)5 SMSException (com.sun.identity.sm.SMSException)5 FederationConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)5 ServiceConfig (com.sun.identity.sm.ServiceConfig)4 ServiceSchema (com.sun.identity.sm.ServiceSchema)4 EntityConfigElement (com.sun.identity.federation.jaxb.entityconfig.EntityConfigElement)3 IDPSSOConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.IDPSSOConfigElement)3 SPSSOConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.SPSSOConfigElement)3 StringTokenizer (java.util.StringTokenizer)3 SSOToken (com.iplanet.sso.SSOToken)2