[jboss-cvs] Picketlink SVN: r528 - in federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2: response and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 4 12:50:19 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-11-04 12:50:18 -0400 (Thu, 04 Nov 2010)
New Revision: 528

Modified:
   federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/request/SAML2Request.java
   federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/response/SAML2Response.java
Log:
stax parsing and writing

Modified: federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/request/SAML2Request.java
===================================================================
--- federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/request/SAML2Request.java	2010-11-04 16:49:46 UTC (rev 527)
+++ federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/request/SAML2Request.java	2010-11-04 16:50:18 UTC (rev 528)
@@ -21,6 +21,7 @@
  */
 package org.picketlink.identity.federation.api.saml.v2.request;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -38,13 +39,16 @@
 import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
 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.v2.common.IDGenerator;
 import org.picketlink.identity.federation.core.saml.v2.common.SAMLDocumentHolder;
+import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
 import org.picketlink.identity.federation.core.saml.v2.factories.JBossSAMLAuthnRequestFactory;
 import org.picketlink.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
 import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
 import org.picketlink.identity.federation.core.saml.v2.util.JAXBElementMappingUtil;
 import org.picketlink.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLRequestWriter;
 import org.picketlink.identity.federation.core.util.JAXBUtil;
 import org.picketlink.identity.federation.saml.v2.SAML2Object;
 import org.picketlink.identity.federation.saml.v2.assertion.NameIDType;
@@ -119,8 +123,7 @@
     * @return
     * @throws IOException
     * @throws ParsingException
-    */
-   @SuppressWarnings("unchecked")
+    */ 
    public SAML2Object getSAML2ObjectFromStream(InputStream is) 
    throws  ConfigurationException, ParsingException,
    ProcessingException
@@ -130,18 +133,22 @@
       
       Document samlDocument =  DocumentUtil.getDocument(is); 
  
-      try
-      {
-         Binder<Node> binder = getBinder();
+      /*try
+      {*/
+         /*Binder<Node> binder = getBinder();
          JAXBElement<SAML2Object> jaxbAuthnRequestType = (JAXBElement<SAML2Object>) binder.unmarshal(samlDocument);
-         SAML2Object requestType = jaxbAuthnRequestType.getValue();
+         SAML2Object requestType = jaxbAuthnRequestType.getValue();*/
+         
+         SAMLParser samlParser = new SAMLParser();
+         SAML2Object requestType = (SAML2Object) samlParser.parse( DocumentUtil.getNodeAsStream( samlDocument ));
+         
          samlDocumentHolder = new SAMLDocumentHolder(requestType, samlDocument);
          return requestType;
-      }
+      /*}
       catch (JAXBException e)
       {
          throw new ParsingException(e);
-      }
+      }*/
    }
    
    /**
@@ -220,6 +227,7 @@
       LogoutRequestType lrt = of.createLogoutRequestType();
       lrt.setID(IDGenerator.create("ID_"));
       lrt.setIssueInstant(XMLTimeUtil.getIssueInstant());
+      lrt.setVersion( JBossSAMLConstants.VERSION_2_0.get() ); 
       
       //Create an issuer 
       NameIDType issuerNameID = JBossSAMLBaseFactory.createNameID();
@@ -275,20 +283,36 @@
     * Return the DOM object
     * @param rat
     * @return
-    * @throws SAXException
-    * @throws IOException
-    * @throws JAXBException
-    * @throws ParserConfigurationException
+    * @throws ProcessingException 
+    * @throws ParsingException 
+    * @throws ConfigurationException 
     */
+   /*public Document convert(RequestAbstractType rat) 
+   throws SAXException, IOException, JAXBException, ConfigurationException */
+   
    public Document convert(RequestAbstractType rat) 
-   throws SAXException, IOException, JAXBException, ConfigurationException 
+   throws ProcessingException, ConfigurationException, ParsingException 
    {
-      JAXBContext jaxb = JAXBUtil.getJAXBContext(RequestAbstractType.class);
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+      
+      SAMLRequestWriter writer = new SAMLRequestWriter();
+      if( rat instanceof AuthnRequestType )
+      {
+         writer.write( (AuthnRequestType) rat, bos);
+      } 
+      else if( rat instanceof LogoutRequestType )
+      {
+         writer.write( (LogoutRequestType) rat, bos);
+      }
+      
+      return DocumentUtil.getDocument( new String( bos.toByteArray() )); 
+         
+      /*JAXBContext jaxb = JAXBUtil.getJAXBContext(RequestAbstractType.class);
       Binder<Node> binder = jaxb.createBinder();
       
       Document doc = DocumentUtil.createDocument();
       binder.marshal(JAXBElementMappingUtil.get(rat), doc);
-      return doc; 
+      return doc;*/ 
    }
    
    /**

Modified: federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/response/SAML2Response.java
===================================================================
--- federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/response/SAML2Response.java	2010-11-04 16:49:46 UTC (rev 527)
+++ federation/trunk/picketlink-fed-api/src/main/java/org/picketlink/identity/federation/api/saml/v2/response/SAML2Response.java	2010-11-04 16:50:18 UTC (rev 528)
@@ -21,6 +21,11 @@
  */
 package org.picketlink.identity.federation.api.saml.v2.response;
 
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLConstants.LOGOUT_RESPONSE;
+import static org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants.PROTOCOL_NSURI;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Writer;
@@ -33,12 +38,14 @@
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.picketlink.identity.federation.core.constants.PicketLinkFederationConstants;
 import org.picketlink.identity.federation.core.exceptions.ConfigurationException;
 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.v2.common.SAMLDocumentHolder;
 import org.picketlink.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
 import org.picketlink.identity.federation.core.saml.v2.exceptions.IssueInstantMissingException;
@@ -51,6 +58,7 @@
 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.JAXBElementMappingUtil;
+import org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter;
 import org.picketlink.identity.federation.core.util.JAXBUtil;
 import org.picketlink.identity.federation.saml.v2.SAML2Object;
 import org.picketlink.identity.federation.saml.v2.assertion.ActionType;
@@ -270,8 +278,7 @@
     * @throws ParsingException 
     * @throws ConfigurationException 
     * @throws ProcessingException 
-    */
-   @SuppressWarnings("unchecked")
+    */ 
    public SAML2Object getSAML2ObjectFromStream(InputStream is) throws ParsingException, ConfigurationException, ProcessingException
    {
       if(is == null)
@@ -279,18 +286,25 @@
       
       Document samlResponseDocument = DocumentUtil.getDocument(is); 
       
+      System.out.println( "RESPONSE=" + DocumentUtil.asString(samlResponseDocument));
+      /*
       try
       {
          Binder<Node> binder = getBinder();
          JAXBElement<SAML2Object> saml2Object = (JAXBElement<SAML2Object>) binder.unmarshal(samlResponseDocument);
          SAML2Object responseType = saml2Object.getValue();
+         */
+         SAMLParser samlParser = new SAMLParser();
+         SAML2Object responseType =  (SAML2Object) samlParser.parse( DocumentUtil.getNodeAsStream( samlResponseDocument ));
+         
          samlDocumentHolder = new SAMLDocumentHolder(responseType, samlResponseDocument);
          return responseType;
+      /*   
       }
       catch (JAXBException e)
       {
          throw new ParsingException(e);
-      }  
+      } */ 
    }
    
    /**
@@ -326,17 +340,40 @@
     * Convert a SAML2 Response into a Document
     * @param responseType
     * @return
+    * @throws ParsingException 
+    * @throws ConfigurationException 
     * @throws JAXBException
     * @throws ParserConfigurationException
-    */
-   public Document convert(StatusResponseType responseType) throws JAXBException, ConfigurationException 
+    *//*
+   public Document convert(StatusResponseType responseType) throws JAXBException, ConfigurationException*/
+   
+
+   public Document convert(StatusResponseType responseType) throws ProcessingException, ConfigurationException, ParsingException
    {
-      JAXBContext jaxb = JAXBUtil.getJAXBContext(StatusResponseType.class);
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+      SAMLResponseWriter writer = new SAMLResponseWriter();
+      
+      if( responseType instanceof ResponseType )
+      {
+         ResponseType response = (ResponseType) responseType;
+         writer.write(response, bos );
+      }
+      else
+      {
+         writer.write(responseType, new QName( PROTOCOL_NSURI.get(), LOGOUT_RESPONSE.get(), "samlp"), bos );
+      }
+      
+      //System.out.println( new String( bos.toByteArray() ) );
+      return DocumentUtil.getDocument( new ByteArrayInputStream( bos.toByteArray() ));
+            
+      /*JAXBContext jaxb = JAXBUtil.getJAXBContext(StatusResponseType.class);
+             * 
       Binder<Node> binder = jaxb.createBinder();
 
       Document responseDocument = DocumentUtil.createDocument();
       binder.marshal(JAXBElementMappingUtil.get(responseType), responseDocument);
-      return responseDocument; 
+      return responseDocument; */
    }
    
    /**



More information about the jboss-cvs-commits mailing list