Skip to content

Commit

Permalink
♻️ refactor:
Browse files Browse the repository at this point in the history
- 인가 과정 api-gateway에 전적으로 위임
- User-Servcie : 토큰 resolve 방식-> 헤더에서 온 email 받아서 쓰는 방식으로 변경
  • Loading branch information
jinho7 committed Jun 2, 2024
1 parent a22e5fe commit 0b38fa5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public GatewayFilter apply(Config config) {

// Mono(단일 값), Flux(다중 값) -> Spring WebFlux
private Mono<Void> onError(ServerWebExchange exchange, String errorMsg) {
log.error(errorMsg);
log.error("[*] Gateway filter error: {}", errorMsg);

ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(HttpStatus.UNAUTHORIZED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.waither.userservice.entity.User;
import com.waither.userservice.global.jwt.execption.SecurityCustomException;
import com.waither.userservice.global.jwt.execption.SecurityErrorCode;
import com.waither.userservice.global.jwt.util.JwtUtil;
import com.waither.userservice.repository.UserRepository;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.core.MethodParameter;
Expand All @@ -23,7 +22,6 @@
@Transactional
public class AuthUserArgumentResolver implements HandlerMethodArgumentResolver {

private final JwtUtil jwtUtil;
private final UserRepository userRepository;

@Override
Expand All @@ -37,10 +35,11 @@ public boolean supportsParameter(MethodParameter parameter) {
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
HttpServletRequest httpServletRequest = (HttpServletRequest) webRequest.getNativeRequest();
String token = jwtUtil.resolveAccessToken(httpServletRequest);
String email = jwtUtil.getEmail(token);
String email = httpServletRequest.getHeader("email");

log.info("[*] Header <email> from ApiGateway: {}", email);

return userRepository.findByEmail(email)
.orElseThrow(() -> new SecurityCustomException(SecurityErrorCode.TOKEN_NOT_FOUND));
.orElseThrow(() -> new SecurityCustomException(SecurityErrorCode.USER_NOT_FOUND));
}
}
}

0 comments on commit 0b38fa5

Please sign in to comment.