In this post, we will see how to resolve PermitAll() not working, Unauthorized 401. Spring security config
Question:
I have multiple entry points. One of them must be protected by a filter, the rest are completely open.Pls help me..
My configuration adapter:
Response:
Best Answer:
Currently your Filter is always executing, even before the non authenticated calls.To solve it you have to say which request to handle by your Filter. For that you have two options:
add the
shouldNotFilter
method to yourJwtAuthFilter
@Override protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { return !request.getRequestURI().startsWith("/data/"); }
simply add the following if condition to the beginning of your
JwtAuthFilter.doFilterInternal
:if (!request.getRequestURI().startsWith("/data/")) { filterChain.doFilter(request, response); return; }
Exactly the same issue has been discussed in the following video at 1:11:11 timestamp: Spring Security, demystified by Daniel Garnier Moiroux
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com