[jboss-cvs] Picketlink SVN: r519 - in federation/trunk/picketlink-fed-core/src: main/java/org/picketlink/identity/federation/core/saml/v2/writers and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Nov 3 10:15:54 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-11-03 10:15:54 -0400 (Wed, 03 Nov 2010)
New Revision: 519

Added:
   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/SAMLAssertionWriter.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java
Modified:
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
   federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
Log:
PLFED-109: PLFED-110: add write of saml response

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java	2010-11-03 03:29:36 UTC (rev 518)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/constants/JBossSAMLConstants.java	2010-11-03 14:15:54 UTC (rev 519)
@@ -35,6 +35,7 @@
    AUDIENCE_RESTRICTION( "AudienceRestriction" ),
    AUTHN_CONTEXT( "AuthnContext" ),
    AUTHN_CONTEXT_DECLARATION_REF( "AuthnContextDeclRef" ),
+   AUTHN_INSTANT( "AuthnInstant" ),
    AUTHN_REQUEST( "AuthnRequest" ),
    AUTHN_STATEMENT( "AuthnStatement" ),
    CONDITIONS( "Conditions" ),
@@ -42,6 +43,7 @@
    DESTINATION( "Destination" ),
    FORMAT( "Format" ),
    ID( "ID" ),
+   IN_RESPONSE_TO( "InResponseTo" ),
    ISSUE_INSTANT( "IssueInstant" ),
    ISSUER( "Issuer" ),
    LANG_EN("en"),
@@ -60,8 +62,11 @@
    SIGNATURE_SHA1_WITH_RSA("http://www.w3.org/2000/09/xmldsig#rsa-sha1"),
    STATUS( "Status" ),
    STATUS_CODE( "StatusCode" ),
+   STATUS_DETAIL( "StatusDetail" ),
+   STATUS_MESSAGE( "StatusMessage" ),
    SUBJECT( "Subject" ),
    SUBJECT_CONFIRMATION( "SubjectConfirmation" ),
+   VALUE( "Value" ),
    VERSION( "Version" ),
    VERSION_2_0("2.0"),
    HTTP_POST_BINDING("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");

Added: 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	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/BaseWriter.java	2010-11-03 14:15:54 UTC (rev 519)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.saml.v2.writers;
+
+import java.io.OutputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+
+/**
+ * Base Class for the Stax writers for SAML
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 2, 2010
+ */
+public class BaseWriter
+{
+   protected static String PROTOCOL_PREFIX = "samlp";
+   protected static String ASSERTION_PREFIX = "saml";
+   
+   protected XMLStreamWriter writer = null;  
+   
+   /**
+    * Write {@code NameIDType} to stream
+    * @param nameIDType
+    * @param tag
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( NameIDType nameIDType, QName tag, OutputStream out ) throws ProcessingException
+   {
+      if( writer == null )
+         writer = StaxUtil.getXMLStreamWriter( out ); 
+      
+      StaxUtil.writeStartElement( writer, tag.getPrefix(), tag.getLocalPart() , tag.getNamespaceURI() );
+      
+      String format = nameIDType.getFormat();
+      if( StringUtil.isNotNull( format ))
+      {
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(), format );
+      }
+      
+      String spProvidedID = nameIDType.getSPProvidedID();
+      if( StringUtil.isNotNull( spProvidedID ))
+      {
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_PROVIDED_ID.get(), spProvidedID );
+      }
+      
+      String spNameQualifier = nameIDType.getSPNameQualifier();
+      if( StringUtil.isNotNull( spNameQualifier ))
+      {
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(), spNameQualifier );
+      }
+      
+      String nameQualifier = nameIDType.getNameQualifier();
+      if( StringUtil.isNotNull( nameQualifier ))
+      {
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_QUALIFIER.get(), nameQualifier );
+      } 
+      
+      String value = nameIDType.getValue();
+      if( StringUtil.isNotNull( value ))
+      {
+         StaxUtil.writeCharacters( writer, value );
+      }
+      
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer ); 
+   }
+   
+   protected void verifyWriter( OutputStream out ) throws ProcessingException
+   { 
+      if( writer == null )
+         writer = StaxUtil.getXMLStreamWriter( out ); 
+   }
+
+}
\ No newline at end of file

Added: 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	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLAssertionWriter.java	2010-11-03 14:15:54 UTC (rev 519)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.saml.v2.writers;
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.ASSERTION_NSURI;
+
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.AuthnContextType;
+import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.assertion.StatementAbstractType;
+
+/**
+ * Write the SAML Assertion to stream
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 2, 2010
+ */
+public class SAMLAssertionWriter extends BaseWriter
+{
+   /**
+    * Write an {@code AssertionType} to stream
+    * @param assertion
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( AssertionType assertion, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out ); 
+
+      StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.ASSERTION.get() , ASSERTION_NSURI.get() ); 
+      StaxUtil.writeNameSpace( writer, ASSERTION_PREFIX, ASSERTION_NSURI.get() );
+      StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+
+      //Attributes 
+      StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), assertion.getID() );
+      StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(), assertion.getVersion() );
+      StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(), assertion.getIssueInstant().toString() );     
+
+      NameIDType issuer = assertion.getIssuer();
+      write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out ); 
+      
+      List<StatementAbstractType> statements = assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement();
+      if( statements != null )
+      {
+         for( StatementAbstractType statement: statements )
+         {
+            if( statement instanceof AuthnStatementType )
+            {
+               write( ( AuthnStatementType )statement, out );
+            }
+            else write( statement, out );
+         }
+      }
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer );  
+   } 
+   
+   /**
+    * Write an {@code StatementAbstractType} to stream
+    * @param statement
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( StatementAbstractType statement, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+      //TODO: handle this section
+   }
+   
+   /**
+    * Write an {@code AuthnStatementType} to stream
+    * @param authnStatement
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( AuthnStatementType authnStatement, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+      StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_STATEMENT.get() , ASSERTION_NSURI.get() );  
+      
+      XMLGregorianCalendar authnInstant = authnStatement.getAuthnInstant();
+      if( authnInstant != null )
+      { 
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.AUTHN_INSTANT.get(), authnInstant.toString() );
+      }
+      
+      AuthnContextType authnContext = authnStatement.getAuthnContext();
+      if( authnContext != null )
+        write( authnContext, out );
+
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer );  
+   }
+   
+   /**
+    * Write an {@code AuthnContextType} to stream
+    * @param authContext
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( AuthnContextType authContext, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+      StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT.get() , ASSERTION_NSURI.get() );  
+      
+      List< JAXBElement<?> > subList = authContext.getContent();
+      if( subList != null )
+      {
+         for( JAXBElement<?> el: subList )
+         {
+            QName elName = el.getName();
+            if( elName.getLocalPart().equals( JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get() ))
+            {
+               String decl = (String) el.getValue();
+               StaxUtil.writeStartElement( writer, ASSERTION_PREFIX, JBossSAMLConstants.AUTHN_CONTEXT_DECLARATION_REF.get() ,
+                     ASSERTION_NSURI.get() );  
+               StaxUtil.writeCharacters( writer, decl );
+               StaxUtil.writeEndElement( writer);  
+            }  
+            else
+               throw new RuntimeException( "Unsupported :" + elName );
+         }
+      }
+   }
+}
\ No newline at end of file

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java	2010-11-03 03:29:36 UTC (rev 518)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLRequestWriter.java	2010-11-03 14:15:54 UTC (rev 519)
@@ -27,7 +27,6 @@
 import java.io.OutputStream;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamWriter;
 
 import org.picketlink.identity.federation.core.exceptions.ProcessingException;
 import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
@@ -42,12 +41,8 @@
  * @author Anil.Saldhana at redhat.com
  * @since Nov 2, 2010
  */
-public class SAMLRequestWriter
-{
-   private static String PROTOCOL_PREFIX = "samlp";
-   
-   private XMLStreamWriter writer = null;  
-   
+public class SAMLRequestWriter extends BaseWriter
+{   
    /**
     * Write a {@code AuthnRequestType } to stream
     * @param request
@@ -56,9 +51,7 @@
     */
    public void write( AuthnRequestType request, OutputStream out ) throws ProcessingException
    { 
-      //Get the XML writer
-      if( writer == null )
-         writer = StaxUtil.getXMLStreamWriter( out ); 
+      verifyWriter( out ); 
       
       StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.AUTHN_REQUEST.get() , PROTOCOL_NSURI.get() ); 
       
@@ -94,54 +87,6 @@
    }
    
    /**
-    * Write {@code NameIDType} to stream
-    * @param nameIDType
-    * @param tag
-    * @param out
-    * @throws ProcessingException
-    */
-   public void write( NameIDType nameIDType, QName tag, OutputStream out ) throws ProcessingException
-   {
-      if( writer == null )
-         writer = StaxUtil.getXMLStreamWriter( out ); 
-      
-      StaxUtil.writeStartElement( writer, tag.getPrefix(), tag.getLocalPart() , tag.getNamespaceURI() );
-      
-      String format = nameIDType.getFormat();
-      if( StringUtil.isNotNull( format ))
-      {
-         StaxUtil.writeAttribute( writer, JBossSAMLConstants.FORMAT.get(), format );
-      }
-      
-      String spProvidedID = nameIDType.getSPProvidedID();
-      if( StringUtil.isNotNull( spProvidedID ))
-      {
-         StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_PROVIDED_ID.get(), spProvidedID );
-      }
-      
-      String spNameQualifier = nameIDType.getSPNameQualifier();
-      if( StringUtil.isNotNull( spNameQualifier ))
-      {
-         StaxUtil.writeAttribute( writer, JBossSAMLConstants.SP_NAME_QUALIFIER.get(), spNameQualifier );
-      }
-      
-      String nameQualifier = nameIDType.getNameQualifier();
-      if( StringUtil.isNotNull( nameQualifier ))
-      {
-         StaxUtil.writeAttribute( writer, JBossSAMLConstants.NAME_QUALIFIER.get(), nameQualifier );
-      } 
-      
-      String value = nameIDType.getValue();
-      if( StringUtil.isNotNull( value ))
-      {
-         StaxUtil.writeCharacters( writer, value );
-      }
-      
-      StaxUtil.writeEndElement( writer); 
-      StaxUtil.flush( writer ); 
-   }
-   
-   /**
     * Write a {@code NameIDPolicyType} to stream
     * @param nameIDPolicy
     * @param out
@@ -149,8 +94,7 @@
     */
    public void write( NameIDPolicyType nameIDPolicy, OutputStream out ) throws ProcessingException
    {
-      if( writer == null )
-         writer = StaxUtil.getXMLStreamWriter( out ); 
+      verifyWriter( out );
       
       StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.NAMEID_POLICY.get(), PROTOCOL_NSURI.get() );
       

Added: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java	                        (rev 0)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/saml/v2/writers/SAMLResponseWriter.java	2010-11-03 14:15:54 UTC (rev 519)
@@ -0,0 +1,181 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.picketlink.identity.federation.core.saml.v2.writers;
+
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.ASSERTION_NSURI;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+
+import java.io.OutputStream;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+ 
+import org.picketlink.identity.federation.core.exceptions.ProcessingException;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.picketlink.identity.federation.core.util.StaxUtil;
+import org.picketlink.identity.federation.core.util.StringUtil;
+import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
+import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
+import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusCodeType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusDetailType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusResponseType;
+import org.picketlink.identity.federation.saml.v2.protocol.StatusType;
+
+/**
+ * Write a SAML Response to stream
+ * @author Anil.Saldhana at redhat.com
+ * @since Nov 2, 2010
+ */
+public class SAMLResponseWriter extends BaseWriter
+{  
+   private  SAMLAssertionWriter assertionWriter = new SAMLAssertionWriter();
+   /**
+    * Write a {@code ResponseType} to stream
+    * @param response
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( ResponseType response, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+      
+      StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.RESPONSE.get() , PROTOCOL_NSURI.get() ); 
+      
+      StaxUtil.writeNameSpace( writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get() );   
+      StaxUtil.WriteDefaultNameSpace( writer, ASSERTION_NSURI.get() );
+      
+      writeBaseAttributes( response ); 
+
+      NameIDType issuer = response.getIssuer();
+      write( issuer, new QName( ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get() ), out ); 
+      
+      StatusType status = response.getStatus();
+      write( status, out );
+      
+      List<Object> assertions = response.getAssertionOrEncryptedAssertion();
+      if( assertions != null )
+      {
+         for( Object assertion: assertions )
+         {
+            if( assertion instanceof AssertionType )
+            {
+               assertionWriter.write( (AssertionType) assertion, out );
+            }
+         }
+      }
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer );  
+   }
+   
+   /**
+    * Write a {@code StatusType} to stream
+    * @param status
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( StatusType status, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+      StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS.get() , PROTOCOL_NSURI.get() ); 
+      
+      StatusCodeType statusCodeType = status.getStatusCode();
+      write( statusCodeType , out );
+      
+      String statusMessage = status.getStatusMessage();
+      if( StringUtil.isNotNull( statusMessage ))
+      {
+         StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_MESSAGE.get() , PROTOCOL_NSURI.get() ); 
+         StaxUtil.writeEndElement( writer);  
+      }
+      
+      StatusDetailType statusDetail = status.getStatusDetail();
+      if( statusDetail != null )
+         write( statusDetail, out );
+      
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer );  
+   }
+   
+   /**
+    * Write a {@code StatusCodeType} to stream
+    * @param statusCodeType
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( StatusCodeType statusCodeType, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+
+      StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_CODE.get() , PROTOCOL_NSURI.get() ); 
+      
+      String value = statusCodeType.getValue();
+      if( StringUtil.isNotNull( value ))
+      { 
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.VALUE.get(), value );
+      }
+      
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer ); 
+   }
+   
+   /**
+    * Write a {@code StatusDetailType} to stream
+    * @param statusDetailType
+    * @param out
+    * @throws ProcessingException
+    */
+   public void write( StatusDetailType statusDetailType, OutputStream out ) throws ProcessingException
+   {
+      verifyWriter( out );
+
+      StaxUtil.writeStartElement( writer, PROTOCOL_PREFIX, JBossSAMLConstants.STATUS_CODE.get() , PROTOCOL_NSURI.get() ); 
+      
+      StaxUtil.writeEndElement( writer); 
+      StaxUtil.flush( writer ); 
+   }
+   
+   /**
+    * Write the common attributes for all response types
+    * @param statusResponse
+    * @throws ProcessingException
+    */
+   private void writeBaseAttributes( StatusResponseType statusResponse ) throws ProcessingException
+   {
+      //Attributes 
+      StaxUtil.writeAttribute( writer, JBossSAMLConstants.ID.get(), statusResponse.getID() );
+      StaxUtil.writeAttribute( writer, JBossSAMLConstants.VERSION.get(), statusResponse.getVersion() );
+      StaxUtil.writeAttribute( writer, JBossSAMLConstants.ISSUE_INSTANT.get(), statusResponse.getIssueInstant().toString() );
+      
+      String destination = statusResponse.getDestination();
+      if( StringUtil.isNotNull( destination ))
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.DESTINATION.get(), destination ); 
+
+      String consent = statusResponse.getConsent();
+      if( StringUtil.isNotNull( consent ))
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.CONSENT.get(), consent );
+      
+      String inResponseTo = statusResponse.getInResponseTo();
+      if( StringUtil.isNotNull( inResponseTo ))
+         StaxUtil.writeAttribute( writer, JBossSAMLConstants.IN_RESPONSE_TO.get(), inResponseTo ); 
+   } 
+}
\ No newline at end of file

Modified: federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java	2010-11-03 03:29:36 UTC (rev 518)
+++ federation/trunk/picketlink-fed-core/src/test/java/org/picketlink/test/identity/federation/core/parser/saml/SAMLResponseParserTestCase.java	2010-11-03 14:15:54 UTC (rev 519)
@@ -32,6 +32,7 @@
 import org.junit.Test;
 import org.picketlink.identity.federation.core.parsers.saml.SAMLParser;
 import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter;
 import org.picketlink.identity.federation.saml.v2.assertion.AssertionType;
 import org.picketlink.identity.federation.saml.v2.assertion.AuthnStatementType;
 import org.picketlink.identity.federation.saml.v2.protocol.ResponseType;
@@ -89,5 +90,9 @@
       assertEquals( XMLTimeUtil.parse( "2009-05-26T14:06:26.359-05:00" ), authnStatement.getAuthnInstant() );
       authnContextDeclRefJaxb = (JAXBElement<?>) authnStatement.getAuthnContext().getContent().get(0);
       assertEquals( "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", authnContextDeclRefJaxb.getValue() ); 
+      
+      //Let us do some writing - currently only visual inspection. We will do proper validation later.
+      SAMLResponseWriter writer = new SAMLResponseWriter();
+      writer.write(response, System.out );
    }
 }
\ No newline at end of file



More information about the jboss-cvs-commits mailing list