DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
What's in store for DevOps in 2023? Hear from the experts in our "DZone 2023 Preview: DevOps Edition" on Fri, Jan 27!
Save your seat
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Signing and Validating Soap requests with Mule ESB

Signing and Validating Soap requests with Mule ESB

$$anonymous$$ user avatar by
$$anonymous$$
·
Jan. 28, 13 · Interview
Like (0)
Save
Tweet
Share
5.19K Views

Join the DZone community and get the full member experience.

Join For Free

for months i have been busy implementing a web-service-proxy by using the mule esb ce . although it took some work to get it setup nicely it is working well now. in this post i will show you the result. lets start with the configuration of the incoming request that is signed and has to validated. by the way, i know there is also the webservice-proxy-pattern in mule but i couldn’t use this in combination with the signing/ validating which i needed to do. so here is the flow which validates the incoming soap request:

<flow name="order-status-update">
        <https:inbound-endpoint address="${my.incoming.url}" connector-ref="httpsconnector">
            <cxf:proxy-service>
                <cxf:ininterceptors>
                    <spring:bean class="org.apache.cxf.interceptor.loggingininterceptor" />
                    <spring:bean class="org.apache.cxf.ws.security.wss4j.wss4jininterceptor">
                        <spring:constructor-arg>
                            <spring:map>
                                <spring:entry key="action" value="signature" />
                                <spring:entry key="signaturepropfile" value="ws-validate-security.properties" />
                            </spring:map>
                        </spring:constructor-arg>
                    </spring:bean>
                </cxf:ininterceptors>
            </cxf:proxy-service>
        </https:inbound-endpoint>
        <https:outbound-endpoint address="${my.internal.url}" connector-ref="httpsconnector">
            <cxf:proxy-client />
        </https:outbound-endpoint>
    </flow>

note: please note that the ‘${}’ values are properties read from a property file as described in this article.

as you can see i have defined a cxf proxy with two interceptors: one for logging and one to perform security actions by using the apache wss4j library. i supply two parameters to the wss4jininterceptor:

  • ‘action’: describes which action has to be performed by the interceptor. possible values are ‘signature’, ‘timestamp’, ‘encrypt’ and more.
  • ‘signaturepropfile’: parameter refers to the property file to be used by the interceptor.

the contents of the ‘ws-validate-security.properties’ which is placed on the mule classpath reads the following:

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.file=/usr/local/keystores/mykeystore.jks
org.apache.ws.security.crypto.merlin.keystore.password=mypassword
for more detailed description of these properties and the used technology see this article .
but this is it to have this part configured. i used mule ce 3.2 in this case. the mule config uses the following namespaces:
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
      xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
      xmlns:spring="http://www.springframework.org/schema/beans"
      xmlns:https="http://www.mulesoft.org/schema/mule/https"
      xsi:schemalocation="
        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
        http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/3.2/mule-cxf.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/3.2/mule-https.xsd">
for completeness the used dependencies in the ‘pom.xml’ are the following:
<dependency>
  <groupid>org.mule</groupid>
  <artifactid>mule-core</artifactid>
  <version>3.2.1</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupid>org.mule.modules</groupid>
  <artifactid>mule-module-spring-config</artifactid>
  <version>3.2.1</version>
  <scope>provided</scope>
</dependency> 
<dependency>
  <groupid>org.mule.transports</groupid>
  <artifactid>mule-transport-http</artifactid>
  <version>3.2.1</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupid>org.mule.modules</groupid>
  <artifactid>mule-module-cxf</artifactid>
  <version>3.2.1</version>
  <scope>provided</scope>
</dependency>
and here is the configuration for signing outgoing requests:
<flow name="place-order">
  <https:inbound-endpoint address="${my.internal.url}" connector-ref="httpsconnector" responsetimeout="0">
    <cxf:proxy-service enablemulesoapheaders="false" payload="envelope" />
  </https:inbound-endpoint>
  <https:outbound-endpoint address="${my.outgoing.url}" connector-ref="httpsconnector" responsetimeout="0" >
    <cxf:proxy-client payload="envelope">
      <cxf:outinterceptors>
        <spring:bean class="org.apache.cxf.ws.security.wss4j.wss4joutinterceptor">
          <spring:constructor-arg>
            <spring:map>
              <spring:entry key="action" value="signature" />
              <spring:entry key="user" value="${signature.user}" />
              <spring:entry key="signaturepropfile" value="ws-sign-security.properties" />
              <spring:entry key="passwordcallbackclass" value="net.pascalalma.mykeystorepasswordcallback"/>
              <spring:entry key="signaturekeyidentifier" value="directreference" />
            </spring:map>
          </spring:constructor-arg>
        </spring:bean>
        <spring:bean class="org.apache.cxf.interceptor.loggingoutinterceptor" />
      </cxf:outinterceptors>
    </cxf:proxy-client>
  </https:outbound-endpoint> 
</flow>
the important interceptor here is of course the wss4joutinterceptor . the properties configured here are:
  • ‘action’: describes which action has to be performed by the interceptor
  • ‘user’: the certificate alias in the signature crypto config to sign the message with. the password is retrieved from the callback handler.
  • ‘signaturepropfile’: defines the file name that contains a properties with the desired settings in it.
  • ‘passwordcallbackclass’: the reference to the callback handler for retrieving passwords for private keys in the signature and encryption crypto configurations.
  • ‘signaturekeyidentifier’: signature key attachment method. i want to put the token directly in the header and not use a reference.

the ‘signaturepropfile’ contains the following info:

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.file=/usr/local/keystores/mykeystore.jks
org.apache.ws.security.crypto.merlin.keystore.password=mypassword
as you can see i added the password which is used to open the keystore here in plain text. of course this is not the way to do it in a production system but for development it is quite convenient. i use the mykeystorepasswordcallback to get this password as is shown in the following implementation of this class:
package net.pascalalma;

import java.io.ioexception;
import java.util.resourcebundle;

import javax.security.auth.callback.callback;
import javax.security.auth.callback.callbackhandler;
import javax.security.auth.callback.unsupportedcallbackexception;

import org.apache.ws.security.wspasswordcallback;
/**
 *
 * @author pascal alma
 */
public class mykeystorepasswordcallback implements callbackhandler {

    private static final string bundle_location = "ws-sign-security";
    private static final string password_property_name = "org.apache.ws.security.crypto.merlin.keystore.password";	

    private static string password;
    static {
        final resourcebundle bundle = resourcebundle.getbundle(bundle_location);
        password = bundle.getstring(password_property_name);
    }	

    public void handle(callback[] callbacks) throws ioexception, unsupportedcallbackexception {
        wspasswordcallback pc = (wspasswordcallback) callbacks[0];

        // set the password for our message.
        pc.setpassword(password);
    }
}

this concludes the example of a complete configuration for signing and validating soap requests with the mule esb. although it is not rocket science it took quite some time to get the complete configuration together and working. and there is still room for improvement, mainly for the error handling but i leave that for another time :-)

Enterprise service bus Requests

Published at DZone with permission of $$anonymous$$. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Explainer: Building High Performing Data Product Platform
  • AWS Fargate: Deploying Jakarta EE Applications on Serverless Infrastructures
  • New MacBook Air Beats M1 Max for Java Development
  • How to Configure AWS Glue Job Using Python-Based AWS CDK

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: