1package dev.rafex.ether.http.security.ip;
38public record
IpPolicy(List<String> allowList, List<String> denyList) {
41 allowList = allowList ==
null ? List.of() : List.copyOf(allowList);
42 denyList = denyList ==
null ? List.of() : List.copyOf(denyList);
46 return new IpPolicy(List.of(), List.of());
49 public boolean isAllowed(
final String
ip) {
50 if (
ip ==
null ||
ip.isBlank()) {
53 for (
final var deny : denyList) {
54 if (matches(deny,
ip)) {
58 if (allowList.isEmpty()) {
61 for (
final var allow : allowList) {
62 if (matches(allow,
ip)) {
69 private static boolean matches(
final String rule,
final String
ip) {
70 if (rule ==
null || rule.isBlank()) {
73 if (
"*".equals(rule)) {
76 return ip.equals(rule) ||
ip.startsWith(rule);
Client IP allow and deny policies.
record IpPolicy(List< String > allowList, List< String > denyList)
Política de control de acceso basada en direcciones IP.