Browse code

BM-15261 Fix: round2, owner was wrong

Thomas Cataldo authored on 08/10/2019 14:56:18
Showing 2 changed files
... ...
@@ -154,6 +154,9 @@ public class ImapContext {
154 154
 
155 155
 	public static ImapContext of(BmContext context) {
156 156
 		String key = context.getSecurityContext().getSessionId();
157
+		if (key == null) {
158
+			throw new ServerFault("ImapContext requires a non null sessionId ctx: " + context.getSecurityContext());
159
+		}
157 160
 		ImapContext imapCtx = sidToCtxCache.getIfPresent(key);
158 161
 		if (imapCtx == null) {
159 162
 			if (logger.isDebugEnabled()) {
... ...
@@ -88,12 +88,18 @@ public class MapiMailboxService implements IMapiMailbox {
88 88
 	private void checkFaiContainer(MapiReplica replica) {
89 89
 		String faiContainerId = MapiFAIContainer.getIdentifier(replica);
90 90
 		ContainerDescriptor fais = ContainerDescriptor.create(faiContainerId, faiContainerId,
91
-				context.getSecurityContext().getSubject(), MapiFAIContainer.TYPE, domainUid, true);
92
-		IContainers contApi = context.provider().instance(IContainers.class);
91
+				pfMailbox ? PublicFolders.mailboxGuid(domainUid) : context.getSecurityContext().getSubject(),
92
+				MapiFAIContainer.TYPE, domainUid, true);
93
+		IContainers contApi = context.su().provider().instance(IContainers.class);
93 94
 		ContainerDescriptor current = contApi.getIfPresent(faiContainerId);
95
+		if (current != null && !current.owner.equals(fais.owner)) {
96
+			logger.info("Reset FAI container {} as owner is wrong", faiContainerId);
97
+			contApi.delete(faiContainerId);
98
+			current = null;
99
+		}
94 100
 		if (current == null) {
95 101
 			contApi.create(faiContainerId, fais);
96
-			logger.info("Created container {}", faiContainerId);
102
+			logger.info("Created FAI container {}", faiContainerId);
97 103
 		}
98 104
 		if (pfMailbox) {
99 105
 			logger.info("Setting domain-wide {} ACLs for PF FAI folder {}", domainUid, faiContainerId);