Class IpAllowlist
java.lang.Object
eu.cloudnetservice.node.impl.util.IpAllowlist
An allowlist for IP addresses that is able to parse and process subnets and static IP addresses.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final recordAn allowlist entry that was parsed from a subnet. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Collection<IpAllowlist.ParsedAllowlistEntry> private static final org.slf4j.Loggerprivate final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateIpAllowlist(int originalAllowlistHashCode, @NonNull Collection<IpAllowlist.ParsedAllowlistEntry> entries) Constructs a new allowlist instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanallows(@NonNull InetAddress address) Checks if the given address is allowed by an entry of this allowlist.static @NonNull IpAllowlistparse(@NonNull Collection<String> allowlist) Parses an allowlist from the given collection of subnets or static ip addresses.updateIfNecessary(@NonNull Collection<String> allowList) Updates this allowlist instance if the given allowlist is different from the original allowlist that was used to construct this instance.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
originalAllowlistHashCode
private final int originalAllowlistHashCode -
entries
-
-
Constructor Details
-
IpAllowlist
private IpAllowlist(int originalAllowlistHashCode, @NonNull @NonNull Collection<IpAllowlist.ParsedAllowlistEntry> entries) Constructs a new allowlist instance. For internal use only, useparse(Collection)instead.- Parameters:
originalAllowlistHashCode- the hashcode of the original allowlist that was parsed.entries- the entries of the newly constructed allowlist.- Throws:
NullPointerException- if the given entries collection is null.
-
-
Method Details
-
parse
Parses an allowlist from the given collection of subnets or static ip addresses. All null entries are ignored, for invalid entries a warning log message is printed.- Parameters:
allowlist- the allowlist to parse.- Returns:
- a new allowlist instance based on the parsed given allowlist.
- Throws:
NullPointerException- if the given allowlist is null.
-
updateIfNecessary
@CheckReturnValue @NonNull public @NonNull IpAllowlist updateIfNecessary(@NonNull @NonNull Collection<String> allowList) Updates this allowlist instance if the given allowlist is different from the original allowlist that was used to construct this instance. If the given allowlist is the same as the original allowlist, this instance is returned. Otherwise, a new instance is created for the given allowlist and returned instead.- Parameters:
allowList- the allowlist to check for changes and return a new instance for, if necessary.- Returns:
- a new allowlist if the given allowlist is different from the original allowlist, otherwise this instance.
- Throws:
NullPointerException- if the given allowlist is null.
-
allows
Checks if the given address is allowed by an entry of this allowlist.- Parameters:
address- the address to check.- Returns:
- true if the given address is allowed, false otherwise.
- Throws:
NullPointerException- if the given address is null.
-