UserFilter.java

  1. package no.nav.data.common.web;

  2. import jakarta.servlet.FilterChain;
  3. import jakarta.servlet.ServletException;
  4. import jakarta.servlet.http.HttpServletRequest;
  5. import jakarta.servlet.http.HttpServletResponse;
  6. import no.nav.data.common.utils.MdcUtils;
  7. import org.springframework.web.filter.OncePerRequestFilter;

  8. import java.io.IOException;

  9. public class UserFilter extends OncePerRequestFilter {

  10.     @Override
  11.     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
  12.         MdcUtils.setCallerFromSecurity();
  13.         try {
  14.             filterChain.doFilter(request, response);
  15.         } finally {
  16.             MdcUtils.clearUser();
  17.         }
  18.     }
  19. }