logback-access-spring-boot-starter
logback-access-spring-boot-starter copied to clipboard
Hashing remote user
Question
Is there a way to hash the remote user that gets logged?
There used to be LogbackAccessSecurityAttributesSaveFilter which enabled to override the doFilter() function, but it has been removed in the newer version of this starter.
Went for a hack like this:
@Component
public class FilterConfiguration {
@Bean
@NotNull
public FilterRegistrationBean<LogbackAccessSecurityServletFilter> logbackAccessSecurityServletFilter() {
return new FilterRegistrationBean(new CustomSecurityAttributesSaveFilter());
}
}
public class CustomSecurityAttributesSaveFilter implements Filter {
@NotNull
public static final String REMOTE_USER_ATTRIBUTE = Reflection.getOrCreateKotlinClass(LogbackAccessSecurityServletFilter.class).getQualifiedName() + ".remoteUser";
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
saveSecurityAttributes((HttpServletRequest) request);
chain.doFilter(request, response);
}
private void saveSecurityAttributes(HttpServletRequest request) {
request.setAttribute(REMOTE_USER_ATTRIBUTE, hash(request.getRemoteUser()));
}
}
Is there a reason that LogbackAccessSecurityServletFilter is final? Otherwise I could override the doFilter there and create my own FilterRegistrationBean without any warnings.