kosmo138 / resumate

자기소개서를 세상에서 가장 쉽게 쓰는 방법
https://www.resumate.store
0 stars 0 forks source link

이력서 조회 404 오류 #50

Closed suyons closed 3 months ago

suyons commented 3 months ago

Related Commit

https://github.com/kosmo138/resumate/commit/664397acfecccf2205c8bdc6926c68207726c447

Related Issue

https://github.com/kosmo138/resumate/issues/46

문제 상황

  1. POST /api/member 요청: 200 OK
  2. POST /api/login 요청: 200 OK
  3. GET /api/resume 요청: 403 Forbidden
  4. Bearer {JWT_TOKEN} 인증 헤더를 추가했음에도 불구하고 GET /api/resume 요청에 실패

문제 해결

1차 시도: Spring Security 비활성화

  1. pom.xml 에서 Spring Security 관련 의존성을 모두 삭제하고 SecurityConfig.java 파일에서는 filterChain 객체 부분을 삭제했다.

SecurityConfig.java

삭제

SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .httpBasic((basic) -> basic.disable())
                .csrf((csrf) -> csrf.ignoringRequestMatchers("/api/**"))
                .sessionManagement((session) -> session.disable())
                .formLogin((form) -> form.disable())
                .authorizeHttpRequests((auth) -> auth
                        .anyRequest().permitAll());
        return http.build();
}

보존

@Bean
public BCryptPasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}
  1. 보안 설정을 해제한 이후 404 NotFound 오류가 표시되는 문제는 46번 이슈 당시와 동일했다.

  2. Docker 콘솔에서 GET /api/resume 요청 시 다음과 같은 로그를 확인

nginx   | 172.18.0.1 - - [27/Mar/2024:01:34:42 +0000] "GET /api/resume HTTP/1.1" 403 0 "-" "Thunder Client (https://www.thunderclient.com)" "-"
server  | 2024-03-27T01:34:42.068Z DEBUG 42 --- [server] [nio-8080-exec-1] o.s.s.w.a.AnonymousAuthenticationFilter  : Set SecurityContextHolder to anonymous SecurityContext
server  | 2024-03-27T01:34:42.068Z DEBUG 42 --- [server] [nio-8080-exec-1] o.s.security.web.FilterChainProxy        : Securing GET /error
server  | 2024-03-27T01:34:42.069Z DEBUG 42 --- [server] [nio-8080-exec-1] o.s.s.w.a.AnonymousAuthenticationFilter  : Set SecurityContextHolder to anonymous SecurityContext
server  | 2024-03-27T01:34:42.069Z DEBUG 42 --- [server] [nio-8080-exec-1] o.s.s.w.s.HttpSessionRequestCache        : Saved request http://host.docker.internal:8080/error?continue to session
server  | 2024-03-27T01:34:42.069Z DEBUG 42 --- [server] [nio-8080-exec-1] o.s.s.w.a.Http403ForbiddenEntryPoint     : Pre-authenticated entry point called. Rejecting access
  1. GET /api/resume 요청 시 발생하는 예외 메시지
org.springframework.web.servlet.resource.NoResourceFoundException: No static resource api/resume.

2차 시도: Controller - 0에서부터 시작하기

  1. GET /api/resume 요청 시 403이 아닌 404가 오는 것에 대해 의구심을 가졌다. 다른 디버깅 방법이 떠오르지 않아 0에서부터 시작했다.

ResumeController.java

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/resume")
public class ResumeController {
    private final ResumeService resumeService;

    @GetMapping(value = "/")
    public ResponseEntity<String> getResumeTest(@RequestHeader("authorization") String bearer) {
        return ResponseEntity.ok("Bearer: " + bearer);
    }
  1. 위와 같이 가장 간단한 형태의 메서드를 추가했음에도 GET /api/resume 요청에 대해 404가 반환되었다.

  2. "설마 끝에 / 문자가 오지 않아서?" 생각에 GET /api/resume/ 요청을 해 보았더니 200 OK가 반환되었다.

  3. 이후 getResume() 메서드가 /api/resume & /api/resume/ 모두에 응답할 수 있도록 Annotation을 수정했다.

@GetMapping(value = { "", "/" }, produces = "application/json")
public ResponseEntity<String> getResume(@RequestHeader("authorization") String bearer) {
    return resumeService.selectResumeHead(bearer);
}

결과

Solved