This is an automated email from the ASF dual-hosted git repository. jhelou pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit a6617039ab154058ada7d21a6e31367b3078547e Author: Jean Helou <j...@codamens.fr> AuthorDate: Sun Feb 11 22:34:38 2024 +0100 [JAMES-3897] refactors ehlo hook to use crowdsec service --- .../java/org/apache/james/crowdsec/CrowdsecEhloHook.java | 16 ++++++---------- .../org/apache/james/crowdsec/CrowdsecEhloHookTest.java | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/third-party/crowdsec/src/main/java/org/apache/james/crowdsec/CrowdsecEhloHook.java b/third-party/crowdsec/src/main/java/org/apache/james/crowdsec/CrowdsecEhloHook.java index a04e35b14a..d8c856d2ec 100644 --- a/third-party/crowdsec/src/main/java/org/apache/james/crowdsec/CrowdsecEhloHook.java +++ b/third-party/crowdsec/src/main/java/org/apache/james/crowdsec/CrowdsecEhloHook.java @@ -19,37 +19,33 @@ package org.apache.james.crowdsec; -import static org.apache.james.crowdsec.CrowdsecUtils.isBanned; - import java.util.List; import javax.inject.Inject; import org.apache.james.crowdsec.client.CrowdsecClientConfiguration; -import org.apache.james.crowdsec.client.CrowdsecHttpClient; import org.apache.james.crowdsec.model.CrowdsecDecision; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HeloHook; import org.apache.james.protocols.smtp.hook.HookResult; public class CrowdsecEhloHook implements HeloHook { - private final CrowdsecHttpClient crowdsecHttpClient; + private final CrowdsecService crowdsecService; @Inject public CrowdsecEhloHook(CrowdsecClientConfiguration configuration) { - this.crowdsecHttpClient = new CrowdsecHttpClient(configuration); + this.crowdsecService = new CrowdsecService(configuration); } @Override public HookResult doHelo(SMTPSession session, String helo) { - String ip = session.getRemoteAddress().getAddress().getHostAddress(); - return crowdsecHttpClient.getCrowdsecDecisions() - .map(decisions -> apply(decisions, ip)).block(); + return crowdsecService.findBanDecisions(session.getRemoteAddress()) + .map(this::apply) + .block(); } - private HookResult apply(List<CrowdsecDecision> decisions, String ip) { + private HookResult apply(List<CrowdsecDecision> decisions) { return decisions.stream() - .filter(decision -> isBanned(decision, ip)) .findFirst() .map(banned -> HookResult.DENY) .orElse(HookResult.DECLINED); diff --git a/third-party/crowdsec/src/test/java/org/apache/james/crowdsec/CrowdsecEhloHookTest.java b/third-party/crowdsec/src/test/java/org/apache/james/crowdsec/CrowdsecEhloHookTest.java index 4033d240a0..d0041d0e9f 100644 --- a/third-party/crowdsec/src/test/java/org/apache/james/crowdsec/CrowdsecEhloHookTest.java +++ b/third-party/crowdsec/src/test/java/org/apache/james/crowdsec/CrowdsecEhloHookTest.java @@ -78,6 +78,6 @@ class CrowdsecEhloHookTest { } private static void banIP(String type, String value) throws IOException, InterruptedException { - crowdsecExtension.getCrowdsecContainer().execInContainer("cscli", "decision", "add", type, value); + crowdsecExtension.banIP(type, value); } } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org