Search in sources :

Example 1 with FederationConfigElement

use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.

the class CreateWSFedMetaDataTemplate method createExtendedMetaTemplate.

public static String createExtendedMetaTemplate(String entityId, Map mapParams) throws JAXBException {
    JAXBContext jc = WSFederationMetaUtils.getMetaJAXBContext();
    com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory objFactory = new com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory();
    FederationConfigElement fedConfig = objFactory.createFederationConfigElement();
    fedConfig.setFederationID(entityId);
    fedConfig.setHosted(true);
    String idpAlias = (String) mapParams.get(MetaTemplateParameters.P_IDP);
    if (idpAlias != null) {
        buildWSFedIDPConfigTemplate(objFactory, fedConfig, mapParams);
    }
    String spAlias = (String) mapParams.get(MetaTemplateParameters.P_SP);
    if (spAlias != null) {
        buildWSFedSPConfigTemplate(objFactory, fedConfig, mapParams);
    }
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    StringWriter pw = new StringWriter();
    m.marshal(fedConfig, pw);
    return pw.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) StringWriter(java.io.StringWriter) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)

Example 2 with FederationConfigElement

use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.

the class WSFederationMetaSecurityUtils method updateProviderKeyInfo.

/**
     * Updates signing or encryption key info for SP or IDP.
     * This will update both signing/encryption alias on extended metadata and
     * certificates in standard metadata.
     * @param realm Realm the entity resides.
     * @param entityID ID of the entity to be updated.
     * @param certAlias Alias of the certificate to be set to the entity. If
     *        null, will remove existing key information from the SP or IDP.
     * @param isIDP true if this is for IDP signing/encryption alias, false
     *        if this is for SP signing/encryption alias
     * @throws WSFederationMetaException if failed to update the certificate 
     *        alias for the entity.
     */
public static void updateProviderKeyInfo(String realm, String entityID, String certAlias, boolean isIDP) throws WSFederationMetaException {
    WSFederationMetaManager metaManager = new WSFederationMetaManager();
    FederationConfigElement config = metaManager.getEntityConfig(realm, entityID);
    if (!config.isHosted()) {
        String[] args = { entityID, realm };
        throw new WSFederationMetaException("entityNotHosted", args);
    }
    FederationElement desp = metaManager.getEntityDescriptor(realm, entityID);
    if (isIDP) {
        IDPSSOConfigElement idpConfig = metaManager.getIDPSSOConfig(realm, entityID);
        if ((idpConfig == null) || (desp == null)) {
            String[] args = { entityID, realm };
            throw new WSFederationMetaException("entityNotIDP", args);
        }
        // update standard metadata
        if ((certAlias == null) || (certAlias.length() == 0)) {
            // remove key info
            removeKeyDescriptor(desp);
            setExtendedAttributeValue(idpConfig, SAML2Constants.SIGNING_CERT_ALIAS, null);
        } else {
            TokenSigningKeyInfoElement kde = getKeyDescriptor(certAlias);
            updateKeyDescriptor(desp, kde);
            // update extended metadata
            Set value = new HashSet();
            value.add(certAlias);
            setExtendedAttributeValue(idpConfig, SAML2Constants.SIGNING_CERT_ALIAS, value);
        }
    } else {
        SPSSOConfigElement spConfig = metaManager.getSPSSOConfig(realm, entityID);
        if ((spConfig == null) || (desp == null)) {
            String[] args = { entityID, realm };
            throw new WSFederationMetaException("entityNotSP", args);
        }
        // update standard metadata
        if ((certAlias == null) || (certAlias.length() == 0)) {
            // remove key info
            removeKeyDescriptor(desp);
            setExtendedAttributeValue(spConfig, SAML2Constants.SIGNING_CERT_ALIAS, null);
        } else {
            TokenSigningKeyInfoElement kde = getKeyDescriptor(certAlias);
            updateKeyDescriptor(desp, kde);
            // update extended metadata
            Set value = new HashSet();
            value.add(certAlias);
            setExtendedAttributeValue(spConfig, SAML2Constants.SIGNING_CERT_ALIAS, value);
        }
    }
    metaManager.setFederation(realm, desp);
    metaManager.setEntityConfig(realm, config);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TokenSigningKeyInfoElement(com.sun.identity.wsfederation.jaxb.wsfederation.TokenSigningKeyInfoElement) SPSSOConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.SPSSOConfigElement) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) IDPSSOConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.IDPSSOConfigElement) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) HashSet(java.util.HashSet)

Example 3 with FederationConfigElement

use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.

the class WSFederationMetaManager 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 WSFederationMetaException if unable to retrieve the entity ids.
     */
public String getEntityByMetaAlias(String metaAlias) throws WSFederationMetaException {
    String realm = WSFederationMetaUtils.getRealmByMetaAlias(metaAlias);
    try {
        Set entityIds = configInst.getAllConfigurationNames(realm);
        if (entityIds == null || entityIds.isEmpty()) {
            return null;
        }
        for (Iterator iter = entityIds.iterator(); iter.hasNext(); ) {
            String federationId = (String) iter.next();
            FederationConfigElement config = getEntityConfig(realm, federationId);
            if (config == null) {
                continue;
            }
            List list = config.getIDPSSOConfigOrSPSSOConfig();
            for (Iterator iter2 = list.iterator(); iter2.hasNext(); ) {
                BaseConfigType bConfig = (BaseConfigType) iter2.next();
                String cMetaAlias = bConfig.getMetaAlias();
                if (cMetaAlias != null && cMetaAlias.equals(metaAlias)) {
                    return federationId;
                }
            }
        }
    } catch (ConfigurationException e) {
        debug.error("WSFederationMetaManager.getEntityByMetaAlias:", e);
        throw new WSFederationMetaException(e);
    }
    return null;
}
Also used : BaseConfigType(com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType) HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) Iterator(java.util.Iterator) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with FederationConfigElement

use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.

the class WSFederationMetaCache method getEntityConfig.

/**
     * Returns extended entity configuration under the realm from cache.
     * @param realm The realm under which the entity resides.
     * @param entityId ID of the entity to be retrieved.
     * @return <code>FederationConfigElement</code> object for the entity or 
     * null if not found.
     */
static FederationConfigElement getEntityConfig(String realm, String entityId) {
    String cacheKey = buildCacheKey(realm, entityId);
    FederationConfigElement config = (FederationConfigElement) configCache.get(cacheKey);
    if (debug.messageEnabled()) {
        debug.message("SAML2MetaCache.getEntityConfig: cacheKey = " + cacheKey + ", found = " + (config != null));
    }
    return config;
}
Also used : FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)

Example 5 with FederationConfigElement

use of com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement in project OpenAM by OpenRock.

the class WSFederationMetaManager method getEntityConfig.

/**
     * Returns extended entity configuration under the realm.
     * 
     * @param realm The realm under which the entity resides.
     * @param federationId ID of the entity to be retrieved.
     * @return <code>FederationConfigElement</code> object for the entity or 
     * null if not found.
     * @throws WSFederationMetaException if unable to retrieve the entity
     *                            configuration.
     */
public FederationConfigElement getEntityConfig(String realm, String federationId) throws WSFederationMetaException {
    if (federationId == null) {
        return null;
    }
    if (realm == null) {
        realm = "/";
    }
    String[] objs = { federationId, realm };
    FederationConfigElement config = null;
    if (callerSession == null) {
        config = WSFederationMetaCache.getEntityConfig(realm, federationId);
        if (config != null) {
            LogUtil.access(Level.FINE, LogUtil.GOT_ENTITY_CONFIG, objs, null);
            return config;
        }
    }
    try {
        Map attrs = configInst.getConfiguration(realm, federationId);
        if (attrs == null) {
            return null;
        }
        Set values = (Set) attrs.get(ATTR_ENTITY_CONFIG);
        if (values == null || values.isEmpty()) {
            return null;
        }
        String value = (String) values.iterator().next();
        Object obj = WSFederationMetaUtils.convertStringToJAXB(value);
        if (obj instanceof FederationConfigElement) {
            config = (FederationConfigElement) obj;
            WSFederationMetaCache.putEntityConfig(realm, federationId, config);
            LogUtil.access(Level.FINE, LogUtil.GOT_ENTITY_CONFIG, objs, null);
            return config;
        }
        debug.error("WSFederationMetaManager.getEntityConfig: " + "invalid config");
        LogUtil.error(Level.INFO, LogUtil.GOT_INVALID_ENTITY_CONFIG, objs, null);
        throw new WSFederationMetaException("invalid_config", objs);
    } catch (ConfigurationException e) {
        debug.error("WSFederationMetaManager.getEntityConfig:", e);
        String[] data = { e.getMessage(), federationId, realm };
        LogUtil.error(Level.INFO, LogUtil.CONFIG_ERROR_GET_ENTITY_CONFIG, data, null);
        throw new WSFederationMetaException(e);
    } catch (JAXBException jaxbe) {
        debug.error("WSFederationMetaManager.getEntityConfig:", jaxbe);
        LogUtil.error(Level.INFO, LogUtil.GOT_INVALID_ENTITY_CONFIG, objs, null);
        throw new WSFederationMetaException("invalid_config", objs);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ConfigurationException(com.sun.identity.plugin.configuration.ConfigurationException) JAXBException(javax.xml.bind.JAXBException) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) Map(java.util.Map)

Aggregations

FederationConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)16 BaseConfigType (com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 List (java.util.List)6 ConfigurationException (com.sun.identity.plugin.configuration.ConfigurationException)5 FederationElement (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)5 Set (java.util.Set)5 JAXBException (javax.xml.bind.JAXBException)5 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)4 WSFederationMetaException (com.sun.identity.wsfederation.meta.WSFederationMetaException)4 WSFederationMetaManager (com.sun.identity.wsfederation.meta.WSFederationMetaManager)4 IDPSSOConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.IDPSSOConfigElement)3 SPSSOConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.SPSSOConfigElement)3 AttributeType (com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType)2 ObjectFactory (com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory)2 TokenSigningKeyInfoElement (com.sun.identity.wsfederation.jaxb.wsfederation.TokenSigningKeyInfoElement)1 StringWriter (java.io.StringWriter)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1