Skip to content

Commit

Permalink
[Fix] - Spring Actuator 접속 불가 문제 해결 (#427)
Browse files Browse the repository at this point in the history
* refactor: 불필요한 의존성 제거

* feat: Spring Actuator 설정 추가

* feat: Spring Actuator로 공개된 정보 접근 가능하도록 화이트리스트 URL 추가

* feat: favicon 추가

* fix: Spring actuator 접속 문제 해결

* fix: 테스트에서 누락된 속성 추가
  • Loading branch information
hangillee authored Sep 20, 2024
1 parent 40be40d commit 872b9f5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
46 changes: 27 additions & 19 deletions backend/src/main/java/kr/touroot/global/auth/JwtAuthFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
import kr.touroot.authentication.infrastructure.JwtTokenProvider;
import kr.touroot.global.auth.dto.HttpRequestInfo;
import kr.touroot.global.exception.dto.ExceptionResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.filter.OncePerRequestFilter;

@RequiredArgsConstructor
@Slf4j
@Component
public class JwtAuthFilter extends OncePerRequestFilter {
Expand All @@ -28,23 +27,32 @@ public class JwtAuthFilter extends OncePerRequestFilter {

private final ObjectMapper objectMapper;
private final JwtTokenProvider tokenProvider;
private final List<HttpRequestInfo> whiteList;

private static final List<HttpRequestInfo> WHITE_LIST = List.of(
new HttpRequestInfo(HttpMethod.GET, "/actuator/**"),
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.GET, "/api/v1/travelogues/**"),
new HttpRequestInfo(HttpMethod.POST, "/api/v1/login/**"),
new HttpRequestInfo(HttpMethod.GET, "/api/v1/travel-plans/shared/**"),
new HttpRequestInfo(HttpMethod.POST, "/api/v1/tags/**"),
new HttpRequestInfo(HttpMethod.GET, "/api/v1/tags/**"),
new HttpRequestInfo(HttpMethod.POST, "/api/v1/members"),
new HttpRequestInfo(HttpMethod.OPTIONS, "/**")
);
public JwtAuthFilter(
ObjectMapper objectMapper,
JwtTokenProvider tokenProvider,
@Value("${management.endpoints.web.base-path}") String basePath
) {
this.objectMapper = objectMapper;
this.tokenProvider = tokenProvider;
this.whiteList = List.of(
new HttpRequestInfo(HttpMethod.GET, basePath + "/**"),
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.GET, "/api/v1/travelogues/**"),
new HttpRequestInfo(HttpMethod.POST, "/api/v1/login/**"),
new HttpRequestInfo(HttpMethod.GET, "/api/v1/travel-plans/shared/**"),
new HttpRequestInfo(HttpMethod.POST, "/api/v1/tags/**"),
new HttpRequestInfo(HttpMethod.GET, "/api/v1/tags/**"),
new HttpRequestInfo(HttpMethod.POST, "/api/v1/members"),
new HttpRequestInfo(HttpMethod.OPTIONS, "/**")
);
}

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Expand Down Expand Up @@ -90,7 +98,7 @@ protected boolean shouldNotFilter(HttpServletRequest request) throws ServletExce
private boolean isInWhiteList(String method, String url) {
AntPathMatcher antPathMatcher = new AntPathMatcher();

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

Expand Down
1 change: 1 addition & 0 deletions backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ management:
web:
exposure:
include: info, health, metrics
base-path: ENC(zc5tP1eNIEjv3uN5Kuih7wlo5zILgWxq)
enabled-by-default: false
---
# local profile
Expand Down
Binary file added backend/src/main/resources/static/favicon.ico
Binary file not shown.
16 changes: 16 additions & 0 deletions backend/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ spring:

cors:
allowed-origins: http://localhost:3000

management:
endpoint:
health:
show-components: always
enabled: true
info:
enabled: true
metrics:
enabled: true
endpoints:
web:
exposure:
include: info, health, metrics
base-path: /test
enabled-by-default: false

0 comments on commit 872b9f5

Please sign in to comment.