Author: anil.saldhana(a)jboss.com
Date: 2010-11-05 11:50:37 -0400 (Fri, 05 Nov 2010)
New Revision: 535
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java
Log:
handle the x500 attributes properly
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java 2010-11-04
21:47:35 UTC (rev 534)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/parsers/util/SAMLParserUtil.java 2010-11-05
15:50:37 UTC (rev 535)
@@ -95,7 +95,7 @@
if( x500EncodingAttr != null )
{
- attributeType.getOtherAttributes().put( x500EncodingName,
StaxParserUtil.getAttributeValue( x500EncodingAttr ));
+ attributeType.getOtherAttributes().put( x500EncodingAttr.getName(),
StaxParserUtil.getAttributeValue( x500EncodingAttr ));
}
Attribute name = startElement.getAttributeByName( new QName(
JBossSAMLConstants.NAME.get() ));
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2010-11-04
21:47:35 UTC (rev 534)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2010-11-05
15:50:37 UTC (rev 535)
@@ -24,7 +24,10 @@
import static
org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.ASSERTION_NSURI;
import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar;
@@ -190,7 +193,15 @@
ASSERTION_NSURI.get() );
StaxUtil.writeCharacters( writer, decl );
StaxUtil.writeEndElement( writer);
- }
+ }
+ else if( elName.getLocalPart().equals(
JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get() ))
+ {
+ String decl = (String) el.getValue();
+ StaxUtil.writeStartElement( writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_CONTEXT_CLASS_REF.get() ,
+ ASSERTION_NSURI.get() );
+ StaxUtil.writeCharacters( writer, decl );
+ StaxUtil.writeEndElement( writer);
+ }
else
throw new RuntimeException( "Unsupported :" + elName );
}
@@ -225,6 +236,27 @@
StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_FORMAT.get(),
friendlyName );
}
+ //Take care of other attributes such as x500:encoding
+ Map<QName, String> otherAttribs = attributeType.getOtherAttributes();
+ if( otherAttribs != null )
+ {
+ List<String> nameSpacesDealt = new ArrayList<String>();
+
+ Iterator<QName> keySet = otherAttribs.keySet().iterator();
+ while( keySet != null && keySet.hasNext() )
+ {
+ QName qname = keySet.next();
+ String ns = qname.getNamespaceURI();
+ if( !nameSpacesDealt.contains( ns ))
+ {
+ StaxUtil.writeNameSpace(writer, qname.getPrefix(), ns );
+ nameSpacesDealt.add( ns );
+ }
+ String attribValue = otherAttribs.get( qname );
+ StaxUtil.writeAttribute(writer, qname, attribValue );
+ }
+ }
+
List<Object> attributeValues = attributeType.getAttributeValue();
if( attributeValues != null )
{
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2010-11-04
21:47:35 UTC (rev 534)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2010-11-05
15:50:37 UTC (rev 535)
@@ -23,6 +23,7 @@
import java.io.OutputStream;
+import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
@@ -110,6 +111,25 @@
throw new ProcessingException( e );
}
}
+
+ /**
+ * Write an attribute
+ * @param writer
+ * @param attributeName QName of the attribute
+ * @param attributeValue
+ * @throws ProcessingException
+ */
+ public static void writeAttribute( XMLStreamWriter writer, QName attributeName, String
attributeValue ) throws ProcessingException
+ {
+ try
+ {
+ writer.writeAttribute( attributeName.getNamespaceURI() ,
attributeName.getLocalPart(), attributeValue );
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ProcessingException( e );
+ }
+ }
/**
* Write an xml attribute
Modified:
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-11-04
21:47:35 UTC (rev 534)
+++
federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLAssertionParserTestCase.java 2010-11-05
15:50:37 UTC (rev 535)
@@ -35,6 +35,7 @@
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLAssertionWriter;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
@@ -242,5 +243,8 @@
assertEquals( "https://sp.example.com/SAML2/SSO/POST",
subjectConfirmationData.getRecipient());
}
}
+
+ SAMLAssertionWriter writer = new SAMLAssertionWriter();
+ writer.write(assertion, System.out );
}
}
\ No newline at end of file
Show replies by date