最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Zalando logbook obfuscate fields isnt working - Stack Overflow

programmeradmin2浏览0评论

I am trying to use obfuscate mechanism from zalando logbook

Previously i had my own Configuration for this

@Configuration
@EnableConfigurationProperties(LogbookObfuscateJsonBodyProperties.class)
public class LogbookObfuscateJsonBodyConfig {

    @Bean
    public BodyFilter sensitiveDataBodyFilter(LogbookObfuscateJsonBodyProperties properties) {
        if (properties.toObfuscate() == null) {
            return BodyFilter.none();
        }

        return properties.toObfuscate().stream()
                .map(path -> JsonPathBodyFilters.jsonPath(path).replace("XXX"))
                .reduce(BodyFilter::tryMerge)
                .orElse(BodyFilter.none());
    }
}

@ConfigurationProperties(prefix = "app.logbook.json.body")
public record LogbookObfuscateJsonBodyProperties(List<String> toObfuscate) {
}

and i was obfuscating fields in my application.yml files like that

app:
  logbook:
    json:
      body:
        to_obfuscate:
          - .fieldToObfuscate

Right now i wanted to use logbook build in obfuscation so i removed my Configuration and tried with this approach in my application.yml file

logbook:
  obfuscate:
    json-body-fields:
      - .fieldToObfuscate

But it looks like it is not working as i still see fields not obfuscated. Any ideas what might be wrong ?

@Update heres BodyFilter which i used before:

@Bean
    public BodyFilter defaultBodyFilter(LogbookProperties properties) {
        final LogbookProperties.Write write = properties.getWrite();
        final int maxBodySize = write.getMaxBodySize();

        if (maxBodySize < 0) {
            return defaultValue();
        }

        return BodyFilter.merge(defaultValue(), truncate(maxBodySize));
    }
发布评论

评论列表(0)

  1. 暂无评论