[picketlink-commits] Picketlink SVN: r1007 - in federation/trunk: picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust and 1 other directory.
picketlink-commits at lists.jboss.org
picketlink-commits at lists.jboss.org
Fri Jun 17 14:29:58 EDT 2011
Author: anil.saldhana at jboss.com
Date: 2011-06-17 14:29:57 -0400 (Fri, 17 Jun 2011)
New Revision: 1007
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/wstrust/STSClient.java
Log:
use soapmessage
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-16 20:55:45 UTC (rev 1006)
+++ federation/trunk/picketlink-bindings-jboss/src/main/java/org/picketlink/identity/federation/bindings/jboss/auth/SAML2STSLoginModule.java 2011-06-17 18:29:57 UTC (rev 1007)
@@ -40,7 +40,7 @@
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.transform.Source;
+import javax.xml.soap.SOAPMessage;
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<Source> dispatch = client.getDispatch();
+ Dispatch<SOAPMessage> 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/wstrust/STSClient.java
===================================================================
--- federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/STSClient.java 2011-06-16 20:55:45 UTC (rev 1006)
+++ federation/trunk/picketlink-fed-core/src/main/java/org/picketlink/identity/federation/core/wstrust/STSClient.java 2011-06-17 18:29:57 UTC (rev 1007)
@@ -17,6 +17,7 @@
*/
package org.picketlink.identity.federation.core.wstrust;
+import java.io.InputStream;
import java.net.URI;
import java.security.Principal;
import java.util.Map;
@@ -24,6 +25,8 @@
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;
@@ -36,6 +39,7 @@
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;
@@ -58,7 +62,7 @@
*/
public class STSClient
{
- private final ThreadLocal<Dispatch<Source>> dispatchLocal = new InheritableThreadLocal<Dispatch<Source>>();
+ private final ThreadLocal<Dispatch<SOAPMessage>> dispatchLocal = new InheritableThreadLocal<Dispatch<SOAPMessage>>();
private final String targetNS = "http://org.picketlink.trust/sts/";
@@ -101,7 +105,7 @@
Service jaxwsService = Service.create(service);
jaxwsService.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, config.getEndPointAddress());
- Dispatch<Source> dispatch = jaxwsService.createDispatch(portName, Source.class, Mode.PAYLOAD);
+ Dispatch<SOAPMessage> dispatch = jaxwsService.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
Map<String, Object> reqContext = dispatch.getRequestContext();
String username = config.getUsername();
@@ -118,7 +122,7 @@
* Set the {@link Dispatch} object for use
* @param dispatch
*/
- public void setDispatch(Dispatch<Source> dispatch)
+ public void setDispatch(Dispatch<SOAPMessage> dispatch)
{
if (dispatch == null)
throw new IllegalArgumentException("dispatch is null");
@@ -281,12 +285,22 @@
validateDispatch();
DOMSource requestSource = this.createSourceFromRequest(request);
- Source response = dispatchLocal.get().invoke(requestSource);
+ 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);
NodeList nodes;
try
{
- Node documentNode = DocumentUtil.getNodeFromSource(response);
+ Node documentNode = SOAPUtil.getSOAPData(responseMessage);
Document responseDoc = documentNode instanceof Document ? (Document) documentNode : documentNode
.getOwnerDocument();
@@ -342,12 +356,12 @@
// send the token request to JBoss STS and get the response.
DOMSource requestSource = this.createSourceFromRequest(request);
- Source response = dispatchLocal.get().invoke(requestSource);
+ SOAPMessage responseMessage = dispatchLocal.get().invoke(createSOAPMessage(requestSource));
NodeList nodes;
try
{
- Node documentNode = DocumentUtil.getNodeFromSource(response);
+ Node documentNode = SOAPUtil.getSOAPData(responseMessage);
Document responseDoc = documentNode instanceof Document ? (Document) documentNode : documentNode
.getOwnerDocument();
@@ -402,11 +416,12 @@
DOMSource requestSource = this.createSourceFromRequest(request);
- Source response = dispatchLocal.get().invoke(requestSource);
+ SOAPMessage responseMessage = dispatchLocal.get().invoke(createSOAPMessage(requestSource));
try
{
+ InputStream stream = DocumentUtil.getNodeAsStream(SOAPUtil.getSOAPData(responseMessage));
RequestSecurityTokenResponseCollection responseCollection = (RequestSecurityTokenResponseCollection) new WSTrustParser()
- .parse(DocumentUtil.getSourceAsStream(response));
+ .parse(stream);
RequestSecurityTokenResponse tokenResponse = responseCollection.getRequestSecurityTokenResponses().get(0);
StatusType status = tokenResponse.getStatus();
@@ -446,13 +461,14 @@
request.setContext("context");
DOMSource requestSource = this.createSourceFromRequest(request);
- Source response = dispatchLocal.get().invoke(requestSource);
+ SOAPMessage responseMessage = dispatchLocal.get().invoke(createSOAPMessage(requestSource));
// get the WS-Trust response and check for presence of the RequestTokenCanceled element.
try
{
+ InputStream stream = DocumentUtil.getNodeAsStream(SOAPUtil.getSOAPData(responseMessage));
RequestSecurityTokenResponseCollection responseCollection = (RequestSecurityTokenResponseCollection) new WSTrustParser()
- .parse(DocumentUtil.getSourceAsStream(response));
+ .parse(stream);
RequestSecurityTokenResponse tokenResponse = responseCollection.getRequestSecurityTokenResponses().get(0);
if (tokenResponse.getRequestedTokenCancelled() != null)
return true;
@@ -468,7 +484,7 @@
* Get the dispatch object
* @return
*/
- public Dispatch<Source> getDispatch()
+ public Dispatch<SOAPMessage> getDispatch()
{
return dispatchLocal.get();
}
@@ -496,4 +512,18 @@
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);
+ }
+ }
}
More information about the picketlink-commits
mailing list