diff --git a/src/main/java/online/partyrun/partyrunmatchingservice/global/controller/GlobalController.java b/src/main/java/online/partyrun/partyrunmatchingservice/global/controller/GlobalController.java new file mode 100644 index 0000000..ee2485a --- /dev/null +++ b/src/main/java/online/partyrun/partyrunmatchingservice/global/controller/GlobalController.java @@ -0,0 +1,16 @@ +package online.partyrun.partyrunmatchingservice.global.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class GlobalController { + + @GetMapping("/") + @ResponseStatus(HttpStatus.OK) + public void healthCheck() { + + } +} diff --git a/src/main/java/online/partyrun/partyrunmatchingservice/global/security/WebfluxAuthFilter.java b/src/main/java/online/partyrun/partyrunmatchingservice/global/security/WebfluxAuthFilter.java index 43186f5..63a9123 100644 --- a/src/main/java/online/partyrun/partyrunmatchingservice/global/security/WebfluxAuthFilter.java +++ b/src/main/java/online/partyrun/partyrunmatchingservice/global/security/WebfluxAuthFilter.java @@ -3,6 +3,7 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.experimental.FieldDefaults; +import lombok.extern.slf4j.Slf4j; import online.partyrun.jwtmanager.JwtExtractor; import online.partyrun.jwtmanager.dto.JwtPayload; import org.springframework.http.server.reactive.ServerHttpRequest; @@ -13,6 +14,7 @@ import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; +@Slf4j @Component @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) @RequiredArgsConstructor @@ -21,12 +23,19 @@ public class WebfluxAuthFilter implements WebFilter { @Override public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { + if(isAllowNonAuth(exchange)) { + return Mono.empty(); + } final JwtPayload payload = getJwtPayload(exchange.getRequest()); return chain.filter(exchange) .contextWrite( ReactiveSecurityContextHolder.withAuthentication(new AuthUser(payload))); } + private boolean isAllowNonAuth(final ServerWebExchange exchange) { + return exchange.getRequest().getPath().value().equals("/api/"); + } + private JwtPayload getJwtPayload(final ServerHttpRequest request) { final String token = request.getHeaders().getFirst("Authorization"); return jwtExtractor.extract(token); diff --git a/src/test/java/online/partyrun/partyrunmatchingservice/global/controller/GlobalControllerTest.java b/src/test/java/online/partyrun/partyrunmatchingservice/global/controller/GlobalControllerTest.java new file mode 100644 index 0000000..c1960d6 --- /dev/null +++ b/src/test/java/online/partyrun/partyrunmatchingservice/global/controller/GlobalControllerTest.java @@ -0,0 +1,22 @@ +package online.partyrun.partyrunmatchingservice.global.controller; + +import online.partyrun.partyrunmatchingservice.config.docs.WebfluxDocsTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration(classes = {GlobalController.class, HttpControllerAdvice.class}) +@WithMockUser +@DisplayName("GlobalController") +class GlobalControllerTest extends WebfluxDocsTest { + @Test + @DisplayName("health check") + void healthCheck() { + client.get() + .uri("/") + .exchange() + .expectStatus() + .isOk(); + } +} \ No newline at end of file