Search in sources :

Example 11 with Attribute

use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.

the class DefaultIDPAttributeMapper method getSAMLAttribute.

/**
     * Returns the SAML <code>Attribute</code> object.
     * @param name attribute name.
     * @param values attribute values.
     * @exception WSFederationException if any failure.
     */
protected Attribute getSAMLAttribute(String name, String[] values) throws WSFederationException {
    if (name == null) {
        throw new WSFederationException(bundle.getString("nullInput"));
    }
    List list = new ArrayList();
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            // Make the AttributeValue element 'by hand', since Attribute 
            // constructor below is expecting a list of AttributeValue 
            // elements
            String attrValueString = SAMLUtils.makeStartElementTagXML("AttributeValue", true, true) + (XMLUtils.escapeSpecialCharacters(values[i])) + SAMLUtils.makeEndElementTagXML("AttributeValue", true);
            list.add(XMLUtils.toDOMDocument(attrValueString, SAMLUtils.debug).getDocumentElement());
        }
    }
    Attribute attribute = null;
    try {
        attribute = new Attribute(name, WSFederationConstants.CLAIMS_URI, list);
    } catch (SAMLException se) {
        throw new WSFederationException(se);
    }
    return attribute;
}
Also used : WSFederationException(com.sun.identity.wsfederation.common.WSFederationException) Attribute(com.sun.identity.saml.assertion.Attribute) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 12 with Attribute

use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.

the class DefaultLibrarySPAccountMapper method getAttribute.

/**
     * Returns the attribute name.
     */
private Set getAttribute(AttributeStatement statement, String attributeName, String realm, String hostEntityID) {
    if (debug.messageEnabled()) {
        debug.message("DefaultLibrarySPAccountMapper.getAttribute: attribute" + "Name =" + attributeName);
    }
    List list = statement.getAttribute();
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        Attribute attribute = (Attribute) iter.next();
        if (!attributeName.equalsIgnoreCase(attribute.getAttributeName())) {
            continue;
        }
        List values = null;
        try {
            values = attribute.getAttributeValue();
        } catch (SAMLException se) {
        // Just ignore it and carry on - getAttributeValue doesn't
        // really throw an exception - it just says it does
        }
        if (values == null || values.size() == 0) {
            return null;
        }
        Set set = new HashSet();
        set.addAll(values);
        return set;
    }
    return null;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Attribute(com.sun.identity.saml.assertion.Attribute) Iterator(java.util.Iterator) List(java.util.List) SAMLException(com.sun.identity.saml.common.SAMLException) HashSet(java.util.HashSet)

Example 13 with Attribute

use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.

the class DefaultSPAttributeMapper method getAttributes.

/**
     * Returns attribute map for the given list of <code>Attribute</code>
     * objects. 
     * @param attributes list <code>Attribute</code>objects.
     * @param userID universal identifier or distinguished name(DN) of the user.
     * @param hostEntityID <code>EntityID</code> of the hosted provider.
     * @param remoteEntityID <code>EntityID</code> of the remote provider. 
     * @param realm realm name.
     * @return a map of mapped attribute value pair. This map has the
     *         key as the attribute name and the value as the attribute value
     * @exception WSFederationException if any failure.
     */
public Map getAttributes(List attributes, String userID, String hostEntityID, String remoteEntityID, String realm) throws WSFederationException {
    if (attributes == null || attributes.size() == 0) {
        throw new WSFederationException(bundle.getString("nullAttributes"));
    }
    if (hostEntityID == null) {
        throw new WSFederationException(bundle.getString("nullHostEntityID"));
    }
    if (realm == null) {
        throw new WSFederationException(bundle.getString("nullRealm"));
    }
    Map<String, Set<String>> map = new HashMap<String, Set<String>>();
    Map configMap = getConfigAttributeMap(realm, hostEntityID);
    for (Iterator iter = attributes.iterator(); iter.hasNext(); ) {
        Attribute attribute = (Attribute) iter.next();
        Set<String> values = new HashSet();
        try {
            List attrValues = attribute.getAttributeValue();
            for (Iterator iter2 = attrValues.iterator(); iter2.hasNext(); ) {
                Element attrValue = (Element) iter2.next();
                values.add(XMLUtils.getElementValue(attrValue));
            }
        } catch (SAMLException se) {
            throw new WSFederationException(se);
        }
        String attributeName = attribute.getAttributeName();
        String localAttribute = (String) configMap.get(attributeName);
        if (localAttribute == null || localAttribute.length() == 0) {
            localAttribute = attributeName;
        }
        Set<String> existingValues = map.get(localAttribute);
        if (existingValues != null) {
            existingValues.addAll(values);
        } else {
            map.put(localAttribute, values);
        }
    }
    return map;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) WSFederationException(com.sun.identity.wsfederation.common.WSFederationException) HashMap(java.util.HashMap) Attribute(com.sun.identity.saml.assertion.Attribute) Element(org.w3c.dom.Element) SAMLException(com.sun.identity.saml.common.SAMLException) Iterator(java.util.Iterator) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 14 with Attribute

use of com.sun.identity.saml.assertion.Attribute in project OpenAM by OpenRock.

the class SAMLUtils method addEnvParamsFromAssertion.

/**
     * Returns attributes included in <code>AttributeStatement</code> of the
     * assertion.
     * @param envParameters return map which includes name value pairs of 
     *   attributes included in <code>AttributeStatement</code> of the assertion
     * @param assertion an <code>Assertion</code> object which contains
     *   <code>AttributeStatement</code>
     * @param subject the <code>Subject</code> instance from
     *   <code>AuthenticationStatement</code>. The <code>Subject</code>
     *   included in <code>AttributeStatement</code> must match this
     *   <code>Subject</code> instance.
     */
public static void addEnvParamsFromAssertion(Map envParameters, Assertion assertion, com.sun.identity.saml.assertion.Subject subject) {
    Set statements = assertion.getStatement();
    Statement statement = null;
    Iterator stmtIter = null;
    List attrs = null;
    Iterator attrIter = null;
    Attribute attribute = null;
    Element attrValue = null;
    List attrValues = null;
    String attrName = null;
    String attrValueString = null;
    if ((statements != null) && (!statements.isEmpty())) {
        stmtIter = statements.iterator();
        while (stmtIter.hasNext()) {
            statement = (Statement) stmtIter.next();
            if (statement.getStatementType() == Statement.ATTRIBUTE_STATEMENT) {
                // check for subject
                if (!subject.equals(((AttributeStatement) statement).getSubject())) {
                    continue;
                }
                attrs = ((AttributeStatement) statement).getAttribute();
                attrIter = attrs.iterator();
                while (attrIter.hasNext()) {
                    attribute = (Attribute) attrIter.next();
                    try {
                        attrValues = attribute.getAttributeValue();
                    } catch (Exception e) {
                        debug.error("SAMLUtils.addEnvParamsFromAssertion:" + " cannot obtain attribute value:", e);
                        continue;
                    }
                    attrName = attribute.getAttributeName();
                    List attrValueList = null;
                    for (Iterator avIter = attrValues.iterator(); avIter.hasNext(); ) {
                        attrValue = (Element) avIter.next();
                        if (!XMLUtils.hasElementChild(attrValue)) {
                            attrValueString = XMLUtils.getElementValue(attrValue);
                            if (attrValueList == null) {
                                attrValueList = new ArrayList();
                            }
                            attrValueList.add(attrValueString);
                        }
                    }
                    if (attrValueList != null) {
                        if (debug.messageEnabled()) {
                            debug.message("SAMLUtils.addEnvParamsFromAssertion:" + " attrName = " + attrName + " attrValue = " + attrValueList);
                        }
                        String[] attrValueStrs = (String[]) attrValueList.toArray(new String[attrValueList.size()]);
                        try {
                            envParameters.put(attrName, attrValueStrs);
                        } catch (Exception ex) {
                            if (debug.messageEnabled()) {
                                debug.message("SAMLUtils.addEnvParamsFromAssertion:", ex);
                            }
                        }
                    } else if (debug.messageEnabled()) {
                        if (debug.messageEnabled()) {
                            debug.message("SAMLUtils.addEnvParamsFromAssertion:" + " attrName = " + attrName + " has no value");
                        }
                    }
                }
            }
        // if it's an attribute statement
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Attribute(com.sun.identity.saml.assertion.Attribute) Statement(com.sun.identity.saml.assertion.Statement) AuthenticationStatement(com.sun.identity.saml.assertion.AuthenticationStatement) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) SubjectStatement(com.sun.identity.saml.assertion.SubjectStatement) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) CharacterIterator(java.text.CharacterIterator) Iterator(java.util.Iterator) StringCharacterIterator(java.text.StringCharacterIterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ServletException(javax.servlet.ServletException) SystemConfigurationException(com.sun.identity.common.SystemConfigurationException) SessionException(com.sun.identity.plugin.session.SessionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

Attribute (com.sun.identity.saml.assertion.Attribute)14 SAMLException (com.sun.identity.saml.common.SAMLException)13 List (java.util.List)12 Iterator (java.util.Iterator)11 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 Set (java.util.Set)7 AttributeStatement (com.sun.identity.saml.assertion.AttributeStatement)6 HashSet (java.util.HashSet)6 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)5 IDFFMetaManager (com.sun.identity.federation.meta.IDFFMetaManager)5 SessionException (com.sun.identity.plugin.session.SessionException)5 HashMap (java.util.HashMap)4 DataStoreProvider (com.sun.identity.plugin.datastore.DataStoreProvider)3 IDPDescriptorConfigElement (com.sun.identity.federation.jaxb.entityconfig.IDPDescriptorConfigElement)2 SPDescriptorConfigElement (com.sun.identity.federation.jaxb.entityconfig.SPDescriptorConfigElement)2 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)2 SessionProvider (com.sun.identity.plugin.session.SessionProvider)2 Assertion (com.sun.identity.saml.assertion.Assertion)2 WSFederationException (com.sun.identity.wsfederation.common.WSFederationException)2