Search in sources :

Example 1 with AttributeValueElement

use of com.sun.identity.saml2.jaxb.assertion.AttributeValueElement in project OpenAM by OpenRock.

the class AttributeQueryUtil method isValueValid.

private static boolean isValueValid(Attribute desiredAttr, AttributeElement supportedAttr) {
    List valuesD = desiredAttr.getAttributeValueString();
    if ((valuesD == null) || (valuesD.isEmpty())) {
        return true;
    }
    List attrValuesS = supportedAttr.getAttributeValue();
    if ((attrValuesS == null) || (attrValuesS.isEmpty())) {
        return true;
    }
    List valuesS = new ArrayList();
    for (Iterator iter = attrValuesS.iterator(); iter.hasNext(); ) {
        AttributeValueElement attrValueElem = (AttributeValueElement) iter.next();
        valuesS.addAll(attrValueElem.getContent());
    }
    try {
        return valuesS.containsAll(valuesD);
    } catch (Exception ex) {
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AttributeQueryUtil.isValueValid:", ex);
        }
        return false;
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) AttributeValueElement(com.sun.identity.saml2.jaxb.assertion.AttributeValueElement) SOAPException(javax.xml.soap.SOAPException) DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception)

Example 2 with AttributeValueElement

use of com.sun.identity.saml2.jaxb.assertion.AttributeValueElement in project OpenAM by OpenRock.

the class AttributeQueryUtil method convertAttributes.

private static List convertAttributes(List jaxbAttrs) throws SAML2Exception {
    List resultAttrs = new ArrayList();
    for (Iterator iter = jaxbAttrs.iterator(); iter.hasNext(); ) {
        AttributeElement jaxbAttr = (AttributeElement) iter.next();
        Attribute attr = AssertionFactory.getInstance().createAttribute();
        attr.setName(jaxbAttr.getName());
        attr.setNameFormat(jaxbAttr.getNameFormat());
        attr.setFriendlyName(jaxbAttr.getFriendlyName());
        List jaxbValues = jaxbAttr.getAttributeValue();
        if ((jaxbValues != null) && (!jaxbValues.isEmpty())) {
            List newValues = new ArrayList();
            for (Iterator iterV = jaxbValues.iterator(); iterV.hasNext(); ) {
                AttributeValueElement jaxbValeu = (AttributeValueElement) iter.next();
                List content = jaxbValeu.getContent();
                if ((content != null) && (!content.isEmpty())) {
                    newValues.add(content.get(0));
                }
            }
            if (!newValues.isEmpty()) {
                attr.setAttributeValueString(newValues);
            }
        }
        resultAttrs.add(attr);
    }
    return resultAttrs;
}
Also used : Attribute(com.sun.identity.saml2.assertion.Attribute) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) AttributeValueElement(com.sun.identity.saml2.jaxb.assertion.AttributeValueElement) AttributeElement(com.sun.identity.saml2.jaxb.assertion.AttributeElement)

Example 3 with AttributeValueElement

use of com.sun.identity.saml2.jaxb.assertion.AttributeValueElement in project OpenAM by OpenRock.

the class SAML2IDPProxyFRImpl method selectIDPBasedOnLOA.

private String selectIDPBasedOnLOA(List<String> idpList, String realm, AuthnRequest authnRequest) {
    String classMethod = "selectIdPBasedOnLOA";
    EntityDescriptorElement idpDesc = null;
    Set authnRequestContextSet = null;
    String idps = "";
    try {
        RequestedAuthnContext requestedAuthnContext = authnRequest.getRequestedAuthnContext();
        if (requestedAuthnContext == null) {
            //In this case we just simply return all the IdPs as each one should support a default AuthnContext.
            return StringUtils.join(idpList, " ");
        }
        List listOfAuthnContexts = requestedAuthnContext.getAuthnContextClassRef();
        debugMessage(classMethod, "listofAuthnContexts: " + listOfAuthnContexts);
        try {
            authnRequestContextSet = new HashSet(listOfAuthnContexts);
        } catch (Exception ex1) {
            authnRequestContextSet = new HashSet();
        }
        if ((idpList != null) && (!idpList.isEmpty())) {
            Iterator idpI = idpList.iterator();
            while (idpI.hasNext()) {
                String idp = (String) idpI.next();
                debugMessage(classMethod, "IDP is: " + idp);
                idpDesc = SAML2Utils.getSAML2MetaManager().getEntityDescriptor(realm, idp);
                if (idpDesc != null) {
                    ExtensionsType et = idpDesc.getExtensions();
                    if (et != null) {
                        debugMessage(classMethod, "Extensions found for idp: " + idp);
                        List idpExtensions = et.getAny();
                        if (idpExtensions != null || !idpExtensions.isEmpty()) {
                            debugMessage(classMethod, "Extensions content found for idp: " + idp);
                            Iterator idpExtensionsI = idpExtensions.iterator();
                            while (idpExtensionsI.hasNext()) {
                                EntityAttributesElement eael = (EntityAttributesElement) idpExtensionsI.next();
                                if (eael != null) {
                                    debugMessage(classMethod, "Entity Attributes found for idp: " + idp);
                                    List attribL = eael.getAttributeOrAssertion();
                                    if (attribL != null || !attribL.isEmpty()) {
                                        Iterator attrI = attribL.iterator();
                                        while (attrI.hasNext()) {
                                            AttributeElement ae = (AttributeElement) attrI.next();
                                            // TODO: Verify what type of element this is (Attribute or assertion)
                                            // For validation purposes
                                            List av = ae.getAttributeValue();
                                            if (av != null || !av.isEmpty()) {
                                                debugMessage(classMethod, "Attribute Values found for idp: " + idp);
                                                Iterator avI = av.iterator();
                                                while (avI.hasNext()) {
                                                    AttributeValueElement ave = (AttributeValueElement) avI.next();
                                                    if (ave != null) {
                                                        List contentL = ave.getContent();
                                                        debugMessage(classMethod, "Attribute Value Elements found for idp: " + idp + "-->" + contentL);
                                                        if (contentL != null || !contentL.isEmpty()) {
                                                            Set idpContextSet = trimmedListToSet(contentL);
                                                            debugMessage(classMethod, "idpContextSet = " + idpContextSet);
                                                            idpContextSet.retainAll(authnRequestContextSet);
                                                            if (idpContextSet != null && !idpContextSet.isEmpty()) {
                                                                idps = idp + " " + idps;
                                                                debugMessage(classMethod, "Extension Values found for idp " + idp + ": " + idpContextSet);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        debugMessage(classMethod, " No extensions found for IdP " + idp);
                    }
                } else {
                    debugMessage(classMethod, "Configuration for the idp " + idp + " was not found in this system");
                }
            }
        }
    } catch (SAML2MetaException me) {
        debugMessage(classMethod, "SOmething went wrong: " + me);
    }
    debugMessage(classMethod, " IDPList returns: " + idps);
    return idps.trim();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) EntityAttributesElement(com.sun.identity.saml2.jaxb.metadataattr.EntityAttributesElement) EntityDescriptorElement(com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement) COTException(com.sun.identity.cot.COTException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) RequestedAuthnContext(com.sun.identity.saml2.protocol.RequestedAuthnContext) ExtensionsType(com.sun.identity.saml2.jaxb.metadata.ExtensionsType) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) AttributeValueElement(com.sun.identity.saml2.jaxb.assertion.AttributeValueElement) AttributeElement(com.sun.identity.saml2.jaxb.assertion.AttributeElement) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) HashSet(java.util.HashSet)

Aggregations

AttributeValueElement (com.sun.identity.saml2.jaxb.assertion.AttributeValueElement)3 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2 AttributeElement (com.sun.identity.saml2.jaxb.assertion.AttributeElement)2 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)2 COTException (com.sun.identity.cot.COTException)1 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)1 Attribute (com.sun.identity.saml2.assertion.Attribute)1 EntityDescriptorElement (com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement)1 ExtensionsType (com.sun.identity.saml2.jaxb.metadata.ExtensionsType)1 EntityAttributesElement (com.sun.identity.saml2.jaxb.metadataattr.EntityAttributesElement)1 RequestedAuthnContext (com.sun.identity.saml2.protocol.RequestedAuthnContext)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SOAPException (javax.xml.soap.SOAPException)1