【问题标题】:Earliest point to encrypt json payload in spring mvc application在spring mvc应用程序中加密json有效负载的最早点
【发布时间】:2020-01-05 00:48:58
【问题描述】:

我有一个 Spring Boot 应用程序服务于 restful api。

我想确保尽早屏蔽/加密某些字段,以便它们不会在应用程序日志中以明文形式显示...通过 logback。

是否有我可以实现的入口点/过滤器/冲刺方面来实现这一点?

【问题讨论】:

    标签: spring-boot spring-data-jpa obfuscation masking spring-logback


    【解决方案1】:

    正如Ali Dehghani 在这个post 的答案中所清楚解释的那样,做你想做的事情的最佳位置是在响应过滤器中。因此,您必须编写一个实现 Filter 接口的类,并在 doFilter 方法中过滤您的响应。

    @Component
    public class YourResponseFilter implements Filter {
     
      @Override
      public void doFilter(
        ServletRequest request, 
        ServletResponse response, 
        FilterChain chain) throws IOException, ServletException {
        ...
        // do your work there
      }
    }
    

    您可能会或可能不会使用 @Component 对过滤器进行注释,具体取决于您是否要过滤所有响应。 如果您需要更多帮助,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 2016-03-12
      • 2015-02-14
      • 1970-01-01
      • 2017-05-04
      • 2021-12-08
      相关资源
      最近更新 更多