riftsaw SVN: r1040 - in trunk: runtime/jbossesb-bpel and 2 other directories.
by riftsaw-commits@lists.jboss.org
Author: objectiser
Date: 2010-10-14 11:08:18 -0400 (Thu, 14 Oct 2010)
New Revision: 1040
Modified:
trunk/pom.xml
trunk/runtime/jbossesb-bpel/pom.xml
trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/internal/soa/esb/actions/bpel/ESBInvocationAdapter.java
trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/soa/esb/actions/bpel/BPELInvoke.java
Log:
RIFTSAW-190 - added support for passing SAML Assertion from ESB application context to a nominated SOAP header part when invoking a BPEL process.
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-14 10:54:42 UTC (rev 1039)
+++ trunk/pom.xml 2010-10-14 15:08:18 UTC (rev 1040)
@@ -99,6 +99,7 @@
<batik.version>1.7</batik.version>
<axiom.version>1.2.8</axiom.version>
<commons.codec.version>1.4</commons.codec.version>
+ <picketlink.version>1.0.3.final</picketlink.version>
</properties>
<dependencyManagement>
Modified: trunk/runtime/jbossesb-bpel/pom.xml
===================================================================
--- trunk/runtime/jbossesb-bpel/pom.xml 2010-10-14 10:54:42 UTC (rev 1039)
+++ trunk/runtime/jbossesb-bpel/pom.xml 2010-10-14 15:08:18 UTC (rev 1040)
@@ -47,6 +47,12 @@
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.picketlink</groupId>
+ <artifactId>picketlink-fed-core</artifactId>
+ <version>${picketlink.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
<finalName>jbossesb-bpel</finalName>
Modified: trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/internal/soa/esb/actions/bpel/ESBInvocationAdapter.java
===================================================================
--- trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/internal/soa/esb/actions/bpel/ESBInvocationAdapter.java 2010-10-14 10:54:42 UTC (rev 1039)
+++ trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/internal/soa/esb/actions/bpel/ESBInvocationAdapter.java 2010-10-14 15:08:18 UTC (rev 1040)
@@ -38,6 +38,7 @@
private String portName;
private QName faultName;
private Element requestXML;
+ private java.util.Map<String,Element> requestHeaderParts;
private Element responseXML;
public ESBInvocationAdapter(String operationName, QName serviceName, String portName)
@@ -75,11 +76,23 @@
this.requestXML = requestXML;
}
+ public void setRequestHeaderParts(java.util.Map<String,Element> headerParts) {
+ this.requestHeaderParts = headerParts;
+ }
+
public void parseRequest(MyRoleMessageExchange mex, Message request)
{
if(null==this.requestXML)
throw new IllegalArgumentException("request XML not set");
request.setMessage(this.requestXML);
+
+ if (requestHeaderParts != null) {
+ for (String part : requestHeaderParts.keySet()) {
+ Element elem=requestHeaderParts.get(part);
+
+ request.setHeaderPart(part, elem);
+ }
+ }
}
public void createResponse(MyRoleMessageExchange mex)
Modified: trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/soa/esb/actions/bpel/BPELInvoke.java
===================================================================
--- trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/soa/esb/actions/bpel/BPELInvoke.java 2010-10-14 10:54:42 UTC (rev 1039)
+++ trunk/runtime/jbossesb-bpel/src/main/java/org/jboss/soa/esb/actions/bpel/BPELInvoke.java 2010-10-14 15:08:18 UTC (rev 1040)
@@ -20,6 +20,8 @@
*/
package org.jboss.soa.esb.actions.bpel;
+import java.security.AccessController;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.internal.soa.esb.actions.bpel.ESBInvocationAdapter;
@@ -30,7 +32,7 @@
import org.jboss.soa.esb.message.format.MessageFactory;
import javax.naming.*;
-import javax.xml.namespace.QName;
+import javax.security.auth.Subject;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
@@ -47,6 +49,7 @@
private static final String TOP_LEVEL_ELEMENT_NAME = "message";
protected static final String REQUEST_PART_NAME = "requestPartName";
+ protected static final String REQUEST_SAML_ASSERTION_PART_NAME = "requestSAMLAssertionPartName";
protected static final String RESPONSE_PART_NAME = "responsePartName";
protected static final String SERVICE = "service";
protected static final String PORT = "port";
@@ -119,24 +122,56 @@
// Create MessagePayloadProxy
MessagePayloadProxy proxy=new MessagePayloadProxy(_config);
+ logger.debug("Request: "+message);
+
+ // Get default body value
+ Object value=proxy.getPayload(message);
+
+ boolean f_toText=(value instanceof String);
+
+ org.w3c.dom.Element mesgElem=createMessageElement(value);
+
+ // Invoke the service
+ String serviceName=_config.getAttribute(SERVICE);
+
+ javax.xml.namespace.QName qname=javax.xml.namespace.QName.valueOf(serviceName);
+
+ logger.debug("Invoking service: "+qname);
+
+ // Create invocationContext
+ ESBInvocationAdapter invocationContext =
+ new ESBInvocationAdapter(_config.getAttribute(OPERATION), qname, _config.getAttribute(PORT));
+ invocationContext.setRequestXML(mesgElem);
+
+ establishHeaderParts(invocationContext);
+
+ // invoke ODE
+ try {
+ engine.invoke(invocationContext);
+ } catch(Throwable t) {
+ // RIFTSAW-177 - prevent ODE specific exceptions being returned to ESB client where
+ // a ClassNotFoundException would be thrown
+ throw new Exception("BPEL invoke failed: "+t);
+ }
+
+ ret = handleResponse(invocationContext.getInvocationResult(),
+ invocationContext.getFaultName(), serviceName, proxy, f_toText);
+
+ return(ret);
+ }
+
+ protected Element createMessageElement(Object value) throws Exception {
+
String requestPartName=_config.getAttribute(REQUEST_PART_NAME);
- logger.debug("Request: "+message);
-
- boolean f_toText=false;
org.w3c.dom.Element mesgElem=null;
-
- // Get default body value
- Object value=proxy.getPayload(message); //message.getBody().get();
Node node=null;
if (value instanceof String) {
// Convert to element
node = getNode((String)value);
-
- // Convert any response to text
- f_toText = true;
+
} else if (value instanceof Node) {
node = (Node)value;
}
@@ -174,32 +209,47 @@
partElem.appendChild(node);
}
- String serviceName=_config.getAttribute(SERVICE);
-
- javax.xml.namespace.QName qname=javax.xml.namespace.QName.valueOf(serviceName);
-
- logger.debug("Invoking service: "+qname);
+ return(mesgElem);
+ }
+
+ protected void establishHeaderParts(ESBInvocationAdapter invocationContext) {
+ String requestSAMLAssertionPartName=_config.getAttribute(REQUEST_SAML_ASSERTION_PART_NAME);
- org.w3c.dom.Element resp=null;
- javax.xml.namespace.QName faultName=null;
-
- // Create invocationContext
- ESBInvocationAdapter invocationContext =
- new ESBInvocationAdapter(_config.getAttribute(OPERATION), qname, _config.getAttribute(PORT));
- invocationContext.setRequestXML(mesgElem);
-
- // invoke ODE
- try {
- engine.invoke(invocationContext);
- } catch(Throwable t) {
- // RIFTSAW-177 - prevent ODE specific exceptions being returned to ESB client where
- // a ClassNotFoundException would be thrown
- throw new Exception("BPEL invoke failed: "+t);
+ if (requestSAMLAssertionPartName != null) {
+
+ // Check if PicketLink SAML creditial is available
+ Subject subject = Subject.getSubject(AccessController.getContext());
+
+ if (subject != null) {
+ org.picketlink.identity.federation.core.wstrust.SamlCredential samlCred=null;
+
+ for (Object cred : subject.getPublicCredentials()) {
+ if (cred instanceof org.picketlink.identity.federation.core.wstrust.SamlCredential) {
+ samlCred = (org.picketlink.identity.federation.core.wstrust.SamlCredential)cred;
+ break;
+ }
+ }
+
+ if (samlCred != null) {
+ try {
+ java.util.Map<String,Element> headerParts=
+ new java.util.HashMap<String, Element>();
+ headerParts.put(requestSAMLAssertionPartName, samlCred.getAssertionAsElement());
+
+ invocationContext.setRequestHeaderParts(headerParts);
+ } catch(Throwable t) {
+ logger.error("Failed to add header parts", t);
+ }
+ }
+ }
}
+ }
+
+ protected Message handleResponse(org.w3c.dom.Element resp, javax.xml.namespace.QName faultName,
+ String serviceName, MessagePayloadProxy proxy, boolean f_toText)
+ throws Exception {
+ Message ret=null;
- resp = invocationContext.getInvocationResult();
- faultName = invocationContext.getFaultName();
-
if (resp != null) {
ret = MessageFactory.getInstance().getMessage();
@@ -290,11 +340,11 @@
} catch(Exception e) {
logger.error("Failed to parse response '"+resp+"'", e);
}
-
- logger.debug("Response: "+ret);
}
- return(ret);
+ logger.debug("Response: "+ret);
+
+ return(ret);
}
/**