Data Masking using class mediator

In my previous post I have explained about how we can use xslt mediator for data masking. dis advantage of that is we need to use multiple xslt and to hold the key also we need use xslt file. also when considering performance it would not recommended. other thing is if you need to mask complex json that method will not support.
with this post I am going to explain data mask using class mediator. also in this method we can mask any of bellow

  • key
  • array
  • object

also in this method it will mask from anywhere in the payload and you can specify path to the object or array you want to mask. that can be configure using json file.

create maven multi module project with

  • ESB config
  • Registery
  • Mediator
  • composite application

if you are not familiar to create that type of project in developer studio you can refer blow my youtube video.

in a class mediator pom file you need to add bellow dependancies.

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.21</version>
		</dependency>
		<dependency>
			<groupId>org.json.wso2</groupId>
			<artifactId>json</artifactId>
			<version>2.0.0.wso2v1</version>
		</dependency>

those are also comes with ESB itself also. so you can add those configuring build path OR add to pom file as above.
after modifying the pom file if those libraries available to import in java code, go to mediator project root directory from and run below command

mvn eclipse:eclipse

update your class mediator as below.


create sequence as follows

create API

add keysToBeMask.json file to registry (make sure the path referred in sequence)

{
"keysToBeMasked":["account.ssn","account.contact.mobile","account.onlineAccount.accountNumbers","account.branch"]
}

now all set. deploy this into ESB and send bellow request

you will get a response like this

you can see array , object , key not matter what. everything masked as per the source json file

you can find this project in gitHub in this link https://github.com/krishantha/code-samples/tree/master/wso2Esb-datamask-classmediator

Share this on your world...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someonePrint this page

Leave a Reply