[picketlink-commits] Picketlink SVN: r1012 - in federation/trunk: picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util and 1 other directories.

picketlink-commits at lists.jboss.org picketlink-commits at lists.jboss.org
Fri Jun 17 16:17:10 EDT 2011


Author: anil.saldhana at jboss.com
Date: 2011-06-17 16:17:09 -0400 (Fri, 17 Jun 2011)
New Revision: 1012

Modified:
   federation/trunk/picketlink-bindings-jboss/src/main/java/org/picketlink/identity/federation/bindings/jboss/auth/SAML2STSLoginModule.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SOAPUtil.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java
   federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/STSClient.java
Log:
revert back to use Source rather than SOAPMessage on the client side for Dispatch

Modified: federation/trunk/picketlink-bindings-jboss/src/main/java/org/picketlink/identity/federation/bindings/jboss/auth/SAML2STSLoginModule.java
===================================================================
--- federation/trunk/picketlink-bindings-jboss/src/main/java/org/picketlink/identity/federation/bindings/jboss/auth/SAML2STSLoginModule.java	2011-06-17 20:11:43 UTC (rev 1011)
+++ federation/trunk/picketlink-bindings-jboss/src/main/java/org/picketlink/identity/federation/bindings/jboss/auth/SAML2STSLoginModule.java	2011-06-17 20:17:09 UTC (rev 1012)
@@ -40,7 +40,7 @@
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.login.LoginException;
 import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.Source;
 import javax.xml.ws.Dispatch;
 
 import org.apache.log4j.Logger;
@@ -506,7 +506,7 @@
       // to the STS and set them in the Dispatch request context.
       if (!this.options.isEmpty())
       {
-         Dispatch<SOAPMessage> dispatch = client.getDispatch();
+         Dispatch<Source> dispatch = client.getDispatch();
          for (Map.Entry<String, ?> entry : this.options.entrySet())
             dispatch.getRequestContext().put(entry.getKey(), entry.getValue());
       }

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SOAPUtil.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SOAPUtil.java	2011-06-17 20:11:43 UTC (rev 1011)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/util/SOAPUtil.java	2011-06-17 20:17:09 UTC (rev 1012)
@@ -34,7 +34,7 @@
 import javax.xml.transform.Source;
 
 import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
-import org.w3c.dom.Node;
+import org.w3c.dom.Document;
 
 /**
  * Utility class dealing with SAAJ
@@ -43,6 +43,11 @@
  */
 public class SOAPUtil
 {
+   /**
+    * Create an empty {@link SOAPMessage}
+    * @return
+    * @throws SOAPException
+    */
    public static SOAPMessage create() throws SOAPException
    {
       MessageFactory messageFactory = MessageFactory.newInstance();
@@ -51,12 +56,25 @@
       return soapMessage;
    }
 
+   /**
+    * Given a stream of {@link SOAPMessage}, construct the {@link SOAPMessage}
+    * @param is
+    * @return
+    * @throws IOException
+    * @throws SOAPException
+    */
    public static SOAPMessage getSOAPMessage(InputStream is) throws IOException, SOAPException
    {
       MessageFactory messageFactory = MessageFactory.newInstance();
       return messageFactory.createMessage(null, is);
    }
 
+   /**
+    * Given a string message, create a {@link SOAPFault}
+    * @param message
+    * @return
+    * @throws SOAPException
+    */
    public static SOAPMessage createFault(String message) throws SOAPException
    {
       MessageFactory messageFactory = MessageFactory.newInstance();
@@ -70,11 +88,23 @@
       return msg;
    }
 
-   public static Node getSOAPData(SOAPMessage soapMessage) throws SOAPException
+   /**
+    * Given a {@link SOAPMessage}, get the content as a {@link Document}
+    * @param soapMessage
+    * @return
+    * @throws SOAPException
+    */
+   public static Document getSOAPData(SOAPMessage soapMessage) throws SOAPException
    {
-      return soapMessage.getSOAPBody().getFirstChild();
+      return soapMessage.getSOAPBody().extractContentAsDocument();
    }
 
+   /**
+    * Add content to {@link SOAPMessage}
+    * @param data
+    * @param soapMessage
+    * @throws SOAPException
+    */
    public static void addData(Source data, SOAPMessage soapMessage) throws SOAPException
    {
       try

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java	2011-06-17 20:11:43 UTC (rev 1011)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/PicketLinkSTS.java	2011-06-17 20:17:09 UTC (rev 1012)
@@ -122,18 +122,16 @@
       {
          throw new WebServiceException(e);
       }
-      Document document;
+      Node payLoad;
       BaseRequestSecurityToken baseRequest;
       try
       {
-         Node payLoad = request.getSOAPBody().getFirstChild();
-         document = DocumentUtil.createDocument();
-         payLoad = document.importNode(payLoad, true);
-         document.appendChild(payLoad);
+         payLoad = SOAPUtil.getSOAPData(request);
 
          WSTrustParser parser = new WSTrustParser();
 
-         baseRequest = (BaseRequestSecurityToken) parser.parse(DocumentUtil.getNodeAsStream(document));
+         System.out.println(DocumentUtil.getNodeAsString(payLoad));
+         baseRequest = (BaseRequestSecurityToken) parser.parse(DocumentUtil.getNodeAsStream(payLoad));
       }
       catch (Exception e)
       {
@@ -143,7 +141,15 @@
       if (baseRequest instanceof RequestSecurityToken)
       {
          RequestSecurityToken req = (RequestSecurityToken) baseRequest;
-         req.setRSTDocument(document);
+         try
+         {
+            req.setRSTDocument((Document) payLoad);
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+
          if (valueType != null)
          {
             req.setBinaryValueType(URI.create(valueType));
@@ -194,13 +200,14 @@
     * 
     * @see org.picketlink.identity.federation.core.wstrust.SecurityTokenService#invoke(javax.xml.transform.Source)
     */
-   public Source invoke(Source request)
+   /*public Source invoke(Source request)
    {
       BaseRequestSecurityToken baseRequest;
       Document document;
       try
       {
          document = (Document) DocumentUtil.getNodeFromSource(request);
+         System.out.println(DocumentUtil.asString(document));
          baseRequest = (BaseRequestSecurityToken) new WSTrustParser().parse(DocumentUtil.getSourceAsStream(request));
       }
       catch (Exception e)
@@ -218,7 +225,7 @@
          return this.handleTokenRequestCollection((RequestSecurityTokenCollection) baseRequest);
       else
          throw new WebServiceException("Invalid security token request");
-   }
+   }*/
 
    /**
     * <p>

Modified: federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/STSClient.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/STSClient.java	2011-06-17 20:11:43 UTC (rev 1011)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/STSClient.java	2011-06-17 20:17:09 UTC (rev 1012)
@@ -25,8 +25,6 @@
 import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMResult;
@@ -39,7 +37,6 @@
 
 import org.picketlink.identity.federation.core.parsers.wst.WSTrustParser;
 import org.picketlink.identity.federation.core.saml.v2.util.DocumentUtil;
-import org.picketlink.identity.federation.core.util.SOAPUtil;
 import org.picketlink.identity.federation.core.util.StringUtil;
 import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityToken;
 import org.picketlink.identity.federation.core.wstrust.wrappers.RequestSecurityTokenResponse;
@@ -62,7 +59,7 @@
  */
 public class STSClient
 {
-   private final ThreadLocal<Dispatch<SOAPMessage>> dispatchLocal = new InheritableThreadLocal<Dispatch<SOAPMessage>>();
+   private final ThreadLocal<Dispatch<Source>> dispatchLocal = new InheritableThreadLocal<Dispatch<Source>>();
 
    private final String targetNS = "http://org.picketlink.trust/sts/";
 
@@ -105,7 +102,7 @@
 
       Service jaxwsService = Service.create(service);
       jaxwsService.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, config.getEndPointAddress());
-      Dispatch<SOAPMessage> dispatch = jaxwsService.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
+      Dispatch<Source> dispatch = jaxwsService.createDispatch(portName, Source.class, Mode.PAYLOAD);
 
       Map<String, Object> reqContext = dispatch.getRequestContext();
       String username = config.getUsername();
@@ -122,7 +119,7 @@
     * Set the {@link Dispatch} object for use
     * @param dispatch
     */
-   public void setDispatch(Dispatch<SOAPMessage> dispatch)
+   public void setDispatch(Dispatch<Source> dispatch)
    {
       if (dispatch == null)
          throw new IllegalArgumentException("dispatch is null");
@@ -285,22 +282,13 @@
 
       validateDispatch();
       DOMSource requestSource = this.createSourceFromRequest(request);
-      SOAPMessage requestMessage;
-      try
-      {
-         requestMessage = SOAPUtil.create();
-         SOAPUtil.addData(requestSource, requestMessage);
-      }
-      catch (SOAPException e1)
-      {
-         throw new WSTrustException("Unable to create SOAP Message:", e1);
-      }
-      SOAPMessage responseMessage = dispatchLocal.get().invoke(requestMessage);
+      Source response = dispatchLocal.get().invoke(requestSource);
 
       NodeList nodes;
       try
       {
-         Node documentNode = SOAPUtil.getSOAPData(responseMessage);
+         Node documentNode = DocumentUtil.getNodeFromSource(response);
+
          Document responseDoc = documentNode instanceof Document ? (Document) documentNode : documentNode
                .getOwnerDocument();
 
@@ -331,6 +319,8 @@
          throw new WSTrustException("NodeList is null");
 
       Node rstr = nodes.item(0);
+      if (rstr == null)
+         throw new WSTrustException("Have not found RSTR in the payload");
 
       return (Element) rstr.getFirstChild();
    }
@@ -356,12 +346,11 @@
 
       // send the token request to JBoss STS and get the response.
       DOMSource requestSource = this.createSourceFromRequest(request);
-      SOAPMessage responseMessage = dispatchLocal.get().invoke(createSOAPMessage(requestSource));
-
+      Source response = dispatchLocal.get().invoke(requestSource);
       NodeList nodes;
       try
       {
-         Node documentNode = SOAPUtil.getSOAPData(responseMessage);
+         Node documentNode = DocumentUtil.getNodeFromSource(response);
          Document responseDoc = documentNode instanceof Document ? (Document) documentNode : documentNode
                .getOwnerDocument();
 
@@ -416,10 +405,10 @@
 
       DOMSource requestSource = this.createSourceFromRequest(request);
 
-      SOAPMessage responseMessage = dispatchLocal.get().invoke(createSOAPMessage(requestSource));
+      Source response = dispatchLocal.get().invoke(requestSource);
       try
       {
-         InputStream stream = DocumentUtil.getNodeAsStream(SOAPUtil.getSOAPData(responseMessage));
+         InputStream stream = DocumentUtil.getNodeAsStream(DocumentUtil.getNodeFromSource(response));
          RequestSecurityTokenResponseCollection responseCollection = (RequestSecurityTokenResponseCollection) new WSTrustParser()
                .parse(stream);
          RequestSecurityTokenResponse tokenResponse = responseCollection.getRequestSecurityTokenResponses().get(0);
@@ -461,12 +450,11 @@
       request.setContext("context");
 
       DOMSource requestSource = this.createSourceFromRequest(request);
-      SOAPMessage responseMessage = dispatchLocal.get().invoke(createSOAPMessage(requestSource));
-
+      Source response = dispatchLocal.get().invoke(requestSource);
       // get the WS-Trust response and check for presence of the RequestTokenCanceled element.
       try
       {
-         InputStream stream = DocumentUtil.getNodeAsStream(SOAPUtil.getSOAPData(responseMessage));
+         InputStream stream = DocumentUtil.getNodeAsStream(DocumentUtil.getNodeFromSource(response));
          RequestSecurityTokenResponseCollection responseCollection = (RequestSecurityTokenResponseCollection) new WSTrustParser()
                .parse(stream);
          RequestSecurityTokenResponse tokenResponse = responseCollection.getRequestSecurityTokenResponses().get(0);
@@ -484,7 +472,7 @@
     * Get the dispatch object
     * @return
     */
-   public Dispatch<SOAPMessage> getDispatch()
+   public Dispatch<Source> getDispatch()
    {
       return dispatchLocal.get();
    }
@@ -512,18 +500,4 @@
       if (getDispatch() == null)
          throw new RuntimeException("Dispatch has not been set");
    }
-
-   private SOAPMessage createSOAPMessage(Source source)
-   {
-      try
-      {
-         SOAPMessage soap = SOAPUtil.create();
-         SOAPUtil.addData(source, soap);
-         return soap;
-      }
-      catch (SOAPException e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-}
+}
\ No newline at end of file



More information about the picketlink-commits mailing list