Search in sources :

Example 6 with AuthenticationStatement

use of com.sun.identity.saml.assertion.AuthenticationStatement 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

AuthenticationStatement (com.sun.identity.saml.assertion.AuthenticationStatement)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 AttributeStatement (com.sun.identity.saml.assertion.AttributeStatement)4 Statement (com.sun.identity.saml.assertion.Statement)4 Iterator (java.util.Iterator)4 SessionException (com.sun.identity.plugin.session.SessionException)3 Subject (com.sun.identity.saml.assertion.Subject)3 SubjectConfirmation (com.sun.identity.saml.assertion.SubjectConfirmation)3 SubjectStatement (com.sun.identity.saml.assertion.SubjectStatement)3 CharacterIterator (java.text.CharacterIterator)3 StringCharacterIterator (java.text.StringCharacterIterator)3 SAMLException (com.sun.identity.saml.common.SAMLException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 SystemConfigurationException (com.sun.identity.common.SystemConfigurationException)1 Assertion (com.sun.identity.saml.assertion.Assertion)1 Attribute (com.sun.identity.saml.assertion.Attribute)1 AudienceRestrictionCondition (com.sun.identity.saml.assertion.AudienceRestrictionCondition)1