💻문제점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 |