@RequiredArgsConstructor
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
private final LoginUserIdArgumentResolver loginUserIdArgumentResolver;
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("OPTIONS", "GET", "POST", "PUT", "DELETE");
}
}
WebMvcConfigurer 인터페이스가 가지고 있는 addCorsMappings 메소드를 오버라이딩 한 후에 위와 같이 http://localhost:3000에 대해서 접근할 수 있는 권한
@RequiredArgsConstructor
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.mvcMatchers(HttpMethod.OPTIONS, "/**").permitAll() // Preflight Request 허용해주기
.antMatchers("/api/v1/**").hasAnyAuthority(USER.name());
}
}