[Start Spring Boot] Spring Security swagger 설정하기

·2024년 4월 8일
0

Start Spring Boot!

목록 보기
35/53
post-thumbnail

swagger 설정하기

  • Security로 접근 권한을 설정 후 swagger 페이지에 정상적으로 접근이 불가능 하다.

config 수정하기

  • SpringSecurityConfiguration.java
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests((requests) -> requests
                        .requestMatchers("/api/players", "/api-docs","/swagger-ui/**", "/swagger-resources/**", "/v3/api-docs/**").authenticated()
                        .requestMatchers("/api/v1/team").permitAll())
                .formLogin(Customizer.withDefaults())
                .httpBasic(Customizer.withDefaults());

        http.csrf().disable();
        return http.build();
    }
  • 다음과 같이 swagger의 모든 경로와 접근 URL을 추가하였다.
profile
백엔드 개발자가 꿈인 컴공과

0개의 댓글

관련 채용 정보