Skip to content

Commit 3cecdf1

Browse files
JAMES-2182 IMAP processors should catch InsufficientRightsException
Otherwise, that exception won't be caught and result in this error log: ``` [ERROR] o.a.j.i.p.AbstractMailboxProcessor - Unexpected error during IMAP processing org.apache.james.mailbox.exception.InsufficientRightsException: user '[email protected]' is not allowed to delete the mailbox '#private:[email protected]:sharedMailbox.child1' ``` While it is a client side error.
1 parent d7e73bd commit 3cecdf1

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/RenameSharedMailbox.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ C: a2 MYRIGHTS #user.boby.sharedMailbox.child2-eiklprstw
4646
S: \* MYRIGHTS \"#user.boby.sharedMailbox.child2-eiklprstw\" \"eiklprstw\"
4747
S: a2 OK MYRIGHTS completed.
4848
C: a3 RENAME #user.boby.sharedMailbox.child2-eiklprstw #user.boby.sharedMailbox.newChild2
49-
S: a3 NO RENAME processing failed.
49+
S: a3 NO RENAME failed. Insufficient rights.
5050

5151
# Cannot rename a shared mailbox if the parent of the target mailbox lacks the "create mailbox" right
5252
C: a4 MYRIGHTS #user.boby.sharedMailbox-eilprstwx
5353
S: \* MYRIGHTS \"#user.boby.sharedMailbox-eilprstwx\" \"eilprstwx\"
5454
S: a4 OK MYRIGHTS completed.
5555
C: a5 RENAME #user.boby.sharedMailbox.child1-eiklprstwx #user.boby.sharedMailbox-eilprstwx.newChild1
56-
S: a5 NO RENAME processing failed.
56+
S: a5 NO RENAME failed. Insufficient rights.
5757

5858
# Cannot rename a mailbox to an existing mailbox name
5959
C: a52 RENAME #user.boby.sharedMailbox.child1-eiklprstwx #user.boby.sharedMailbox.child2-eiklprstw

protocols/imap/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ public static HumanReadableText permanentFlags(Flags flags) {
182182
public static final String UNSUFFICIENT_RIGHTS_DEFAULT_VALUE = "You need the {0} right to perform command {1} on mailbox {2}.";
183183
public static final String UNSUFFICIENT_RIGHTS_KEY = "org.apache.james.imap.UNSUFFICIENT_RIGHTS";
184184

185+
public static final HumanReadableText UNSUFFICIENT_RIGHTS = new HumanReadableText(UNSUFFICIENT_RIGHTS_KEY, "failed. Insufficient rights.");
186+
185187
public static final String UNSUPPORTED_RIGHT_KEY = "org.apache.james.imap.UNSUPPORTED_RIGHT";
186188
public static final String UNSUPPORTED_RIGHT_DEFAULT_VALUE = "The {0} right is not supported.";
187189

protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.james.mailbox.MessageUid;
5858
import org.apache.james.mailbox.ModSeq;
5959
import org.apache.james.mailbox.NullableMessageSequenceNumber;
60+
import org.apache.james.mailbox.exception.InsufficientRightsException;
6061
import org.apache.james.mailbox.exception.MailboxException;
6162
import org.apache.james.mailbox.exception.MessageRangeException;
6263
import org.apache.james.mailbox.exception.OverQuotaException;
@@ -100,6 +101,10 @@ protected final Mono<Void> doProcess(R acceptableMessage, Responder responder, I
100101
no(acceptableMessage, responder, HumanReadableText.DENIED_SHARED_MAILBOX);
101102
return Mono.empty();
102103
})
104+
.onErrorResume(InsufficientRightsException.class, e -> {
105+
no(acceptableMessage, responder, HumanReadableText.UNSUFFICIENT_RIGHTS);
106+
return ReactorUtils.logAsMono(() -> LOGGER.info("Processing failed due to insufficient rights", e));
107+
})
103108
.onErrorResume(OverQuotaException.class, e -> {
104109
no(acceptableMessage, responder, HumanReadableText.FAILURE_OVERQUOTA, StatusResponse.ResponseCode.overQuota());
105110
return ReactorUtils.logAsMono(() -> LOGGER.info("Processing failed due to quota restriction", e));

server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,7 @@ void renameShouldFailWhenInsufficientRightsOnSharedMailbox() throws Exception {
35733573
String response = testIMAPClient.sendCommand("RENAME #user.bobo.sharedMailbox.child1 #user.bobo.sharedMailbox.newChild");
35743574

35753575
// Assert that the operation fails due to insufficient rights
3576-
assertThat(response).contains("NO RENAME processing failed.");
3576+
assertThat(response).contains("NO RENAME failed. Insufficient rights.");
35773577
}
35783578
}
35793579

0 commit comments

Comments
 (0)