Chef.Yeon
Code Cook
Chef.Yeon
전체 방문자
오늘
어제
  • 분류 전체보기 (230)
    • 게임 개발 (1)
      • Unity (1)
    • Android (27)
      • Kotlin (19)
      • 우아한테크코스 5기 (4)
    • Language (11)
      • 파이썬 (3)
      • Java (7)
    • DB (2)
      • SQL (16)
    • Spring (25)
    • 코딩테스트 (56)
    • Git (1)
    • TIL (85)
    • DevOps (6)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 코틀린 인 액션
  • elasticsearch
  • 안드로이드
  • rsocket
  • Docker
  • 프로그래머스
  • til
  • webflux
  • 코딩테스트
  • enum
  • kibana
  • Android
  • 레포지토리
  • ec2
  • Wil
  • SQL
  • kotlin
  • java
  • 에라토스테네스의 체
  • grafana
  • 백준
  • 코틀린
  • spring
  • 문자열
  • 파이썬
  • 내림차순
  • 다이나믹 프로그래밍
  • 프리코스
  • 우아한테크코스
  • MariaDB

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Chef.Yeon

Code Cook

[TIL - 20240612] Swagger Failed to load remote configuration 해결
TIL

[TIL - 20240612] Swagger Failed to load remote configuration 해결

2024. 6. 12. 10:31

 

 

💻문제점1 - Failed to load remote configuration

application.yaml

springdoc:
  default-consumes-media-type: application/json
  default-produces-media-type: application/json
  swagger-ui:
    disable-swagger-default-url: true
    path: /api/v1/docs/swagger
  paths-to-match:
    - /**

 

SecurityConfig

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        return http.cors(cors -> cors.configurationSource(corsConfigurationSource()))
                .csrf(AbstractHttpConfigurer::disable)
                .exceptionHandling(
                        config ->
                                config.authenticationEntryPoint(jwtAuthenticationEntryPoint)
                                        .accessDeniedHandler(resourceAccessDeniedHandler))
                .authorizeHttpRequests(
                        authorize ->
                                authorize
                                        .requestMatchers(
                                                new AntPathRequestMatcher("/api/v1/docs/swagger*/**"),
                                                new AntPathRequestMatcher(
                                                        "/api/v1/members/oauth/*/login"),
                                                new AntPathRequestMatcher("/actuator/health"))
                                        .permitAll()
                                        .anyRequest()
                                        .authenticated())
                .sessionManagement(
                        session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
                .build();
    }

 

와일드 카드를 사용하여 /api/v1/docs/swagger 로 시작되는 URL 요청을 허용했다.

http://localhost:8080/api/v1/docs/swagger 에 접속은 되었으나 다음과 같은 문구가 떴다.

Failed to load remote configuration

 

 

 

서버 로그를 확인했을 때, 다음과 같은 에러가 발생했다.

[Exception: org.springframework.security.authentication.InsufficientAuthenticationException | Status: 401 UNAUTHORIZED | Message: Full authentication is required to access this resource]

 

어떤 자원에 대한 접근 권한이 없는지 개발자 도구를 통해 확인해본 결과, /v3/api-docs/swagger-config 요청 URL에서 401 에러가 뜬 것을 볼 수 있다.

 

허용되지 않은 요청 URL에 접근하려면 토큰이 필요한데, 이 때문에 401 에러가 발생하는 것 같다.


🔍해결

SecurityConfig에서 해당 리소스 접근에 대한 URL 요청을 허용해주었다.

SecurityConfig

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        return http.cors(cors -> cors.configurationSource(corsConfigurationSource()))
                .csrf(AbstractHttpConfigurer::disable)
                .exceptionHandling(
                        config ->
                                config.authenticationEntryPoint(jwtAuthenticationEntryPoint)
                                        .accessDeniedHandler(resourceAccessDeniedHandler))
                .authorizeHttpRequests(
                        authorize ->
                                authorize
                                        .requestMatchers(
                                                new AntPathRequestMatcher(
                                                        "/api/v1/docs/swagger*/**"),
                                                new AntPathRequestMatcher("/v3/api-docs/**"),
                                                new AntPathRequestMatcher(
                                                        "/api/v1/members/oauth/*/login"),
                                                new AntPathRequestMatcher("/actuator/health"))
                                        .permitAll()
                                        .anyRequest()
                                        .authenticated())
                .sessionManagement(
                        session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
                .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
                .build();
    }

 

728x90

'TIL' 카테고리의 다른 글

[TIL-20240805] ElasticSearch + Spring Boot 연동 오류 해결  (0) 2024.08.05
[TIL - 20240612] Swagger HTTPS 설정  (0) 2024.06.12
[TIL-231219] 사용자 정의 애노테이션을 사용한 List 요소 검증  (0) 2024.03.20
[TIL-20240307] 주간/월간/연간 섭취량 조회 API 성능 개선  (1) 2024.03.07
[TIL - 20240110] 컨트롤러 나누기?!  (0) 2024.01.10
    'TIL' 카테고리의 다른 글
    • [TIL-20240805] ElasticSearch + Spring Boot 연동 오류 해결
    • [TIL - 20240612] Swagger HTTPS 설정
    • [TIL-231219] 사용자 정의 애노테이션을 사용한 List 요소 검증
    • [TIL-20240307] 주간/월간/연간 섭취량 조회 API 성능 개선
    Chef.Yeon
    Chef.Yeon
    보기 좋고 깔끔한 코드를 요리하기 위해 노력하고 있습니다.

    티스토리툴바