Swagger-ui.html - Unauthorized error: Full authentication is required to access this resource

·2023년 3월 6일

# 졸업 프로젝트

목록 보기
3/3

문제 상황

나는 swagger api 문서를 jwt 토큰 인증을 하지 않아도 접근할 수 있도록 설계하고 싶었다.
그래서 내가 시도했던 방법은
이렇게 SecurityConfig 파일에 http.antMatchers("/swagger-ui.html")을 추가하기.
단순하게 스웨거 api 문서를 보는 사이트가 http://localhost:8080/swagger-ui.html 니까 이렇게 추가하면 되는 줄 알았다ㅎ
하지만 실행결과
이렇게 오류가 뜨는 것을 확인했다.

해결

결론부터 말하자면, swagger-ui.html 뿐만 아니라 다른 url들도 permitAll() 해주어야 한다.
나 같은 경우, 다음처럼 url을 추가했더니 jwt 인증을 거치지 않고 swagger-ui.html에 접속할 수 있었다.

.antMatchers(
                        "/v2/api-docs",
                        "/configuration/ui",
                        "/swagger-resources",
                        "/configuration/security",
                        "/swagger-ui.html",
                        "/webjars/**",
                        "/swagger-resources/configuration/ui",
                        "/swagger-resources/configuration/security",
                        "/swagger-ui.html"
            ).permitAll()

참고
https://stackoverflow.com/questions/37671125/how-to-configure-spring-security-to-allow-swagger-url-to-be-accessed-without-aut

profile
혼자 끄적끄적

0개의 댓글