Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - health checker api 로깅 필터 안거치게 변경 #498

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public JwtAuthFilter(

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
throws IOException {
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
if (isTokenBlank(token)) {
sendUnauthorizedResponse(response, "로그인을 해주세요.");
Expand Down
28 changes: 17 additions & 11 deletions backend/src/main/java/kr/touroot/global/logging/LoggingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kr.touroot.global.auth.JwtAuthFilter;
import kr.touroot.global.auth.dto.HttpRequestInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
Expand All @@ -20,15 +21,20 @@
@Component
public class LoggingFilter extends OncePerRequestFilter {

private static final List<HttpRequestInfo> WHITE_LIST = List.of(
new HttpRequestInfo(HttpMethod.GET, "/h2-console/**"),
new HttpRequestInfo(HttpMethod.POST, "/h2-console/**"),
new HttpRequestInfo(HttpMethod.GET, "/favicon/**"),
new HttpRequestInfo(HttpMethod.GET, "/swagger-ui/**"),
new HttpRequestInfo(HttpMethod.GET, "/swagger-resources/**"),
new HttpRequestInfo(HttpMethod.GET, "/v3/api-docs/**"),
new HttpRequestInfo(HttpMethod.OPTIONS, "/**")
);
private final List<HttpRequestInfo> whiteList;

public LoggingFilter(@Value("${management.endpoints.web.base-path}") String actuatorBasePath) {
this.whiteList = List.of(
new HttpRequestInfo(HttpMethod.GET, actuatorBasePath + "/**"),
new HttpRequestInfo(HttpMethod.GET, "/h2-console/**"),
new HttpRequestInfo(HttpMethod.POST, "/h2-console/**"),
new HttpRequestInfo(HttpMethod.GET, "/favicon.ico"),
new HttpRequestInfo(HttpMethod.GET, "/swagger-ui/**"),
new HttpRequestInfo(HttpMethod.GET, "/swagger-resources/**"),
new HttpRequestInfo(HttpMethod.GET, "/v3/api-docs/**"),
new HttpRequestInfo(HttpMethod.OPTIONS, "/**")
);
}

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Expand All @@ -49,13 +55,13 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {
protected boolean shouldNotFilter(HttpServletRequest request) {
AntPathMatcher antPathMatcher = new AntPathMatcher();

String url = request.getRequestURI();
String method = request.getMethod();

return WHITE_LIST.stream()
return whiteList.stream()
.anyMatch(white -> white.method().matches(method) && antPathMatcher.match(white.urlPattern(), url));
}
}
Loading