Reading Time: 10 minutes

Mule ESB has had support for WS-Security via CXF for some time now, but the enterprise edition of Mule 2.2.4 goes a bit further still with the inclusion of the Mule SAML Module and a new WS-Security example. In this article, I will step through the WS-Security example so that you can see the different possibilities available for incorporating WS-Security into your Mule application. For a good introduction to security and SAML, check out the blog post on the Atos site on Security in the Open Source SOA.

Running the WS-Security example

You will find the new WS-Security example in the directory $MULE_HOME/examples/security, where $MULE_HOME is the path to your installation of Mule 2.2.4 Enterprise. From that directory run ./security (Unix/Linux/Mac) or security.bat (Windows), and once Mule starts up, you should see the following menu:

1. No security
2. UsernameToken
3. UsernameToken with wrong password (error)
4. UsernameToken Signed
5. UsernameToken missing signature (error)
6. UsernameToken Encrypted
7. SAMLToken
8. SAMLToken wrong subject (error)
q. Quit

Each of these options will invoke an instance of the same simple web service, each of which is protected by a different form of security.

All of the configuration files used by the example are in the conf directory (i.e., $MULE_HOME/examples/security/conf). The principle configuration file is called secure-services.xml.

The basic web service we will use without any security whatsoever looks like this in our Mule configuration:

<service name="UnsecureService">
    <component class="" />

Select option #1 from the menu to call this service. We can see the simple SOAP request message sent:

<soap:Envelope xmlns:soap="">
    <ns2:greet xmlns:ns2="">

and the service’s equally simple response message:

latest report
Learn why we are the Leaders in API management and iPaaS
<soap:Envelope xmlns:soap="">
    <ns2:greetResponse xmlns:ns2="">
      <name>Hello Mule</name>


Now let’s add some simple security to the service. We’ll start with a basic Username authentication. For this, we’ll add a WSS4J interceptor to our inbound CXF endpoint:

    <spring:bean class="">
                  <spring:entry key="action" value="UsernameToken Timestamp" />
                  <spring:entry key="passwordCallbackClass"
value="" />

The most important thing we specify on this interceptor is the action, which is the list of features/aspects of WS-Security that we want to validate upon receiving an incoming message. In this case, we specify UsernameToken, which will check the username and password, and Timestamp, which will verify that the message is not too stale. We also specify a password callback so that our password is not stored in the config file itself.

public class PasswordCallback implements CallbackHandler
    public void handle(Callback[] callbacks)  
        if (pc.getIdentifier().equals("joe")) 

Selecting option #2 from the menu will create an appropriate WS-Security header for our SOAP request:

  <wsse:Security xmlns:wsse="
oasis-200401-wss-wssecurity-secext-1.0.xsd" soap:mustUnderstand="1">
    <wsu:Timestamp xmlns:wsu="
oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-2">
    <wsse:UsernameToken xmlns:wsu="
oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">

We can see the Username and Password as well as the Timestamp in the header. Note that the password is in digest form rather than plain text, which is the default behavior.

Now select option #3 to see what happens if the wrong password is provided: The security token could not be 
authenticated or authorized


A more advanced way of authenticating the user is via a digital signature. To validate based on a signature, we’ll need to add a new Signature action to our inbound endpoint:

<spring:entry key="action" value="UsernameToken Signature Timestamp" />
<spring:entry key="signaturePropFile" value="" />

Signatures are validated based on a keystore, so we’ll also need to specify some information about the keystore we’re using. The following properties are in the file:

We can use the Java keytool command to verify that the certificate for user “joe” exists in our keystore:

$ keytool -list -v -keystore ./conf/keystore.jks -alias joe
Enter keystore password:  keyStorePassword

Alias name: joe
Creation date: Sep 24, 2009
Entry type: keyEntry
Certificate chain length: 1
Owner: CN=joe
Issuer: CN=joe
Serial number: 4abb93da
Valid from: Thu Sep 24 11:44:26 CLT 2009 until: Wed Dec 23 12:44:26 CLST 2009
Certificate fingerprints:
 MD5:  24:08:D3:3B:D1:FE:E0:18:6B:12:DC:79:98:EE:62:6D
 SHA1: 25:69:19:52:C9:FE:26:64:F7:C8:F3:BF:E4:9A:5B:71:B4:9E:9F:C3

Note that this certificate is self-signed. In the real world, it would be issued by a trusted third party such as Verisign.

Selecting option #4 from the menu will invoke the web service using a signed SOAP message:

<ds:Signature xmlns:ds=""Id="Signature-2">
<ds:SignedInfo xmlns:ds="">
<ds:CanonicalizationMethod xmlns:ds=""
Algorithm="" />
<ds:SignatureMethod xmlns:ds=""
Algorithm="" />
<ds:Reference xmlns:ds=""URI="#id-3">
<ds:Transforms xmlns:ds="">
<ds:Transform xmlns:ds=""
Algorithm="" />
<ds:DigestMethod xmlns:ds=""
Algorithm="" />
<ds:DigestValue xmlns:ds="">
<ds:SignatureValue xmlns:ds="">
<ds:KeyInfo xmlns:ds="" 
<ds:X509Data xmlns:ds="">
<ds:X509IssuerSerial xmlns:ds="">
<ds:X509IssuerName xmlns:ds="">
<ds:X509SerialNumber xmlns:ds="">

And option #5 shows what happens if we try to send a message that isn’t signed by joe: An error was 
discovered processing the  header


Note that so far, all security information has been contained in the header of the SOAP message, but the body of the message is completely transparent. We can encrypt the body of the message by adding an Encrypt action to our service:

<spring:entry key="action" value="UsernameToken Timestamp Encrypt" />
<spring:entry key="decryptionPropFile" value="" />

Selecting option #6 will send a SOAP message with the body encrypted:

<xenc:EncryptedData xmlns:xenc=""
Id="EncDataId-9" Type="">
<xenc:EncryptionMethod xmlns:xenc=""
Algorithm="" />
<ds:KeyInfo xmlns:ds="">
URI="#EncKeyId-FCBB1376C4DCB7E74C12579575025715" />
<xenc:CipherData xmlns:xenc="">
<xenc:CipherValue xmlns:xenc="">

The message will not be decrypted without the user’s signature, so the keystore is once again used for encryption.


Since SAML is used for Single Sign-On, authentication of the user is assumed to have already occurred, and the SAML Token simply contains one or more subjects, which provide some information understood by other systems. In this case we will configure our service to require a SAML subject of AllowGreetingServices. To our inbound endpoint we add a SAMLVerifyInterceptor with a callback, which will check for the correct SAML subject:

<spring:bean class="org.mule.module.saml.cxf.SAMLVerifyInterceptor">
     <spring:property name="callback">
          <spring:bean class="">
               <spring:property name="subject" value="AllowGreetingServices" />
public class VerifyAuthorization implements SAMLVerifyCallback
    private String subject;
    public SAMLAuthenticationAdapter verify(SAMLAuthenticationAdapter 
samlAuthentication) throws SecurityException
        SAMLSubject samlSubject = samlAuthentication.getSubject();
        if (!samlSubject.getNameIdentifier().getName().equals(subject))
            throw new UnauthorisedException(...cut...

Option #7 adds the expected SAML token to the WS-Security header of the message:

IssueInstant="2009-11-13T02:26:06.569Z" Issuer="self" 
MajorVersion="1" MinorVersion="1">
  <AuthenticationStatement AuthenticationInstant="2009-11-13T02:26:06.569Z" 
        <ConfirmationMethod>urn:oasis:names:tc:<a href="" target="_blank" rel="" title="Mule Enterprise Security" >SAML</a>:1.0:cm:sender-vouches

Selecting option #8 will send a SAML token without the expected subject:

Missing SAML authorization for resource: AllowGreetingServices. 
Message payload is of type: ChunkedInputStream
at org.mule.module.saml.cxf.SAMLVerifyInterceptor.

To verify that the received SAML token is authentic, SAML offers two different modes of trust: Sender Vouches and Holder of Key. In this case, we are using Sender Vouches, which means that the sender of the message must be trusted (e.g., via a digital signature). In Holder of Key mode, the sender of the message does not matter, but the SAML token subject must contain a key from a trusted source (e.g., an X.509 certificate from Verisign).

For more information on SAML, refer to: