@@ -73,6 +73,20 @@ public class BlockList { | |||||
return decision; | return decision; | ||||
} | } | ||||
public BlockDecision getFqdnDecision(String fqdn) { | |||||
for (BlockSpec allow : whitelist) { | |||||
if (allow.matchesFqdn(fqdn)) return BlockDecision.ALLOW; | |||||
} | |||||
final BlockDecision decision = new BlockDecision(); | |||||
for (BlockSpec block : blacklist) { | |||||
if (block.matchesFqdn(fqdn)) { | |||||
if (!block.hasSelector()) return BlockDecision.BLOCK; | |||||
decision.add(block); | |||||
} | |||||
} | |||||
return decision; | |||||
} | |||||
@JsonIgnore public Set<BlockSpec> getBlacklistDomains() { | @JsonIgnore public Set<BlockSpec> getBlacklistDomains() { | ||||
return blacklist.stream().filter(BlockSpec::hasNoSelector).collect(Collectors.toSet()); | return blacklist.stream().filter(BlockSpec::hasNoSelector).collect(Collectors.toSet()); | ||||
} | } | ||||
@@ -143,6 +143,18 @@ public class BlockSpec { | |||||
return false; | return false; | ||||
} | } | ||||
public boolean matchesFqdn(String fqdn) { | |||||
if (target.hasDomainRegex() && target.getDomainPattern().matcher(fqdn).find()) { | |||||
return checkDomainExclusionsAndType(fqdn, null); | |||||
} else if (target.hasRegex()) { | |||||
if (target.getRegexPattern().matcher(fqdn).find()) { | |||||
return checkDomainExclusionsAndType(fqdn, null); | |||||
}; | |||||
} | |||||
return false; | |||||
} | |||||
public boolean checkDomainExclusionsAndType(String fqdn, String contentType) { | public boolean checkDomainExclusionsAndType(String fqdn, String contentType) { | ||||
if (domainExclusions != null) { | if (domainExclusions != null) { | ||||
for (String domain : domainExclusions) { | for (String domain : domainExclusions) { | ||||