make it simple
article thumbnail
[Spring Boot 3.0 / Spring Security 6.0] Controller에서 시큐리티 인증 mocking 후 테스트 하기(401 피하기)
Kotlin 2024. 1. 11. 16:57

문제 스프링 부트 3.2 / Spring Security 6.0 적용을 한 후 유저가 모임을 생성하는 API를 테스트 해야된다. 하지만 애석하게도 인증 실패로 401이 반환된다. 주어진 상황 설정된 스프링 시큐리티 밑과 같이 http.authorizedHttpRequests 안에 permitAll()된 엔드포인트들만 인증을 안해도 접근이 가능한다. 이 외에 모든 엔드포인트에는 인증이 필요하다. @Bean fun securityFilterChain( http: HttpSecurity, jwtAuthenticationFilter: JwtAuthenticationFilter, ): DefaultSecurityFilterChain { http .csrf { it.disable() } .headers { it.f..