Creating an Excel output is quite common in MuleSoft. But sometime we need to assign a password protection to the excel sheet. In this post, I am going to explain how to achieve this in Mulesoft.
Table of Contents
What is the Problem?
MuleSoft provides a way to transform the output to css or excel but how to make an excel file Password Protected.
Solution
Remember to store sensitive information, we password protect excel sheet. So how do we create a password protected file. There is no inbuilt option in MuleSoft. There are various ways but I am going to suggest using Java class to achieve this.
We are going to use Apache POI to access, create excel sheet and then protect it with a password.
We will create a Java class for it. Remember once you protect an excel file with password, you cannot get the original payload using MuleSoft without decrypting it back.
What is Apache POI
Apache POI, a project run by the Apache Software Foundation, and previously a sub-project of the Jakarta Project, provides pure Java libraries for reading and writing files in Microsoft Office formats, such as Word, PowerPoint and Excel
Click Here To Know More
List Of Steps
Use Transform to get excel file content in payload
Add Apache POI dependency in pom
Create Java class, get payload in stream
Add encryptor method to password protect file with given password
References
https://poi.apache.org
https://docs.mulesoft.com/general/
Code
Download Complete code from here
BonusTips
If you are using Cloudhub, you may use /tmp location to store unprotected file temporarily or if on premise, select folder path from local file system.
Ravi Singh
I am an MuleSoft Architect by Profession and a blogger. I love to write blogs, Youtube, content creator, meetup speaker, host and conduct tech talks. I love to travel, make new friends and here to help the community. Connect with me to learn more.