← Developers
Level 1: code Framework
Java: Spring AI
Spring AI function tools are methods. Guard those that reach the network.
Configuration and reference code for Java: Spring AI
Guard
SecurdGuard.java
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
public final class SecurdGuard {
private static final Set<String> BLOCK_ADDRS = Arrays.stream(
System.getenv().getOrDefault("SECURD_BLOCK_ADDRS", "").split(","))
.filter(s -> !s.isBlank()).collect(Collectors.toSet());
public static final class Held extends RuntimeException {
public Held(String msg) { super(msg); }
}
public static void check(String host, String agentRole) {
try {
for (InetAddress a : InetAddress.getAllByName(host)) {
if (BLOCK_ADDRS.contains(a.getHostAddress())) {
throw new Held(host + " is held or blocked for " + agentRole);
}
}
} catch (java.net.UnknownHostException e) {
throw new Held(host + " did not resolve inside " + agentRole);
}
}
}
Tool
Tools.java
@Bean
@Description("Fetch an approved URL")
public Function<String, String> fetchUrl(RestClient http) {
return url -> {
String host = URI.create(url).getHost();
try {
SecurdGuard.check(host, "billing-agent");
} catch (SecurdGuard.Held held) {
return "BLOCKED: " + held.getMessage();
}
return http.get().uri(url).retrieve().body(String.class);
};
}
Evaluate Agent DNS with your own agent traffic
Deploy on a single policy in learning mode and review the recorded destinations with your team.