Skip to content

Instantly share code, notes, and snippets.

@sandeeppagatur
Created February 8, 2023 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeeppagatur/aa76e2967e1ff7b4649a89434dcb11da to your computer and use it in GitHub Desktop.
Save sandeeppagatur/aa76e2967e1ff7b4649a89434dcb11da to your computer and use it in GitHub Desktop.
@Component
public class CustomAuthFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
Object context=request.getSession().getAttribute("SPRING_SECURITY_CONTEXT");
//context will be null if we dont pass x-auth-token in header and null should not be set in SecurityContextHolder
if(context!=null){
SecurityContextHolder.setContext((SecurityContext) context);
}
filterChain.doFilter(request, response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment