Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JsonValueUnmaskFromEndPatternBuilder #18

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ebay.ejmask.extenstion.builder.json;

import com.ebay.ejmask.extenstion.builder.AbstractRegexPatternBuilder;

/**
* An implementation of IPatternBuilder to support high sensitive JSON field, whose value
* need to be partially masked with relative field from end of the field.
*
* @author ganwu
prasanthkv marked this conversation as resolved.
Show resolved Hide resolved
*/
public class JsonValueUnmaskFromEndPatternBuilder extends AbstractRegexPatternBuilder {
prasanthkv marked this conversation as resolved.
Show resolved Hide resolved

//https://regex101.com/r/LL3EY7/1/
private static final String PATTERN_TEMPLATE = "\\\"(%s)(\\\\*\\\"\\s*:\\s*\\\\*\\\")[^\\\"]*([^\\\\\"]{%d})(\\\\?\\\"|)";
//group $1 = field name
//group $2 = ":" (with json serialization support)
//group $3 = sensitive information -> unmasked
//group $4 = ending qts
private static final String REPLACEMENT_TEMPLATE = "\"$1$2xxxx-$3$4";

/**
* Build pattern to match
*
* @param visibleCharacters as no of characters to be visible.
* @param fieldNames as list of field names
* @return match pattern
*/
@Override
public String buildPattern(int visibleCharacters, String... fieldNames) {
if (visibleCharacters < 0) {
throw new IllegalArgumentException("visibleCharacters must be a value greater than zero instead of " + visibleCharacters);
}
return String.format(PATTERN_TEMPLATE, super.buildFieldNamesForRegexOr(fieldNames), visibleCharacters);
}

/**
* Build pattern to replace.
*
* @param visibleCharacters as no of characters to be visible.
* @param fieldNames as list of field names
* @return match pattern
*/
@Override
public String buildReplacement(int visibleCharacters, String... fieldNames) {
return REPLACEMENT_TEMPLATE;
}
}