Search in sources :

Example 1 with AttributeType

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

the class WSFederationMetaSecurityUtils method setExtendedAttributeValue.

private static void setExtendedAttributeValue(BaseConfigType config, String attrName, Set attrVal) throws WSFederationMetaException {
    try {
        List attributes = config.getAttribute();
        for (Iterator iter = attributes.iterator(); iter.hasNext(); ) {
            AttributeType avp = (AttributeType) iter.next();
            if (avp.getName().trim().equalsIgnoreCase(attrName)) {
                iter.remove();
            }
        }
        if (attrVal != null) {
            ObjectFactory factory = new ObjectFactory();
            AttributeType atype = factory.createAttributeType();
            atype.setName(attrName);
            atype.getValue().addAll(attrVal);
            config.getAttribute().add(atype);
        }
    } catch (JAXBException e) {
        throw new WSFederationMetaException(e);
    }
}
Also used : ObjectFactory(com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory) AttributeType(com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType) JAXBException(javax.xml.bind.JAXBException) Iterator(java.util.Iterator) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 2 with AttributeType

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

the class WSFederationMetaUtils method getAttributes.

/**
     * Gets attribute value pairs from <code>BaseConfigType</code> and
     * put in a <code>Map</code>. The key is attribute name and the value is
     * a <code>List</code> of attribute values;
     * @param config the <code>BaseConfigType</code> object
     * @return a attrbute value <code>Map</code>
     */
public static Map<String, List<String>> getAttributes(BaseConfigType config) {
    Map<String, List<String>> attrMap = new HashMap<String, List<String>>();
    List list = config.getAttribute();
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        AttributeType avp = (AttributeType) iter.next();
        attrMap.put(avp.getName(), avp.getValue());
    }
    return attrMap;
}
Also used : HashMap(java.util.HashMap) AttributeType(com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType) Iterator(java.util.Iterator) List(java.util.List)

Example 3 with AttributeType

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

the class WSFederationCOTUtils method updateEntityConfig.

/**
     * Updates the entity config to add the circle of trust name to the
     * <code>cotlist</code> attribute. The Service Provider and Identity
     * Provider Configuration are updated.
     *
     * @param realm the realm name where the entity configuration is.
     * @param name the circle of trust name.
     * @param entityId the name of the Entity identifier.
     * @throws WSFederationMetaException if there is a configuration error when
     *         updating the configuration.
     * @throws JAXBException is there is an error updating the entity
     *          configuration.
     */
public void updateEntityConfig(String realm, String name, String entityId) throws WSFederationMetaException, JAXBException {
    String classMethod = "WSFederationCOTUtils.updateEntityConfig: ";
    WSFederationMetaManager metaManager = null;
    if (callerSession != null) {
        metaManager = new WSFederationMetaManager(callerSession);
    } else {
        metaManager = new WSFederationMetaManager();
    }
    ObjectFactory objFactory = new ObjectFactory();
    // Check whether the entity id existed in the DS
    FederationElement edes = metaManager.getEntityDescriptor(realm, entityId);
    if (edes == null) {
        debug.error(classMethod + "No such entity: " + entityId);
        String[] data = { realm, entityId };
        throw new WSFederationMetaException("entityid_invalid", data);
    }
    FederationConfigElement eConfig = metaManager.getEntityConfig(realm, entityId);
    if (eConfig == null) {
        BaseConfigType bctype = null;
        AttributeType atype = objFactory.createAttributeType();
        atype.setName(SAML2Constants.COT_LIST);
        atype.getValue().add(name);
        // add to eConfig
        FederationConfigElement ele = objFactory.createFederationConfigElement();
        ele.setFederationID(entityId);
        ele.setHosted(false);
        List ll = ele.getIDPSSOConfigOrSPSSOConfig();
        // IdP will have UriNamedClaimTypesOffered
        if (metaManager.getUriNamedClaimTypesOffered(edes) != null) {
            bctype = objFactory.createIDPSSOConfigElement();
            bctype.getAttribute().add(atype);
            ll.add(bctype);
        } else {
            bctype = objFactory.createSPSSOConfigElement();
            bctype.getAttribute().add(atype);
            ll.add(bctype);
        }
        metaManager.setEntityConfig(realm, ele);
    } else {
        List elist = eConfig.getIDPSSOConfigOrSPSSOConfig();
        for (Iterator iter = elist.iterator(); iter.hasNext(); ) {
            BaseConfigType bConfig = (BaseConfigType) iter.next();
            List list = bConfig.getAttribute();
            boolean foundCOT = false;
            for (Iterator iter2 = list.iterator(); iter2.hasNext(); ) {
                AttributeType avp = (AttributeType) iter2.next();
                if (avp.getName().trim().equalsIgnoreCase(SAML2Constants.COT_LIST)) {
                    foundCOT = true;
                    List avpl = avp.getValue();
                    if (avpl.isEmpty() || !containsValue(avpl, name)) {
                        avpl.add(name);
                        metaManager.setEntityConfig(realm, eConfig);
                        break;
                    }
                }
            }
            // no cot_list in the original entity config
            if (!foundCOT) {
                AttributeType atype = objFactory.createAttributeType();
                atype.setName(SAML2Constants.COT_LIST);
                atype.getValue().add(name);
                list.add(atype);
                metaManager.setEntityConfig(realm, eConfig);
            }
        }
    }
}
Also used : BaseConfigType(com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType) ObjectFactory(com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory) AttributeType(com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType) Iterator(java.util.Iterator) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) List(java.util.List) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)

Example 4 with AttributeType

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

the class WSFederationCOTUtils method removeFromEntityConfig.

/**
     * Removes the circle of trust name passed from the <code>cotlist</code>
     * attribute in the Entity Config. The Service Provider and Identity
     * Provider Entity Configuration are updated.
     *
     * @param realm the realm of the provider
     * @param name the circle of trust name to be removed.
     * @param entityId the entity identifier of the provider.
     * @throws WSFederationMetaException if there is an error updating the 
     * entity config.
     * @throws JAXBException if there is an error updating the entity config.
     */
public void removeFromEntityConfig(String realm, String name, String entityId) throws WSFederationMetaException, JAXBException {
    String classMethod = "WSFederationCOTUtils.removeFromEntityConfig: ";
    WSFederationMetaManager metaManager = null;
    if (callerSession != null) {
        metaManager = new WSFederationMetaManager(callerSession);
    } else {
        metaManager = new WSFederationMetaManager();
    }
    // Check whether the entity id existed in the DS
    FederationElement edes = metaManager.getEntityDescriptor(realm, entityId);
    if (edes == null) {
        debug.error(classMethod + "No such entity: " + entityId);
        String[] data = { realm, entityId };
        throw new WSFederationMetaException("entityid_invalid", data);
    }
    FederationConfigElement eConfig = metaManager.getEntityConfig(realm, entityId);
    if (eConfig != null) {
        List elist = eConfig.getIDPSSOConfigOrSPSSOConfig();
        for (Iterator iter = elist.iterator(); iter.hasNext(); ) {
            BaseConfigType bConfig = (BaseConfigType) iter.next();
            List list = bConfig.getAttribute();
            for (Iterator iter2 = list.iterator(); iter2.hasNext(); ) {
                AttributeType avp = (AttributeType) iter2.next();
                if (avp.getName().trim().equalsIgnoreCase(SAML2Constants.COT_LIST)) {
                    List avpl = avp.getValue();
                    if (avpl != null && !avpl.isEmpty() && containsValue(avpl, name)) {
                        avpl.remove(name);
                        metaManager.setEntityConfig(realm, eConfig);
                        break;
                    }
                }
            }
        }
    }
}
Also used : BaseConfigType(com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType) AttributeType(com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType) Iterator(java.util.Iterator) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) List(java.util.List) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)

Aggregations

AttributeType (com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType)4 Iterator (java.util.Iterator)4 List (java.util.List)4 BaseConfigType (com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType)2 FederationConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)2 ObjectFactory (com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory)2 FederationElement (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)2 HashMap (java.util.HashMap)1 JAXBException (javax.xml.bind.JAXBException)1 NodeList (org.w3c.dom.NodeList)1