Author: anil.saldhana(a)jboss.com
Date: 2011-06-27 13:31:32 -0400 (Mon, 27 Jun 2011)
New Revision: 1039
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/util/StaxUtil.java
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java
Log:
PLFED-192: saml writing
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 2011-06-27
17:30:40 UTC (rev 1038)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java 2011-06-27
17:31:32 UTC (rev 1039)
@@ -39,12 +39,14 @@
import org.picketlink.identity.federation.saml.v2.assertion.AdviceType;
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.AttributeStatementType.ASTChoiceType;
import org.picketlink.identity.federation.saml.v2.assertion.AttributeType;
import org.picketlink.identity.federation.saml.v2.assertion.AudienceRestrictionType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextClassRefType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextDeclRefType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextDeclType;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType;
+import
org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType.AuthnContextTypeSequence;
import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
import org.picketlink.identity.federation.saml.v2.assertion.BaseIDAbstractType;
import org.picketlink.identity.federation.saml.v2.assertion.ConditionAbstractType;
@@ -56,10 +58,8 @@
import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationDataType;
import org.picketlink.identity.federation.saml.v2.assertion.SubjectConfirmationType;
import org.picketlink.identity.federation.saml.v2.assertion.SubjectType;
+import org.picketlink.identity.federation.saml.v2.assertion.SubjectType.STSubType;
import org.picketlink.identity.federation.saml.v2.assertion.URIType;
-import
org.picketlink.identity.federation.saml.v2.assertion.AttributeStatementType.ASTChoiceType;
-import
org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType.AuthnContextTypeSequence;
-import org.picketlink.identity.federation.saml.v2.assertion.SubjectType.STSubType;
import
org.picketlink.identity.federation.saml.v2.profiles.xacml.assertion.XACMLAuthzDecisionStatementType;
import org.picketlink.identity.xmlsec.w3.xmldsig.KeyInfoType;
import org.picketlink.identity.xmlsec.w3.xmldsig.X509CertificateType;
@@ -111,8 +111,8 @@
ConditionsType conditions = assertion.getConditions();
if (conditions != null)
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.CONDITIONS.get(), ASSERTION_NSURI
- .get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.CONDITIONS.get(),
+ ASSERTION_NSURI.get());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_BEFORE.get(),
conditions.getNotBefore().toString());
StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_ON_OR_AFTER.get(),
conditions.getNotOnOrAfter()
@@ -165,15 +165,19 @@
{
write((AttributeStatementType) statement);
}
- else if (statement instanceof XACMLAuthzDecisionStatementType )
+ else if (statement instanceof XACMLAuthzDecisionStatementType)
{
write((XACMLAuthzDecisionStatementType) statement);
}
- else
+ else
throw new RuntimeException("unknown statement type=" +
statement.getClass().getName());
}
}
+ Element sig = assertion.getSignature();
+ if (sig != null)
+ StaxUtil.writeDOMElement(writer, sig);
+
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
@@ -225,7 +229,8 @@
*/
public void write(AuthnStatementType authnStatement) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_STATEMENT.get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_STATEMENT.get(),
+ ASSERTION_NSURI.get());
XMLGregorianCalendar authnInstant = authnStatement.getAuthnInstant();
if (authnInstant != null)
@@ -240,28 +245,26 @@
StaxUtil.writeEndElement(writer);
StaxUtil.flush(writer);
}
-
- public void write( XACMLAuthzDecisionStatementType xacmlStat ) throws
ProcessingException
- {
+
+ public void write(XACMLAuthzDecisionStatementType xacmlStat) throws
ProcessingException
+ {
StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.STATEMENT.get(), ASSERTION_NSURI.get());
-
+
StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
StaxUtil.writeNameSpace(writer, XACML_SAML_PREFIX,
JBossSAMLURIConstants.XACML_SAML_NSURI.get());
StaxUtil.writeNameSpace(writer, XACML_SAML_PROTO_PREFIX,
JBossSAMLURIConstants.XACML_SAML_PROTO_NSURI.get());
StaxUtil.writeNameSpace(writer, XSI_PREFIX,
JBossSAMLURIConstants.XSI_NSURI.get());
-
- StaxUtil.writeAttribute( writer,
- new QName(
JBossSAMLURIConstants.XSI_NSURI.get(),JBossSAMLConstants.TYPE.get(), XSI_PREFIX),
- XACMLAuthzDecisionStatementType.XSI_TYPE );
-
+ StaxUtil.writeAttribute(writer, new QName(JBossSAMLURIConstants.XSI_NSURI.get(),
JBossSAMLConstants.TYPE.get(),
+ XSI_PREFIX), XACMLAuthzDecisionStatementType.XSI_TYPE);
+
ResponseType responseType = xacmlStat.getResponse();
- if( responseType == null )
- throw new RuntimeException( " XACML response is null" );
-
+ if (responseType == null)
+ throw new RuntimeException(" XACML response is null");
+
Document doc = SAMLXACMLUtil.getXACMLResponse(responseType);
- StaxUtil.writeDOMElement(writer, doc.getDocumentElement() );
-
+ StaxUtil.writeDOMElement(writer, doc.getDocumentElement());
+
/*try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -279,12 +282,12 @@
{
throw new ProcessingException( e );
}*/
-
+
RequestType requestType = xacmlStat.getRequest();
- if( requestType != null )
- {
- StaxUtil.writeDOMNode(writer,
SAMLXACMLUtil.getXACMLRequest(requestType).getDocumentElement() );
-
+ if (requestType != null)
+ {
+ StaxUtil.writeDOMNode(writer,
SAMLXACMLUtil.getXACMLRequest(requestType).getDocumentElement());
+
/*try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -304,7 +307,7 @@
}*/
}
StaxUtil.writeEndElement(writer);
- StaxUtil.flush(writer);
+ StaxUtil.flush(writer);
}
/**
@@ -316,7 +319,8 @@
*/
public void write(AuthnContextType authContext) throws ProcessingException
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_CONTEXT.get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_CONTEXT.get(),
+ ASSERTION_NSURI.get());
AuthnContextTypeSequence sequence = authContext.getSequence();
if (sequence != null)
@@ -337,15 +341,15 @@
{
if (uriType instanceof AuthnContextDeclType)
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION
- .get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
+ JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION.get(),
ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
if (uriType instanceof AuthnContextDeclRefType)
{
- StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF
- .get(), ASSERTION_NSURI.get());
+ StaxUtil.writeStartElement(writer, ASSERTION_PREFIX,
+ JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get(),
ASSERTION_NSURI.get());
StaxUtil.writeCharacters(writer, uriType.getValue().toASCIIString());
StaxUtil.writeEndElement(writer);
}
@@ -369,8 +373,6 @@
StaxUtil.flush(writer);
}
-
-
/**
* write an {@code SubjectType} to stream
*
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-06-27
17:30:40 UTC (rev 1038)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/StaxUtil.java 2011-06-27
17:31:32 UTC (rev 1039)
@@ -102,7 +102,7 @@
throw new ProcessingException(e);
}
}
-
+
/**
* Get an {@code XMLStreamWriter}
*
@@ -110,12 +110,12 @@
* @return
* @throws ProcessingException
*/
- public static XMLStreamWriter getXMLStreamWriter(final Writer writer ) throws
ProcessingException
+ public static XMLStreamWriter getXMLStreamWriter(final Writer writer) throws
ProcessingException
{
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
try
{
- return xmlOutputFactory.createXMLStreamWriter( writer );
+ return xmlOutputFactory.createXMLStreamWriter(writer);
}
catch (XMLStreamException e)
{
@@ -165,6 +165,21 @@
* @param attributeValue
* @throws ProcessingException
*/
+ public static void writeAttribute(XMLStreamWriter writer, String attributeName, QName
attributeValue)
+ throws ProcessingException
+ {
+ writeAttribute(writer, attributeName, attributeValue.toString());
+ }
+
+ /**
+ * 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
{
@@ -244,7 +259,7 @@
throw new ProcessingException(e);
}
}
-
+
/**
* Write a string as text node
*
@@ -256,7 +271,7 @@
{
try
{
- writer.writeCData( value );
+ writer.writeCData(value);
}
catch (XMLStreamException e)
{
Modified:
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java
===================================================================
---
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java 2011-06-27
17:30:40 UTC (rev 1038)
+++
federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/plugins/saml/SAMLUtil.java 2011-06-27
17:31:32 UTC (rev 1039)
@@ -29,8 +29,8 @@
import org.picketlink.identity.federation.core.exceptions.ParsingException;
import org.picketlink.identity.federation.core.exceptions.ProcessingException;
import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
+import org.picketlink.identity.federation.core.saml.v1.writers.SAML11AssertionWriter;
import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
-import org.picketlink.identity.federation.core.saml.v2.writers.SAML11AssertionWriter;
import org.picketlink.identity.federation.core.saml.v2.writers.SAMLAssertionWriter;
import org.picketlink.identity.federation.core.util.StaxUtil;
import org.picketlink.identity.federation.saml.v1.assertion.SAML11AssertionType;