Development/Spring Boot3 (Kotlin)

[SOLVED][Kotlin][Spring3] Swagger : Failed to load remote configuration.

Tradgineer 2023. 12. 26. 08:15

 

1. 문제 상황

 

http://localhost:8080/swagger-ui/index.html#/

Failed to load remote configuration.

 

 

 

 

 

2. 문제 원인

 

필자는 Spring Security 적용했을때 위와 같은 상황이 생겼다. Spring Security에서 접근할 수 없도록 막기 때문에 위 현상이 발생했다.

 

 

 

 

 

3. 해결 방법

 

.requestMatchers(AntPathRequestMatcher("/v3/api-docs/**")).permitAll()

permit all로 1개 항목을 더 추가합니다.

 

// vim SecurityConfig.kt

package com.dev.test01.security

import com.dev.test01.product.client.RoleEnum
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.util.matcher.AntPathRequestMatcher

@Configuration
@EnableWebSecurity
class SecurityConfig {
    @Bean
    @Throws(Exception::class)
    fun filterChain(http: HttpSecurity): SecurityFilterChain {
        http
            .csrf {
                csrfConfig: CsrfConfigurer<HttpSecurity> -> csrfConfig.disable()
            } // 1번
            .headers { headerConfig: HeadersConfigurer<HttpSecurity?> ->
                headerConfig.frameOptions(
                    { frameOptionsConfig -> frameOptionsConfig.disable() }
                )
            } // 2번
            .authorizeHttpRequests { authorizeRequests ->
                authorizeRequests
                    .requestMatchers(AntPathRequestMatcher("/h2-console/**")).permitAll()
                    .requestMatchers(AntPathRequestMatcher("/swagger-ui/**")).permitAll()
                    .requestMatchers(AntPathRequestMatcher("/v3/api-docs/**")).permitAll()
//                    .requestMatchers(AntPathRequestMatcher("/swagger-resources/**")).permitAll()
//                    .requestMatchers(AntPathRequestMatcher("/favicon.ico")).permitAll()
//                    .requestMatchers(AntPathRequestMatcher("/error")).permitAll()
                    .requestMatchers(AntPathRequestMatcher("/api/v1/client/**")).hasRole(RoleEnum.BASIC_PLAN.name)
                    .requestMatchers(AntPathRequestMatcher("/api/v1/posts/**")).hasRole(RoleEnum.BASIC_PLAN.name)
                    .requestMatchers(AntPathRequestMatcher("/api/v1/admins/**")).hasRole(RoleEnum.ADMIN.name)
                    .anyRequest().authenticated()
            } // 3번
        return http.build()
    }
}

 

 

 

 

 

4. 해결 완료