Search in sources :

Example 21 with ConfigurationException

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

the class SAML2MetaManager method getAllHostedMetaAliasesByRealm.

/**
     * Returns all the hosted entity metaAliases for a realm.
     *
     * @param realm The given realm.
     * @return all the hosted entity metaAliases for a realm or an empty arrayList if not found.
     * @throws SAML2MetaException  if unable to retrieve the entity ids.
     */
public List<String> getAllHostedMetaAliasesByRealm(String realm) throws SAML2MetaException {
    List<String> metaAliases = new ArrayList<String>();
    try {
        Set<String> entityIds = configInst.getAllConfigurationNames(realm);
        if (entityIds == null || entityIds.isEmpty()) {
            return metaAliases;
        }
        for (String entityId : entityIds) {
            EntityConfigElement config = getEntityConfig(realm, entityId);
            if (config == null || !config.isHosted()) {
                continue;
            }
            List<BaseConfigType> configList = config.getIDPSSOConfigOrSPSSOConfigOrAuthnAuthorityConfig();
            for (BaseConfigType bConfigType : configList) {
                String curMetaAlias = bConfigType.getMetaAlias();
                if (curMetaAlias != null && !curMetaAlias.isEmpty()) {
                    metaAliases.add(curMetaAlias);
                }
            }
        }
    } catch (ConfigurationException e) {
        debug.error("SAML2MetaManager.getAllHostedMetaAliasesByRealm:", e);
        throw new SAML2MetaException(e);
    }
    return metaAliases;
}
Also used : BaseConfigType(com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) ArrayList(java.util.ArrayList) EntityConfigElement(com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)

Example 22 with ConfigurationException

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

the class SAML2MetaManager method getEntityDescriptor.

/**
     * Returns the standard metadata entity descriptor under the realm.
     * @param realm The realm under which the entity resides.
     * @param entityId ID of the entity to be retrieved. 
     * @return <code>EntityDescriptorElement</code> for the entity or null if
     *         not found. 
     * @throws SAML2MetaException if unable to retrieve the entity descriptor. 
     */
public EntityDescriptorElement getEntityDescriptor(String realm, String entityId) throws SAML2MetaException {
    if (entityId == null) {
        return null;
    }
    if (realm == null) {
        realm = "/";
    }
    String[] objs = { entityId, realm };
    EntityDescriptorElement descriptor = null;
    if (callerSession == null) {
        descriptor = SAML2MetaCache.getEntityDescriptor(realm, entityId);
        if (descriptor != null) {
            if (debug.messageEnabled()) {
                debug.message("SAML2MetaManager.getEntityDescriptor: got " + "descriptor from SAML2MetaCache " + entityId);
            }
            LogUtil.access(Level.FINE, LogUtil.GOT_ENTITY_DESCRIPTOR, objs, null);
            return descriptor;
        }
    }
    try {
        Map attrs = configInst.getConfiguration(realm, entityId);
        if (attrs == null) {
            return null;
        }
        Set values = (Set) attrs.get(ATTR_METADATA);
        if ((values == null) || values.isEmpty()) {
            return null;
        }
        String value = (String) values.iterator().next();
        Object obj = SAML2MetaUtils.convertStringToJAXB(value);
        if (obj instanceof EntityDescriptorElement) {
            descriptor = (EntityDescriptorElement) obj;
            SAML2MetaCache.putEntityDescriptor(realm, entityId, descriptor);
            if (debug.messageEnabled()) {
                debug.message("SAML2MetaManager.getEntityDescriptor: got " + "descriptor from SMS " + entityId);
            }
            LogUtil.access(Level.FINE, LogUtil.GOT_ENTITY_DESCRIPTOR, objs, null);
            return descriptor;
        }
        debug.error("SAML2MetaManager.getEntityDescriptor: invalid descriptor");
        LogUtil.error(Level.INFO, LogUtil.GOT_INVALID_ENTITY_DESCRIPTOR, objs, null);
        throw new SAML2MetaException("invalid_descriptor", objs);
    } catch (ConfigurationException e) {
        debug.error("SAML2MetaManager.getEntityDescriptor", e);
        String[] data = { e.getMessage(), entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_GET_ENTITY_DESCRIPTOR, data, null);
        throw new SAML2MetaException(e);
    } catch (JAXBException jaxbe) {
        debug.error("SAML2MetaManager.getEntityDescriptor", jaxbe);
        LogUtil.error(Level.INFO, LogUtil.GOT_INVALID_ENTITY_DESCRIPTOR, objs, null);
        throw new SAML2MetaException("invalid_descriptor", objs);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) JAXBException(javax.xml.bind.JAXBException) EntityDescriptorElement(com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement) Map(java.util.Map)

Example 23 with ConfigurationException

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

the class SAML2MetaManager method getAllEntities.

/**
     * Returns all entities under the realm.
     * @param realm The realm under which the entities reside.
     * @return a <code>Set</code> of entity ID <code>String</code>.
     * @throws SAML2MetaException if unable to retrieve the entity ids.
     */
public Set getAllEntities(String realm) throws SAML2MetaException {
    Set ret = new HashSet();
    String[] objs = { realm };
    try {
        Set entityIds = configInst.getAllConfigurationNames(realm);
        if (entityIds != null && !entityIds.isEmpty()) {
            ret.addAll(entityIds);
        }
    } catch (ConfigurationException e) {
        debug.error("SAML2MetaManager.getAllEntities:", e);
        String[] data = { e.getMessage(), realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_GET_ALL_ENTITIES, data, null);
        throw new SAML2MetaException(e);
    }
    LogUtil.access(Level.FINE, LogUtil.GOT_ALL_ENTITIES, objs, null);
    return ret;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) HashSet(java.util.HashSet)

Example 24 with ConfigurationException

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

the class SAML2MetaManager method deleteEntityConfig.

/**
     * Deletes the extended entity configuration under the realm.
     * @param realm The realm under which the entity resides.
     * @param entityId The ID of the entity for whom the extended entity
     *                 configuration will be deleted.
     * @throws SAML2MetaException if unable to delete the entity descriptor.
     */
public void deleteEntityConfig(String realm, String entityId) throws SAML2MetaException {
    if (entityId == null) {
        return;
    }
    if (realm == null) {
        realm = "/";
    }
    String[] objs = { entityId, realm };
    try {
        Map oldAttrs = configInst.getConfiguration(realm, entityId);
        Set oldValues = (Set) oldAttrs.get(ATTR_ENTITY_CONFIG);
        if (oldValues == null || oldValues.isEmpty()) {
            LogUtil.error(Level.INFO, LogUtil.NO_ENTITY_DESCRIPTOR_DELETE_ENTITY_CONFIG, objs, null);
            throw new SAML2MetaException("entity_config_not_exist", objs);
        }
        // Remove the entity from cot              
        removeFromCircleOfTrust(realm, entityId);
        Set attr = new HashSet();
        attr.add(ATTR_ENTITY_CONFIG);
        configInst.deleteConfiguration(realm, entityId, attr);
        LogUtil.access(Level.INFO, LogUtil.ENTITY_CONFIG_DELETED, objs, null);
        SAML2MetaCache.putEntityConfig(realm, entityId, null);
    } catch (ConfigurationException e) {
        debug.error("SAML2MetaManager.deleteEntityConfig:", e);
        String[] data = { e.getMessage(), entityId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_DELETE_ENTITY_CONFIG, data, null);
        throw new SAML2MetaException(e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) Map(java.util.Map) HashSet(java.util.HashSet)

Example 25 with ConfigurationException

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

the class SAML2MetaManager method getEntityByMetaAlias.

/**
     * Returns entity ID associated with the metaAlias.
     * @param metaAlias The metaAlias.
     * @return entity ID associated with the metaAlias or null if not found.
     * @throws SAML2MetaException if unable to retrieve the entity ids.
     */
public String getEntityByMetaAlias(String metaAlias) throws SAML2MetaException {
    String realm = SAML2MetaUtils.getRealmByMetaAlias(metaAlias);
    try {
        Set entityIds = configInst.getAllConfigurationNames(realm);
        if (entityIds == null || entityIds.isEmpty()) {
            return null;
        }
        for (Iterator iter = entityIds.iterator(); iter.hasNext(); ) {
            String entityId = (String) iter.next();
            EntityConfigElement config = getEntityConfig(realm, entityId);
            if ((config == null) || !config.isHosted()) {
                continue;
            }
            List list = config.getIDPSSOConfigOrSPSSOConfigOrAuthnAuthorityConfig();
            for (Iterator iter2 = list.iterator(); iter2.hasNext(); ) {
                BaseConfigType bConfig = (BaseConfigType) iter2.next();
                String cMetaAlias = bConfig.getMetaAlias();
                if (cMetaAlias != null && cMetaAlias.equals(metaAlias)) {
                    return entityId;
                }
            }
        }
    } catch (ConfigurationException e) {
        debug.error("SAML2MetaManager.getEntityByMetaAlias:", e);
        throw new SAML2MetaException(e);
    }
    return null;
}
Also used : BaseConfigType(com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType) HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EntityConfigElement(com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)

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