From b65c37d92148ecb890a34e9bd69c9ca3be39b06e Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Tue, 21 Apr 2026 12:02:07 +0900 Subject: [PATCH] =?UTF-8?q?260421=5F01=5FENH:=20Swagger=EB=A5=BC=20?= =?UTF-8?q?=EB=8C=80=EC=83=81=EC=9C=BC=EB=A1=9C=20=ED=95=9C=20IP=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EB=A7=81=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EC=B2=98=EB=A6=AC=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../webmvc/KriIpAccessProperties.java | 41 ------------------- .../webmvc/KriWebMvcAutoConfiguration.java | 33 +-------------- .../webmvc/IpAccessControlInterceptor.java | 26 ------------ .../webmvc/IpAccessControlService.java | 20 --------- 5 files changed, 2 insertions(+), 120 deletions(-) delete mode 100644 src/main/java/com/kri/common/autoconfigure/webmvc/KriIpAccessProperties.java delete mode 100644 src/main/java/com/kri/common/runtime/webmvc/IpAccessControlInterceptor.java delete mode 100644 src/main/java/com/kri/common/runtime/webmvc/IpAccessControlService.java diff --git a/build.gradle b/build.gradle index 8f01a55..13534bf 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } //버전 변경은 여기서 -def commonVer = "beta.1.1.15" +def commonVer = "beta.1.1.16" group = 'com.kri.common' version = commonVer diff --git a/src/main/java/com/kri/common/autoconfigure/webmvc/KriIpAccessProperties.java b/src/main/java/com/kri/common/autoconfigure/webmvc/KriIpAccessProperties.java deleted file mode 100644 index f9d00b4..0000000 --- a/src/main/java/com/kri/common/autoconfigure/webmvc/KriIpAccessProperties.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.kri.common.autoconfigure.webmvc; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@Getter -@Setter -@ConfigurationProperties(prefix = "kri.webmvc.ip") -public class KriIpAccessProperties { - - /** - * 공통에서 고정으로 들고 갈 기본 CIDR 들 → setter 없음 (외부에서 못 바꿈) - */ - private final List defaultCidrs = List.of( - "127.0.0.1/32", // 로컬 IPv4 - "::1/128", // 로컬 IPv6 - "10.10.13.0/24", //석오 내부망 - "211.254.145.128/25" //석오 내부망 외부 IP - ); - - /** - * 서비스에서 추가로 넣고 싶은 CIDR 목록 application.yml / properties 로 바인딩되는 리스트 - *

- * 예) kri.webmvc.ip.additional-cidrs[0]=10.10.0.0/16 - */ - private List additionalCidrs = new ArrayList<>(); - - /** - * 기본 + 추가를 합친 최종 목록 - */ - public List getEffectiveCidrs() { - return Stream.concat(defaultCidrs.stream(), additionalCidrs.stream()) - .distinct() - .collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/src/main/java/com/kri/common/autoconfigure/webmvc/KriWebMvcAutoConfiguration.java b/src/main/java/com/kri/common/autoconfigure/webmvc/KriWebMvcAutoConfiguration.java index 0509e0b..32b1611 100644 --- a/src/main/java/com/kri/common/autoconfigure/webmvc/KriWebMvcAutoConfiguration.java +++ b/src/main/java/com/kri/common/autoconfigure/webmvc/KriWebMvcAutoConfiguration.java @@ -1,8 +1,6 @@ package com.kri.common.autoconfigure.webmvc; import com.kri.common.feature.auth.jwt.JwtService; -import com.kri.common.runtime.webmvc.IpAccessControlInterceptor; -import com.kri.common.runtime.webmvc.IpAccessControlService; import com.kri.common.runtime.webmvc.RequestUserContextArgumentResolver; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.ObjectProvider; @@ -10,36 +8,18 @@ import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @AutoConfiguration -@EnableConfigurationProperties(KriIpAccessProperties.class) @ConditionalOnProperty(name = "kri.webmvc.enabled", matchIfMissing = true) @RequiredArgsConstructor public class KriWebMvcAutoConfiguration { - private final KriIpAccessProperties ipProps; // 생성자 주입 (RequiredArgsConstructor) - // 선택 주입: 있으면 쓰고, 없으면 안 씀 - private final ObjectProvider ipAccessControlInterceptorProvider; - @Bean - @ConditionalOnMissingBean - public IpAccessControlService ipAccessControlService(KriIpAccessProperties ipProps) { - return new IpAccessControlService(ipProps); - } - - @Bean - @ConditionalOnMissingBean - public IpAccessControlInterceptor ipAccessControlInterceptor(IpAccessControlService service) { - return new IpAccessControlInterceptor(service); - } - - @Bean - @ConditionalOnBean(JwtService.class)// JwtService 있을 때만 동작 + @ConditionalOnBean(JwtService.class) @ConditionalOnMissingBean public RequestUserContextArgumentResolver requestUserContextArgumentResolver( JwtService jwtService @@ -47,19 +27,13 @@ public class KriWebMvcAutoConfiguration { return new RequestUserContextArgumentResolver(jwtService); } - /** - * 실제로 WebMvc 설정을 하는 WebMvcConfigurer Bean - */ @Bean public WebMvcConfigurer kriCommonWebMvcConfigurer( - KriIpAccessProperties properties, - ObjectProvider ipAccessControlInterceptorProvider, ObjectProvider requestUserContextArgumentResolverProvider ) { return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { - // 기본 CORS – 필요하면 나중에 조정 registry.addMapping("/**") .allowedOriginPatterns("*") .allowedMethods("*") @@ -69,11 +43,6 @@ public class KriWebMvcAutoConfiguration { @Override public void addInterceptors(InterceptorRegistry registry) { - ipAccessControlInterceptorProvider.ifAvailable(interceptor -> - registry.addInterceptor(interceptor) - .order(1) - .addPathPatterns("/swagger-ui/**", "/v3/api-docs/**") - ); } @Override diff --git a/src/main/java/com/kri/common/runtime/webmvc/IpAccessControlInterceptor.java b/src/main/java/com/kri/common/runtime/webmvc/IpAccessControlInterceptor.java deleted file mode 100644 index 244ca3c..0000000 --- a/src/main/java/com/kri/common/runtime/webmvc/IpAccessControlInterceptor.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.kri.common.runtime.webmvc; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.web.servlet.HandlerInterceptor; - -@RequiredArgsConstructor -public class IpAccessControlInterceptor implements HandlerInterceptor { - - private final IpAccessControlService ipAccessControlService; - - @Override - public boolean preHandle(HttpServletRequest request, - HttpServletResponse response, - Object handler) throws Exception { - - String clientIpAddress = IpUtil.getClientIp(request); - if (!ipAccessControlService.isAccessible(clientIpAddress)) { - response.sendError(HttpServletResponse.SC_FORBIDDEN); - return false; - } - - return true; - } -} \ No newline at end of file diff --git a/src/main/java/com/kri/common/runtime/webmvc/IpAccessControlService.java b/src/main/java/com/kri/common/runtime/webmvc/IpAccessControlService.java deleted file mode 100644 index fa6cbaa..0000000 --- a/src/main/java/com/kri/common/runtime/webmvc/IpAccessControlService.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.kri.common.runtime.webmvc; - -import com.kri.common.autoconfigure.webmvc.KriIpAccessProperties; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.security.web.util.matcher.IpAddressMatcher; - -@RequiredArgsConstructor -public class IpAccessControlService { - - private final KriIpAccessProperties properties; - - public boolean isAccessible(String ipAddress) { - List cidrs = properties.getEffectiveCidrs(); - - return cidrs.stream() - .map(IpAddressMatcher::new) - .anyMatch(matcher -> matcher.matches(ipAddress)); - } -}