You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2023/11/30 02:47:01 UTC
(james-project) 02/03: JAMES-3964 Implement and test disabledCaps for SMTP
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 0b40e17d1e1ca2b601a7a82c1a234602e4886764
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Tue Nov 28 15:59:36 2023 +0100
JAMES-3964 Implement and test disabledCaps for SMTP
---
.../james/protocols/smtp/SMTPConfiguration.java | 7 +++
.../apache/james/protocols/smtp/SMTPSession.java | 7 +++
.../protocols/smtp/core/esmtp/EhloCmdHandler.java | 7 ++-
.../james/smtpserver/ExtendedSMTPSession.java | 7 +++
.../apache/james/smtpserver/netty/SMTPServer.java | 11 +++++
.../test/resources/smtpserver-disabled-feature.xml | 51 ++++++++++++++++++++++
6 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPConfiguration.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPConfiguration.java
index acbf2dc604..b2c9ac0704 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPConfiguration.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPConfiguration.java
@@ -22,10 +22,13 @@
package org.apache.james.protocols.smtp;
import java.util.Optional;
+import java.util.Set;
import org.apache.james.protocols.api.OidcSASLConfiguration;
import org.apache.james.protocols.api.ProtocolConfiguration;
+import com.google.common.collect.ImmutableSet;
+
/**
* Provides a number of server-wide constant values to the
@@ -77,4 +80,8 @@ public interface SMTPConfiguration extends ProtocolConfiguration {
Optional<OidcSASLConfiguration> saslConfiguration();
+ default Set<String> disabledFeatures() {
+ return ImmutableSet.of();
+ }
+
}
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSession.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSession.java
index 595f06c352..3075629e86 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSession.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSession.java
@@ -20,11 +20,14 @@
package org.apache.james.protocols.smtp;
import java.util.List;
+import java.util.Set;
import org.apache.james.core.MailAddress;
import org.apache.james.core.MaybeSender;
import org.apache.james.protocols.api.ProtocolSession;
+import com.google.common.collect.ImmutableSet;
+
/**
* All the handlers access this interface to communicate with
* SMTPHandler object
@@ -93,5 +96,9 @@ public interface SMTPSession extends ProtocolSession {
void setMessageFailed(boolean value);
+ default Set<String> disabledFeatures() {
+ return ImmutableSet.of();
+ }
+
}
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
index dc78bdd54c..590fdbba5a 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java
@@ -37,6 +37,7 @@ import org.apache.james.protocols.smtp.hook.HookResult;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
/**
* Handles EHLO command
@@ -159,12 +160,16 @@ public class EhloCmdHandler extends AbstractHookableCmdHandler<HeloHook> impleme
@Override
public List<String> getImplementedEsmtpFeatures(SMTPSession session) {
- return ImmutableList.<String>builder()
+ ImmutableSet<String> esmtpFeatures = ImmutableSet.<String>builder()
.addAll(ESMTP_FEATURES)
.addAll(getHooks().stream()
.flatMap(heloHook -> heloHook.implementedEsmtpFeatures(session).stream())
.collect(ImmutableList.toImmutableList()))
.build();
+
+ return ImmutableList.copyOf(
+ Sets.difference(esmtpFeatures,
+ session.disabledFeatures()));
}
}
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/ExtendedSMTPSession.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/ExtendedSMTPSession.java
index 651b4434ab..4c7c5c73cb 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/ExtendedSMTPSession.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/ExtendedSMTPSession.java
@@ -18,6 +18,8 @@
****************************************************************/
package org.apache.james.smtpserver;
+import java.util.Set;
+
import org.apache.james.lifecycle.api.LifecycleUtil;
import org.apache.james.protocols.api.ProtocolTransport;
import org.apache.james.protocols.smtp.SMTPConfiguration;
@@ -42,6 +44,11 @@ public class ExtendedSMTPSession extends org.apache.james.protocols.smtp.SMTPSes
return !(smtpConfiguration instanceof SMTPHandlerConfigurationDataImpl) || ((SMTPHandlerConfigurationDataImpl) smtpConfiguration).verifyIdentity();
}
+ @Override
+ public Set<String> disabledFeatures() {
+ return smtpConfiguration.disabledFeatures();
+ }
+
public MimeMessageInputStreamSource getMimeMessageWriter() {
return mimeMessageInputStreamSource;
}
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
index 359880b7e8..4e9413eb57 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
@@ -24,6 +24,7 @@ import static org.apache.james.smtpserver.netty.SMTPServer.AuthenticationAnnounc
import java.net.MalformedURLException;
import java.util.Locale;
import java.util.Optional;
+import java.util.Set;
import javax.inject.Inject;
@@ -49,6 +50,8 @@ import org.apache.james.util.Size;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.ImmutableSet;
+
import io.netty.channel.ChannelInboundHandlerAdapter;
/**
@@ -180,6 +183,7 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
*/
private final SMTPConfiguration theConfigData = new SMTPHandlerConfigurationDataImpl();
private final SmtpMetrics smtpMetrics;
+ private Set<String> disabledFeatures = ImmutableSet.of();
private boolean addressBracketsEnforcement = true;
@@ -244,6 +248,8 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
addressBracketsEnforcement = configuration.getBoolean("addressBracketsEnforcement", true);
verifyIdentity = configuration.getBoolean("verifyIdentity", true);
+
+ disabledFeatures = ImmutableSet.copyOf(configuration.getStringArray("disabledFeatures"));
}
}
@@ -336,6 +342,11 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
public Optional<OidcSASLConfiguration> saslConfiguration() {
return authenticationConfiguration.getSaslConfiguration();
}
+
+ @Override
+ public Set<String> disabledFeatures() {
+ return disabledFeatures;
+ }
}
@Override
diff --git a/server/protocols/protocols-smtp/src/test/resources/smtpserver-disabled-feature.xml b/server/protocols/protocols-smtp/src/test/resources/smtpserver-disabled-feature.xml
new file mode 100644
index 0000000000..a4913c3cc2
--- /dev/null
+++ b/server/protocols/protocols-smtp/src/test/resources/smtpserver-disabled-feature.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+<!-- Read https://james.apache.org/server/config-smtp-lmtp.html#SMTP_Configuration for further details -->
+
+<smtpserver enabled="true">
+ <bind>0.0.0.0:0</bind>
+ <connectionBacklog>200</connectionBacklog>
+ <tls socketTLS="false" startTLS="false">
+ <keystore>file://conf/keystore</keystore>
+ <secret>james72laBalle</secret>
+ <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider>
+ <algorithm>SunX509</algorithm>
+ </tls>
+ <connectiontimeout>360</connectiontimeout>
+ <connectionLimit>0</connectionLimit>
+ <connectionLimitPerIP>0</connectionLimitPerIP>
+ <auth>
+ <announce>forUnauthorizedAddresses</announce>
+ <requireSSL>false</requireSSL>
+ </auth>
+ <verifyIdentity>true</verifyIdentity>
+ <maxmessagesize>0</maxmessagesize>
+ <addressBracketsEnforcement>true</addressBracketsEnforcement>
+ <smtpGreeting>Apache JAMES awesome SMTP Server</smtpGreeting>
+ <handlerchain>
+ <handler class="org.apache.james.smtpserver.futurerelease.FutureReleaseEHLOHook"/>
+ <handler class="org.apache.james.smtpserver.futurerelease.FutureReleaseMailParameterHook"/>
+ <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/>
+ </handlerchain>
+ <gracefulShutdown>false</gracefulShutdown>
+ <disabledFeatures>ENHANCEDSTATUSCODES</disabledFeatures>
+</smtpserver>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org