Search in sources :

Example 41 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)

Example 42 with ConfigurationException

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

the class ConfigurationInstanceImpl method getAllConfigurationNames.

/**
     * Returns all service config name for this components.
     * @param realm the name of organization at which the configuration resides.
     * @return Set of service configuration names. Return null if there 
     *     is no service configuration for this component, return empty set
     *     if there is only default configuration instance.
     * @exception ConfigurationException if could not get all service 
     *     configuration names.
     */
public Set getAllConfigurationNames(String realm) throws ConfigurationException {
    if (debug.messageEnabled()) {
        debug.message("ConfigurationInstanceImpl.getAllConfigurationNames" + ": realm = " + realm + ", componentName = " + componentName);
    }
    try {
        if (hasOrgSchema) {
            ServiceConfig sc = scm.getOrganizationConfig(realm, null);
            if (sc == null) {
                return null;
            }
            Set subConfigNames = sc.getSubConfigNames();
            if ((subConfigNames != null) && (subConfigNames.size() > 0)) {
                return subConfigNames;
            } else {
                return Collections.EMPTY_SET;
            }
        } else {
            if ((realm != null) && (!realm.equals("/"))) {
                return null;
            }
            ServiceSchema ss = ssm.getGlobalSchema();
            if (ss == null) {
                return null;
            } else {
                return Collections.EMPTY_SET;
            }
        }
    } catch (SMSException smsex) {
        debug.error("ConfigurationInstanceImpl.getAllConfigurationNames:", smsex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedGetConfigNames", data);
    } catch (SSOException ssoex) {
        debug.error("ConfigurationInstanceImpl.getAllConfigurationNames:", ssoex);
        String[] data = { componentName, realm };
        throw new ConfigurationException(RESOURCE_BUNDLE, "failedGetConfigNames", data);
    }
}
Also used : ServiceSchema(com.sun.identity.sm.ServiceSchema) Set(java.util.Set) ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) SSOException(com.iplanet.sso.SSOException)

Example 43 with ConfigurationException

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

the class CircleOfTrustManager method getAllActiveCirclesOfTrust.

/**
     * Returns a set of names of all active circle of trusts.
     *
     * @param realm The realm under which the circle of trust resides.
     * @return Set of names of all active circle of trusts.
     * @throws COTException if the names of
     *         circle of trusts cannot be read.
     */
public Set getAllActiveCirclesOfTrust(String realm) throws COTException {
    String classMethod = "COTManager.getAllActiveCirclesOfTrust: ";
    Set activeAuthDomains = new HashSet();
    try {
        Set valueSet = configInst.getAllConfigurationNames(realm);
        if ((valueSet != null) && !valueSet.isEmpty()) {
            for (Iterator iter = valueSet.iterator(); iter.hasNext(); ) {
                String name = (String) iter.next();
                Map attrMap = configInst.getConfiguration(realm, name);
                if (COTUtils.getFirstEntry(attrMap, COTConstants.COT_STATUS).equalsIgnoreCase(COTConstants.ACTIVE)) {
                    activeAuthDomains.add(name);
                }
            }
        }
    } catch (ConfigurationException se) {
        debug.error(classMethod, se);
        String[] data = { se.getMessage(), realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_GET_ALL_ACTIVE_COT, data);
        throw new COTException(se);
    }
    return activeAuthDomains;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 44 with ConfigurationException

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

the class CircleOfTrustManager method addCircleOfTrustMember.

/**
     * Adds entity identifier to a circle of trust under the realm.
     *
     * @param realm The realm under which the circle of trust will be
     *              modified.
     * @param cotName the name of the circle of trust.
     * @param protocolType the federation protcol type the entity supports.
     * @param entityId the entity identifier.
     * @param addToEntityConfig if true, add the cotname to the entity config.
     * @throws COTException if unable to add member to the
     *         circle of trust.
     */
public void addCircleOfTrustMember(String realm, String cotName, String protocolType, String entityId, boolean addToEntityConfig) throws COTException {
    String classMethod = "COTManager.addCircleOfTrustMember: ";
    if (realm == null) {
        realm = "/";
    }
    if ((cotName == null) || (cotName.trim().length() == 0)) {
        String[] data = { realm };
        LogUtil.error(Level.INFO, LogUtil.NULL_COT_NAME_ADD_COT_DESCRIPTOR, data);
        throw new COTException("invalidCOTName", null);
    }
    if ((entityId == null) || (entityId.trim().length() == 0)) {
        String[] data = { realm };
        LogUtil.error(Level.INFO, LogUtil.NULL_ENTITYID_ADD_COT_DESCRIPTOR, data);
        throw new COTException("invalidEntityID", null);
    }
    try {
        Map attrs = configInst.getConfiguration(realm, cotName);
        //validate protocol type
        isValidProtocolType(protocolType);
        // add the cot to the entity config descriptor
        if (addToEntityConfig) {
            updateEntityConfig(realm, cotName, protocolType, entityId);
        }
        // add the entityid to the cot
        CircleOfTrustDescriptor cotDesc;
        if (attrs == null) {
            cotDesc = new CircleOfTrustDescriptor(cotName, realm, "active");
        } else {
            cotDesc = new CircleOfTrustDescriptor(cotName, realm, attrs);
        }
        if (!cotDesc.add(entityId, protocolType)) {
            debug.error(classMethod + "fail to add entityid to the circle of trust." + entityId + " in Realm " + realm);
            String[] args = { realm, entityId };
            throw new COTException("addCOTFailed", args);
        } else {
            modifyCircleOfTrust(realm, cotDesc);
        }
    } catch (ConfigurationException e) {
        debug.error(classMethod, e);
        String[] data = { e.getMessage(), cotName, entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_ADD_COT_MEMBER, data);
        throw new COTException(e);
    } catch (JAXBException jbe) {
        debug.error(classMethod, jbe);
        String[] data = { jbe.getMessage(), cotName, entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_CREATE_COT_DESCRIPTOR, data);
        throw new COTException(jbe);
    }
}
Also used : ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) JAXBException(javax.xml.bind.JAXBException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with ConfigurationException

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

the class CircleOfTrustManager method removeCircleOfTrustMember.

/**
     * Removes entity from circle of trust under the realm.
     *
     * @param realm the realm to which the circle of trust belongs.
     * @param cotName  the circle of trust name.
     * @param protocolType the federation protocol type.
     * @param entityId the entity identifier.
     * @param rmEntityConfig flag indicate needs to remove cot from 
     *         entity config or not.
     * @throws COTException if there is an error removing entity from the
     *         circle of trust.
     */
public void removeCircleOfTrustMember(String realm, String cotName, String protocolType, String entityId, boolean rmEntityConfig) throws COTException {
    String classMethod = "COTManager.removeCircleOfTrustMember: ";
    if ((cotName == null) || (cotName.trim().length() == 0)) {
        String[] data = { cotName, realm };
        LogUtil.error(Level.INFO, LogUtil.NULL_COT_NAME_REMOVE_COT_MEMBER, data);
        throw new COTException("invalidCOTName", null);
    }
    if ((entityId == null) || (entityId.trim().length() == 0)) {
        String[] data = { cotName, entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.NULL_ENTITYID_REMOVE_COT_MEMBER, data);
        throw new COTException("invalidEntityID", null);
    }
    if (realm == null) {
        realm = COTConstants.ROOT_REALM;
    }
    try {
        // the entity config.
        if (rmEntityConfig) {
            removeFromEntityConfig(realm, cotName, protocolType, entityId);
        }
        // Remove entity id from the cot
        CircleOfTrustDescriptor cotDesc;
        Map attrs = configInst.getConfiguration(realm, cotName);
        if (attrs == null) {
            cotDesc = new CircleOfTrustDescriptor(cotName, realm, COTConstants.ACTIVE);
        } else {
            cotDesc = new CircleOfTrustDescriptor(cotName, realm, attrs);
        }
        if (!cotDesc.remove(entityId, protocolType)) {
            debug.error(classMethod + "fail to remove entityid from the circle of trust." + realm);
            String[] data = { entityId, realm };
            throw new COTException("removeCOTFailed", data);
        } else {
            modifyCircleOfTrust(realm, cotDesc);
        }
    } catch (ConfigurationException e) {
        debug.error(classMethod, e);
        String[] data = { e.getMessage(), cotName, entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_REMOVE_COT_MEMBER, data);
        throw new COTException(e);
    } catch (JAXBException jaxbe) {
        debug.error(classMethod, jaxbe);
        String[] data = { jaxbe.getMessage(), cotName, entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_REMOVE_COT_MEMBER, data);
        throw new COTException(jaxbe);
    }
}
Also used : ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) JAXBException(javax.xml.bind.JAXBException) HashMap(java.util.HashMap) Map(java.util.Map)

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