Created
February 8, 2023 13:50
-
-
Save sandeeppagatur/aa76e2967e1ff7b4649a89434dcb11da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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