[Spring Security 문제 해결] Spring Security 관련 Preflight 의 401 이슈 발생 문제 그리고 브라우저의 http 캐시
이전에 관련한 문제가 발생했었는데 상황이 조금 다르게 발생했다. 그래서 문제를 다시금 해결하면서 확실하게 문제와 개념을 깨부숴 버리도록 한다. 이전의 포스트는 브라우저 캐시에 집중했다면 이번 포스트는 CORS 와 Preflight, Spring Security 의 특성등에 대해 다루게 된다.
코드는 다음과 같다.
const result = await axios.options<any>("MY_URL",
{ headers: { "Authorization": "Bearer MY_TOKEN" } })
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// 쿠키 방식 X, 세션 저장 X, JWT O
.and()
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(new RestAuthenticationEntryPoint())
.accessDeniedHandler(tokenAccessDeniedHandler)
.and()
.authorizeRequests()
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.antMatchers("MY_URL").hasAnyAuthority(RoleType.USER.getCode())
.antMatchers("OTHER_URL").permitAll()
http.cors().disable();