Author: anil.saldhana(a)jboss.com
Date: 2011-07-27 18:40:37 -0400 (Wed, 27 Jul 2011)
New Revision: 1137
Modified:
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java
Log:
PLFED-216: new method in StaxUtil
Modified:
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java
===================================================================
---
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java 2011-07-27
19:15:46 UTC (rev 1136)
+++
federation/trunk/picketlink-fed-api/src/test/java/org/picketlink/test/identity/federation/api/saml/v2/SAML2ResponseUnitTestCase.java 2011-07-27
22:40:37 UTC (rev 1137)
@@ -23,6 +23,8 @@
import static org.junit.Assert.assertNotNull;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.security.Key;
import java.security.KeyPair;
@@ -42,6 +44,9 @@
import org.picketlink.identity.federation.core.saml.v2.util.AssertionUtil;
import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
import org.picketlink.identity.federation.core.saml.v2.util.StatementUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter;
+import org.picketlink.identity.federation.core.util.JAXPValidationUtil;
+import org.picketlink.identity.federation.core.util.StaxUtil;
import org.picketlink.identity.federation.saml.v2.SAML2Object;
import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType;
@@ -124,6 +129,18 @@
assertNotNull(signedDoc);
System.out.println("Signed Response=" +
DocumentUtil.asString(signedDoc));
+
+ Document convertedDoc = samlResponse.convert(responseType);
+ assertNotNull(convertedDoc);
+
+ //Now for the writing part
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ SAMLResponseWriter samlWriter = new
SAMLResponseWriter(StaxUtil.getXMLStreamWriter(baos));
+ samlWriter.write(responseType);
+
+ Document doc = DocumentUtil.getDocument(new
ByteArrayInputStream(baos.toByteArray()));
+ JAXPValidationUtil.validate(DocumentUtil.getNodeAsStream(doc));
}
/**
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java 2011-07-27
19:15:46 UTC (rev 1136)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v1/writers/SAML11AssertionWriter.java 2011-07-27
22:40:37 UTC (rev 1137)
@@ -82,7 +82,7 @@
StaxUtil.writeDefaultNameSpace(writer, ns);
// Attributes
-// StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), assertion.getID());
+ // StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(),
assertion.getID());
StaxUtil.writeAttribute(writer, SAML11Constants.ASSERTIONID, assertion.getID());
StaxUtil.writeAttribute(writer, SAML11Constants.MAJOR_VERSION,
assertion.getMajorVersion() + "");
StaxUtil.writeAttribute(writer, SAML11Constants.MINOR_VERSION,
assertion.getMinorVersion() + "");
@@ -452,7 +452,7 @@
StaxUtil.writeNameSpace(writer, JBossSAMLURIConstants.XSI_PREFIX.get(),
JBossSAMLURIConstants.XSI_NSURI.get());
StaxUtil.writeNameSpace(writer, "xs",
JBossSAMLURIConstants.XMLSCHEMA_NSURI.get());
- StaxUtil.writeAttribute(writer, JBossSAMLURIConstants.XSI_NSURI.get(),
"type", "xs:string");
+ StaxUtil.writeAttribute(writer, "xsi",
JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xs:string");
StaxUtil.writeCharacters(writer, attributeValue);
StaxUtil.writeEndElement(writer);
}
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java 2011-07-27
19:15:46 UTC (rev 1136)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java 2011-07-27
22:40:37 UTC (rev 1137)
@@ -205,7 +205,7 @@
StaxUtil.writeNameSpace(writer, JBossSAMLURIConstants.XSI_PREFIX.get(),
JBossSAMLURIConstants.XSI_NSURI.get());
StaxUtil.writeNameSpace(writer, "xs",
JBossSAMLURIConstants.XMLSCHEMA_NSURI.get());
- StaxUtil.writeAttribute(writer, JBossSAMLURIConstants.XSI_NSURI.get(),
"type", "xs:string");
+ StaxUtil.writeAttribute(writer, "xsi",
JBossSAMLURIConstants.XSI_NSURI.get(), "type", "xs:string");
StaxUtil.writeCharacters(writer, attributeValue);
StaxUtil.writeEndElement(writer);
}
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 2011-07-27
19:15:46 UTC (rev 1136)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2011-07-27
22:40:37 UTC (rev 1137)
@@ -242,6 +242,32 @@
}
/**
+ * Write an xml attribute
+ *
+ * @param writer
+ * @param prefix prefix for the attribute
+ * @param localName
+ * localpart
+ * @param type
+ * typically xsi:type
+ * @param value
+ * value of the attribute
+ * @throws ProcessingException
+ */
+ public static void writeAttribute(XMLStreamWriter writer, String prefix, String
localName, String type, String value)
+ throws ProcessingException
+ {
+ try
+ {
+ writer.writeAttribute(prefix, localName, type, value);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new ProcessingException(e);
+ }
+ }
+
+ /**
* Write a string as text node
*
* @param writer