james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [2/2] james-project git commit: JAMES-1854 Rely more on UserRepository::getUser(MailAddress)
Date Thu, 05 Apr 2018 13:37:36 GMT
JAMES-1854 Rely more on UserRepository::getUser(MailAddress)

This limits virtualHosting knowledge spreading in the code base


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/34b2f98c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/34b2f98c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/34b2f98c

Branch: refs/heads/master
Commit: 34b2f98c82210d4354f7cf4df691716391a4c0f2
Parents: 5fbaeba
Author: benwa <btellier@linagora.com>
Authored: Tue Apr 3 09:26:44 2018 +0700
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Thu Apr 5 15:32:08 2018 +0200

----------------------------------------------------------------------
 .../james/transport/mailets/AbstractSign.java   |  5 +---
 ...tSenderAuthIdentifyVerificationRcptHook.java | 27 +++++++++-----------
 .../hook/MailboxDeliverToRecipientHandler.java  |  8 +-----
 .../SenderAuthIdentifyVerificationRcptHook.java |  6 ++---
 .../smtpserver/fastfail/ValidRcptHandler.java   |  7 +----
 5 files changed, 18 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/34b2f98c/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
----------------------------------------------------------------------
diff --git a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
index 8b266a9..a81f1e6 100644
--- a/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
+++ b/mailet/crypto/src/main/java/org/apache/james/transport/mailets/AbstractSign.java
@@ -605,10 +605,7 @@ public abstract class AbstractSign extends GenericMailet {
 
     private String getUsername(MailAddress mailAddress) {
         try {
-            if (usersRepository.supportVirtualHosting()) {
-                return mailAddress.asString();
-            }
-            return mailAddress.getLocalPart();
+            return usersRepository.getUser(mailAddress);
         } catch (UsersRepositoryException e) {
             throw Throwables.propagate(e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34b2f98c/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
index 754df55..de3148e 100644
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
@@ -47,15 +47,7 @@ public abstract class AbstractSenderAuthIdentifyVerificationRcptHook implements
             String authUser = (session.getUser()).toLowerCase(Locale.US);
             MailAddress senderAddress = (MailAddress) session.getAttachment(
                     SMTPSession.SENDER, ProtocolSession.State.Transaction);
-            String username = null;
-
-            if (senderAddress != null && !sender.isNullSender()) {
-                if (useVirtualHosting()) {
-                    username = senderAddress.asString();
-                } else {
-                    username = senderAddress.getLocalPart();
-                }
-            }
+            String username = retrieveSender(sender, senderAddress);
             
             // Check if the sender address is the same as the user which was used to authenticate.
             // Its important to ignore case here to fix JAMES-837. This is save todo because
if the handler is called
@@ -68,8 +60,14 @@ public abstract class AbstractSenderAuthIdentifyVerificationRcptHook implements
         }
         return HookResult.declined();
     }
-    
-    
+
+    public String retrieveSender(MailAddress sender, MailAddress senderAddress) {
+        if (senderAddress != null && !sender.isNullSender()) {
+            return getUser(senderAddress);
+        }
+        return null;
+    }
+
     /**
      * Return true if the given domain is a local domain for this server
      * 
@@ -79,11 +77,10 @@ public abstract class AbstractSenderAuthIdentifyVerificationRcptHook implements
     protected abstract boolean isLocalDomain(Domain domain);
     
     /**
-     * Return true if virtualHosting should get used. If so the full email address will get
used to 
-     * match against the supplied auth username
+     * Return the username corresponding to the given mail address.
      * 
-     * @return useVirtualHosting
+     * @return username corresponding to the mail address
      */
-    protected abstract boolean useVirtualHosting();
+    protected abstract String getUser(MailAddress mailAddress);
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34b2f98c/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
index 9a300ec..7d52a3a 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
@@ -69,16 +69,10 @@ public class MailboxDeliverToRecipientHandler implements DeliverToRecipientHook
     
     @Override
     public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelope envelope)
{
-        String username;
         HookResult result;
 
         try {
-
-            if (users.supportVirtualHosting()) {
-                username = recipient.toString();
-            } else {
-                username = recipient.getLocalPart();
-            }
+            String username = users.getUser(recipient);
 
             MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
             MailboxPath inbox = MailboxPath.inbox(mailboxSession);

http://git-wip-us.apache.org/repos/asf/james-project/blob/34b2f98c/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
index db00d42..53028a9 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java
@@ -83,12 +83,12 @@ public class SenderAuthIdentifyVerificationRcptHook extends AbstractSenderAuthId
     }
 
     @Override
-    protected boolean useVirtualHosting() {
+    protected String getUser(MailAddress mailAddress) {
         try {
-            return users.supportVirtualHosting();
+            return users.getUser(mailAddress);
         } catch (UsersRepositoryException e) {
             throw Throwables.propagate(e);
         }
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/34b2f98c/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
index d79ac4c..0dddccf 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java
@@ -94,15 +94,10 @@ public class ValidRcptHandler extends AbstractValidRcptHandler implements
Protoc
 
     @Override
     protected boolean isValidRecipient(SMTPSession session, MailAddress recipient) {
-
-        String username = recipient.toString();
-
         // check if the server use virtualhosting, if not use only the localpart
         // as username
         try {
-            if (!users.supportVirtualHosting()) {
-                username = recipient.getLocalPart();
-            }
+            String username = users.getUser(recipient);
 
             if (users.contains(username)) {
                 return true;


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message