Skip to content

Commit

Permalink
add Date serializer to mask dates in log
Browse files Browse the repository at this point in the history
  • Loading branch information
MarjanMehranfar authored Apr 30, 2024
1 parent f45f4d8 commit fd853e5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public SecureParametersConfig secureParametersConfig() {
securedParameters.add(new SecureParameter("age", UserMaskType.LEFT, ComparisonType.EQUALS_IGNORE_CASE));
securedParameters.add(new SecureParameter("average", UserMaskType.RIGHT, ComparisonType.LIKE));
securedParameters.add(new SecureParameter("length", UserMaskType.SEMI, ComparisonType.LIKE));
securedParameters.add(new SecureParameter("date", UserMaskType.COMPLETE));
return new SecureParametersConfig(securedParameters);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tosan.http.server.starter.logger;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

public class DateSerializer extends JsonSerializer<Date> {

private final SerializerUtility serializerUtility;

public DateSerializer(SerializerUtility serializerUtility) {
this.serializerUtility = serializerUtility;
}

@Override
public void serialize(Date value, JsonGenerator jsonGenerator, SerializerProvider serializers) throws IOException {
serializerUtility.serialize(value.toString(), jsonGenerator);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.tosan.http.server.starter.logger.DateSerializer;
import com.tosan.http.server.starter.logger.NumberMaskSerializer;
import com.tosan.http.server.starter.logger.SerializerUtility;
import com.tosan.http.server.starter.logger.StringMaskSerializer;
import com.tosan.tools.mask.starter.replace.JsonReplaceHelperDecider;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author Mostafa Abdollahi
Expand Down Expand Up @@ -42,6 +44,8 @@ private void customizeObjectMapper() {
module.addSerializer(float.class, numberMaskSerializer);
module.addSerializer(double.class, numberMaskSerializer);
module.addSerializer(short.class, numberMaskSerializer);
DateSerializer dateSerializer = new DateSerializer(serializerUtility);
module.addSerializer(Date.class, dateSerializer);
mapper.registerModule(module);
mapper.findAndRegisterModules();
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'H:m:ssZ"));
Expand Down

0 comments on commit fd853e5

Please sign in to comment.