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 ebdb788 commit d73dc04
Show file tree
Hide file tree
Showing 3 changed files with 26 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 @@ -11,6 +11,7 @@
import org.springframework.web.multipart.MultipartFile;

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

/**
* @author Mostafa Abdollahi
Expand Down Expand Up @@ -43,6 +44,8 @@ private void customizeObjectMapper() {
module.addSerializer(double.class, numberMaskSerializer);
module.addSerializer(short.class, numberMaskSerializer);
module.addSerializer(byte[].class, new ByteArraySerializer());
DateSerializer dateSerializer = new DateSerializer(serializerUtility);
module.addSerializer(Date.class, dateSerializer);
module.addSerializer(MultipartFile.class, multipartMaskSerializer);
mapper.registerModule(module);
mapper.findAndRegisterModules();
Expand Down

0 comments on commit d73dc04

Please sign in to comment.