quantranhong1999 commented on code in PR #3059:
URL: https://github.com/apache/james-project/pull/3059#discussion_r3425617400


##########
protocols/imap/src/main/java/org/apache/james/imap/processor/DefaultProcessor.java:
##########
@@ -136,6 +185,27 @@ public static ImapProcessor 
createDefaultProcessor(ImapProcessor chainEndProcess
         return new DefaultProcessor(processorMap, chainEndProcessor);
     }
 
+    private static JamesSaslAuthenticator 
jamesSaslAuthenticator(MailboxManager mailboxManager) {
+        Authenticator authenticator = (username, password) -> {
+            try {
+                return Optional.of(mailboxManager.authenticate(username, 
password.toString()).withoutDelegation().getUser());
+            } catch (BadCredentialsException e) {
+                return Optional.empty();
+            }
+        };
+        Authorizator authorizator = (username, otherUsername) -> {
+            try {
+                mailboxManager.authenticate(username).as(otherUsername);
+                return Authorizator.AuthorizationState.ALLOWED;
+            } catch (UserDoesNotExistException e) {
+                return Authorizator.AuthorizationState.UNKNOWN_USER;
+            } catch (ForbiddenDelegationException | BadCredentialsException e) 
{
+                return Authorizator.AuthorizationState.FORBIDDEN;
+            }
+        };
+        return new JamesSaslAuthenticator(authenticator, authorizator);
+    }

Review Comment:
   moved to `JamesSaslAuthenticator`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to