260626_03_ENH: admin용 swagger 안뜨던 문제 수정

This commit is contained in:
2026-06-26 15:52:25 +09:00
parent c36f53bd5f
commit 11eaca9197
4 changed files with 31 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
// 버전 변경은 여기서
def commonVer = "beta.1.1.31"
def commonVer = "beta.1.1.32"
group = 'com.kri.common'
version = commonVer

View File

@@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@AutoConfiguration
@AutoConfiguration(after = ApiKeyJpaAutoConfiguration.class)
@EnableConfigurationProperties(ApiKeyProperties.class)
@ConditionalOnProperty(prefix = "kri.auth.apikey", name = "enabled", havingValue = "true")
public class ApiKeyPreloadAutoConfiguration {

View File

@@ -10,6 +10,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "kri.auth.apikey")
public class ApiKeyProperties {
public static final List<String> DEFAULT_ADMIN_ALLOW_IPS = List.of(
"127.0.0.1/32",
"localhost",
"0:0:0:0:0:0:0:1"
);
/**
* API Key 인증 허용 여부
*/
@@ -38,10 +44,7 @@ public class ApiKeyProperties {
/**
* 내부 관리 API 접근 허용 IP(CIDR)
*/
private List<String> adminAllowIps = List.of(
"127.0.0.1/32",
"0:0:0:0:0:0:0:1"
);
private List<String> adminAllowIps = DEFAULT_ADMIN_ALLOW_IPS;
/**
* apikey 전용 DB 설정(기본값 포함)
@@ -80,4 +83,4 @@ public class ApiKeyProperties {
private String password = "it#51304";
private String driverClassName = "com.mysql.cj.jdbc.Driver";
}
}
}

View File

@@ -5,10 +5,13 @@ import com.kri.common.feature.auth.dto.JwtUserClaimsDto;
import com.kri.common.runtime.auth.apikey.PreloadedApiKeyUserClaimsProvider;
import com.kri.common.runtime.web.IpUtil;
import jakarta.servlet.http.HttpServletRequest;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.http.HttpStatus;
import org.springframework.security.web.util.matcher.IpAddressMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,12 +24,18 @@ public class ApiKeyAdminController {
private final ApiKeyProperties props;
private final PreloadedApiKeyUserClaimsProvider provider;
private final List<IpAddressMatcher> allow;
private final List<String> allow;
public ApiKeyAdminController(ApiKeyProperties props, PreloadedApiKeyUserClaimsProvider provider) {
this.props = props;
this.provider = provider;
this.allow = props.getAdminAllowIps().stream().map(IpAddressMatcher::new).toList();
Set<String> allowIps = new LinkedHashSet<>(ApiKeyProperties.DEFAULT_ADMIN_ALLOW_IPS);
if (props.getAdminAllowIps() != null) {
allowIps.addAll(props.getAdminAllowIps());
}
this.allow = allowIps.stream()
.filter(StringUtils::hasText)
.toList();
}
@PostMapping("/reload")
@@ -53,12 +62,21 @@ public class ApiKeyAdminController {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
String remote = IpUtil.getClientIp(req);
boolean ok = allow.stream().anyMatch(m -> m.matches(remote));
boolean ok = allow.stream().anyMatch(allowed -> matches(remote, allowed));
if (!ok) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "IP not allowed: " + remote);
}
}
private boolean matches(String remote, String allowed) {
if ("localhost".equalsIgnoreCase(allowed)) {
return "localhost".equalsIgnoreCase(remote)
|| "127.0.0.1".equals(remote)
|| "0:0:0:0:0:0:0:1".equals(remote);
}
return new IpAddressMatcher(allowed).matches(remote);
}
private String mask(String raw) {
if (raw == null) {
return "";