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

add Date serializer to mask dates in log #24

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading