You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/04/19 04:04:29 UTC
[james-project] 38/49: JAMES-3737 IMAP: Reactify LIST RIGHTS
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 8e13a4d93f9cf982da0d200e9c8bea353d227674
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Apr 5 09:34:21 2022 +0700
JAMES-3737 IMAP: Reactify LIST RIGHTS
---
.../org/apache/james/mailbox/RightManager.java | 2 +
.../james/mailbox/store/StoreRightManager.java | 6 ++
.../james/imap/processor/ListRightsProcessor.java | 114 +++++++++++----------
3 files changed, 66 insertions(+), 56 deletions(-)
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
index b8e627d7f9..2eb2a2721d 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/RightManager.java
@@ -85,6 +85,8 @@ public interface RightManager {
*/
List<MailboxACL.Rfc4314Rights> listRights(MailboxPath mailboxPath, MailboxACL.EntryKey identifier, MailboxSession session) throws MailboxException;
+ List<MailboxACL.Rfc4314Rights> listRights(Mailbox mailbox, MailboxACL.EntryKey identifier, MailboxSession session) throws MailboxException;
+
MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException;
MailboxACL listRights(MailboxId mailboxId, MailboxSession session) throws MailboxException;
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index 319d353873..9c168e15af 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -134,6 +134,12 @@ public class StoreRightManager implements RightManager {
mailbox.getUser().asString());
}
+ @Override
+ public List<Rfc4314Rights> listRights(Mailbox mailbox, EntryKey key, MailboxSession session) throws MailboxException {
+ return aclResolver.listRights(key,
+ mailbox.getUser().asString());
+ }
+
@Override
public MailboxACL listRights(MailboxPath mailboxPath, MailboxSession session) throws MailboxException {
MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
index c2b7a6f556..d47a4171f9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
@@ -43,8 +43,11 @@ import org.apache.james.util.MDCBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.github.fge.lambdas.Throwing;
import com.google.common.collect.ImmutableList;
+import reactor.core.publisher.Mono;
+
/**
* LISTRIGHTS Processor.
*/
@@ -59,67 +62,66 @@ public class ListRightsProcessor extends AbstractMailboxProcessor<ListRightsRequ
}
@Override
- protected void processRequest(ListRightsRequest request, ImapSession session, Responder responder) {
-
- final MailboxManager mailboxManager = getMailboxManager();
- final MailboxSession mailboxSession = session.getMailboxSession();
- final String mailboxName = request.getMailboxName();
- final String identifier = request.getIdentifier();
- try {
+ protected Mono<Void> processRequestReactive(ListRightsRequest request, ImapSession session, Responder responder) {
+ MailboxManager mailboxManager = getMailboxManager();
+ MailboxSession mailboxSession = session.getMailboxSession();
+ String mailboxName = request.getMailboxName();
+ String identifier = request.getIdentifier();
+ MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(mailboxName);
- MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(mailboxName);
- // Check that mailbox exists
- mailboxManager.getMailbox(mailboxPath, mailboxSession);
-
- /*
- * RFC 4314 section 6.
- * An implementation MUST make sure the ACL commands themselves do
- * not give information about mailboxes with appropriately
- * restricted ACLs. For example, when a user agent executes a GETACL
- * command on a mailbox that the user has no permission to LIST, the
- * server would respond to that request with the same error that
- * would be used if the mailbox did not exist, thus revealing no
- * existence information, much less the mailbox’s ACL.
- */
- if (!mailboxManager.hasRight(mailboxPath, MailboxACL.Right.Lookup, mailboxSession)) {
- no(request, responder, HumanReadableText.MAILBOX_NOT_FOUND);
- } else if (!mailboxManager.hasRight(mailboxPath, MailboxACL.Right.Administer, mailboxSession)) {
- /* RFC 4314 section 4. */
- Object[] params = new Object[] {
+ return Mono.from(mailboxManager.getMailboxReactive(mailboxPath, mailboxSession))
+ .doOnNext(Throwing.consumer(mailbox -> {
+ /*
+ * RFC 4314 section 6.
+ * An implementation MUST make sure the ACL commands themselves do
+ * not give information about mailboxes with appropriately
+ * restricted ACLs. For example, when a user agent executes a GETACL
+ * command on a mailbox that the user has no permission to LIST, the
+ * server would respond to that request with the same error that
+ * would be used if the mailbox did not exist, thus revealing no
+ * existence information, much less the mailbox’s ACL.
+ */
+ if (!mailboxManager.hasRight(mailbox.getMailboxEntity(), MailboxACL.Right.Lookup, mailboxSession)) {
+ no(request, responder, HumanReadableText.MAILBOX_NOT_FOUND);
+ } else if (!mailboxManager.hasRight(mailbox.getMailboxEntity(), MailboxACL.Right.Administer, mailboxSession)) {
+ /* RFC 4314 section 4. */
+ Object[] params = new Object[] {
MailboxACL.Right.Administer.toString(),
request.getCommand().getName(),
mailboxName
- };
- HumanReadableText text = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
- no(request, responder, text);
- } else {
-
- EntryKey key = EntryKey.deserialize(identifier);
-
- // FIXME check if identifier is a valid user or group
- // FIXME Servers, when processing a command that has an identifier as a
- // parameter (i.e., any of SETACL, DELETEACL, and LISTRIGHTS commands),
- // SHOULD first prepare the received identifier using "SASLprep" profile
- // [SASLprep] of the "stringprep" algorithm [Stringprep]. If the
- // preparation of the identifier fails or results in an empty string,
- // the server MUST refuse to perform the command with a BAD response.
- // Note that Section 6 recommends additional identifier’s verification
- // steps.
-
- List<Rfc4314Rights> rights = mailboxManager.listRights(mailboxPath, key, mailboxSession);
- ListRightsResponse aclResponse = new ListRightsResponse(mailboxName, identifier, rights);
- responder.respond(aclResponse);
- okComplete(request, responder);
- // FIXME should we send unsolicited responses here?
- // unsolicitedResponses(session, responder, false);
- }
- } catch (MailboxNotFoundException e) {
- no(request, responder, HumanReadableText.MAILBOX_NOT_FOUND);
- } catch (MailboxException e) {
- LOGGER.error("{} failed for mailbox {}", request.getCommand().getName(), mailboxName, e);
- no(request, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
- }
+ };
+ HumanReadableText text = new HumanReadableText(HumanReadableText.UNSUFFICIENT_RIGHTS_KEY, HumanReadableText.UNSUFFICIENT_RIGHTS_DEFAULT_VALUE, params);
+ no(request, responder, text);
+ } else {
+ EntryKey key = EntryKey.deserialize(identifier);
+
+ // FIXME check if identifier is a valid user or group
+ // FIXME Servers, when processing a command that has an identifier as a
+ // parameter (i.e., any of SETACL, DELETEACL, and LISTRIGHTS commands),
+ // SHOULD first prepare the received identifier using "SASLprep" profile
+ // [SASLprep] of the "stringprep" algorithm [Stringprep]. If the
+ // preparation of the identifier fails or results in an empty string,
+ // the server MUST refuse to perform the command with a BAD response.
+ // Note that Section 6 recommends additional identifier’s verification
+ // steps.
+
+ List<Rfc4314Rights> rights = mailboxManager.listRights(mailbox.getMailboxEntity(), key, mailboxSession);
+ ListRightsResponse aclResponse = new ListRightsResponse(mailboxName, identifier, rights);
+ responder.respond(aclResponse);
+ okComplete(request, responder);
+ }
+ }))
+ .onErrorResume(MailboxNotFoundException.class, e -> {
+ no(request, responder, HumanReadableText.MAILBOX_NOT_FOUND);
+ return Mono.empty();
+ })
+ .onErrorResume(MailboxException.class, e -> {
+ LOGGER.error("{} failed for mailbox {}", request.getCommand().getName(), mailboxName, e);
+ no(request, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
+ return Mono.empty();
+ })
+ .then();
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org