mirror of
https://github.com/headporter81/specialsource-homepage-backend.git
synced 2026-08-08 15:41:11 +09:00
This commit is contained in:
@@ -1,28 +1,20 @@
|
|||||||
package company.specialsource.config;
|
package company.specialsource.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@RequiredArgsConstructor
|
||||||
public class WebMvcConfig {
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Bean
|
private final VisitorInterceptor visitorInterceptor;
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
||||||
http
|
|
||||||
// 1. 🟢 외부 매크로의 POST 요청이 통과할 수 있도록 CSRF 보호 대상에서 업로드 API를 제외합니다.
|
|
||||||
.csrf(csrf -> csrf
|
|
||||||
.ignoringRequestMatchers("/api/sync/upload")
|
|
||||||
)
|
|
||||||
// 2. 🟢 로그인이나 별도의 인증 토큰 없이도 접근할 수 있도록 허용합니다.
|
|
||||||
.authorizeHttpRequests(auth -> auth
|
|
||||||
.requestMatchers("/api/sync/upload").permitAll()
|
|
||||||
.anyRequest().authenticated()
|
|
||||||
);
|
|
||||||
|
|
||||||
return http.build();
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(visitorInterceptor)
|
||||||
|
// .addPathPatterns("/api/**") // 🟢 모든 API 주소로 들어오는 길목을 차단하여 감시
|
||||||
|
.excludePathPatterns("/api/analytics/**", "/static/**", "/favicon.ico"); // 통계 조회 API 자체는 중복 카운팅 차단
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user