How to use Secure Properties in DataWeave 2


Mule 4 ships with a Secure Configuration Properties Module that can be used to encrypt properties files or individual properties. In this quick note, we will see how to use Secure properties inside DataWeave 2 or in Mule 4 expression statements.

Getting Started: If you need to see how to configure your Mule project to use the Secure Configuration Properties Module, and Encrypt Properties, I recommend you read the documentation here.
Secure Configuration Properties Module is Enterprise Only feature. See this for how to configure Mule Enterprise Maven Repository access.

Once you have Secure Properties configured, you can read secure properties inside your xml configuration by prefixing secure:: namespace before the property name.

<global-property name="prop" value="my-${secure::property.key1}"/>

<flow name="demo">
    <set-payload value="${secure::encrypted.key}"/>
</flow>

What about using it in DataWeave 2?

If you have used properties in DataWeave 1, you would know about a special function p(prop_name) that can be used inside DataWeave 1 script to read properties. The same function is available in Mule 4 and DataWeave 2.

Using in Expression:

<global-property name="prop" value="#[p('secure::encrypted.key')]"/>

Using in DataWeave 2.0:

%dw 2.0
output application/java
---
{
	password: p('secure::encrypted.key')
}

That was easy, right!

on twitter to get updates on new posts.

Stay updated!

On this blog, I post articles about different technologies like Java, MuleSoft, and much more.

You can get updates for new Posts in your email by subscribing to JavaStreets feed here -


Lives on Java Planet, Walks on Java Streets, Read/Writes in Java, JCP member, Jakarta EE enthusiast, MuleSoft Integration Architect, MuleSoft Community Ambassador, Open Source Contributor and Supporter, also writes at Unit Testers, A Family man!