Files
common-library/src/main/java/com/kri/common/webmvc/IpAccessControlService.java

21 lines
546 B
Java

package com.kri.common.webmvc;
import lombok.RequiredArgsConstructor;
import org.springframework.security.web.util.matcher.IpAddressMatcher;
import java.util.List;
@RequiredArgsConstructor
public class IpAccessControlService {
private final KriIpAccessProperties properties;
public boolean isAccessible(String ipAddress) {
List<String> cidrs = properties.getEffectiveCidrs();
return cidrs.stream()
.map(IpAddressMatcher::new)
.anyMatch(matcher -> matcher.matches(ipAddress));
}
}