I’m working on implementing of lockback in a little spring project. When credentialDTO is passed in login end point, Spring generates a log line with apparent password.
2024-06-27 14:55:37,555 DEBUG [http-nio-8080-exec-1] org.springframework.core.log.LogFormatUtils: Read "application/json;charset=UTF-8" to [CredentialDTO(username=user, password=12345)]
After mapping dto to real entity, the password is encoded and no problem the rest
I thought to avoid this behavior with a patternLayout and wrote a regex like “passwords*=s*(.*?))]” just like in Baeuldung. But i wonder if there may be a better approach i don’t know. Could we manipulate Spring logger directly to hide a field of a object during logging (maybe mark it with annotation) or maybe with an after process to mask the sensitive part? if this log was generated manually by us, i think we could have skipped or masked the marked field in log but in this case, i think there s no possible to do that. i don’t have so much experience about logging with AOP but maybe it be the solution i m looking for. Could we use logging with AOP for this kind of purpose?
Could you give me an advice, an idea would be more efficient, if that is possible?