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

feat : health check 추가 #52

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
@@ -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() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,6 +14,7 @@
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

@Slf4j
@Component
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
@RequiredArgsConstructor
Expand All @@ -21,12 +23,19 @@ public class WebfluxAuthFilter implements WebFilter {

@Override
public Mono<Void> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading