Skip to content

Commit

Permalink
KL-184/fix: handle public endpoint error
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhamma committed Oct 11, 2024
1 parent 8576de0 commit d374f5d
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
if ("GET".equalsIgnoreCase(request.getMethod())) {
return SecurityEndpoint.isPublicEndpoint(request)
&& !SecurityEndpoint.isBothEndpoint(request);
}
return false;
return "GET".equalsIgnoreCase(request.getMethod())
&& SecurityEndpoint.isPublicEndpoint(request);
}

@Override
Expand All @@ -45,9 +42,15 @@ protected void doFilterInternal(
FilterChain filterChain
) throws ServletException, IOException {
final String accessToken = tokenUtil.resolveToken(request);
final boolean isBothEndpoint = SecurityEndpoint.isBothEndpoint(request);
final boolean isGetRequest = "GET".equalsIgnoreCase(request.getMethod());

if (accessToken == null && SecurityEndpoint.isBothEndpoint(request)) {
proceedWithoutAuthentication(request, response, filterChain);
if (!StringUtils.hasText(accessToken)) {
if (isBothEndpoint || isGetRequest) {
filterChain.doFilter(request, response);
return;
}
handleTokenException(request, response, filterChain, new UnauthorizedException());
return;
}

Expand All @@ -62,9 +65,17 @@ protected void doFilterInternal(
}
}
} catch (TokenInvalidException | TokenExpiredException e) {
if (isBothEndpoint || isGetRequest) {
filterChain.doFilter(request, response);
return;
}
handleTokenException(request, response, filterChain, e);
return;
} catch (Exception e) {
if (isBothEndpoint || isGetRequest) {
filterChain.doFilter(request, response);
return;
}
handleTokenException(request, response, filterChain, new UnauthorizedException());
return;
}
Expand Down

0 comments on commit d374f5d

Please sign in to comment.