Browse code

[mapi] BM-15261 Fix: create an FAI container for public folders replica as we saw outlook (with gpg addon) write in this

Thomas Cataldo authored on 08/10/2019 10:19:06
Showing 2 changed files
... ...
@@ -37,6 +37,12 @@ public class MapiReplicaStore extends JdbcAbstractStore {
37 37
 		super(dataSource);
38 38
 	}
39 39
 
40
+	/**
41
+	 * Upsert the given {@link MapiReplica}
42
+	 * 
43
+	 * @param value
44
+	 * @throws SQLException
45
+	 */
40 46
 	public void store(MapiReplica value) throws SQLException {
41 47
 		String query = "INSERT INTO t_mapi_replica (" + MapiReplicaColumns.cols.names() + ") VALUES ("
42 48
 				+ MapiReplicaColumns.cols.values() + ") ON CONFLICT (mailbox_uid) DO UPDATE SET ("
... ...
@@ -22,6 +22,7 @@ import java.sql.Connection;
22 22
 import java.sql.ResultSet;
23 23
 import java.sql.SQLException;
24 24
 import java.sql.Statement;
25
+import java.util.Arrays;
25 26
 import java.util.List;
26 27
 
27 28
 import org.slf4j.Logger;
... ...
@@ -30,10 +31,13 @@ import org.vertx.java.core.json.JsonObject;
30 31
 
31 32
 import net.bluemind.core.api.fault.ServerFault;
32 33
 import net.bluemind.core.container.api.ContainerQuery;
34
+import net.bluemind.core.container.api.IContainerManagement;
33 35
 import net.bluemind.core.container.api.IContainers;
34 36
 import net.bluemind.core.container.model.ContainerDescriptor;
35 37
 import net.bluemind.core.container.model.ItemUri;
36 38
 import net.bluemind.core.container.model.ItemValue;
39
+import net.bluemind.core.container.model.acl.AccessControlEntry;
40
+import net.bluemind.core.container.model.acl.Verb;
37 41
 import net.bluemind.core.jdbc.JdbcAbstractStore;
38 42
 import net.bluemind.core.rest.BmContext;
39 43
 import net.bluemind.exchange.mapi.api.IMapiFolderAssociatedInformation;
... ...
@@ -41,6 +45,7 @@ import net.bluemind.exchange.mapi.api.IMapiMailbox;
41 45
 import net.bluemind.exchange.mapi.api.MapiFAIContainer;
42 46
 import net.bluemind.exchange.mapi.api.MapiReplica;
43 47
 import net.bluemind.exchange.mapi.persistence.MapiReplicaStore;
48
+import net.bluemind.exchange.publicfolders.common.PublicFolders;
44 49
 import net.bluemind.hornetq.client.MQ;
45 50
 import net.bluemind.hornetq.client.Topic;
46 51
 import net.bluemind.user.api.IUser;
... ...
@@ -57,12 +62,15 @@ public class MapiMailboxService implements IMapiMailbox {
57 62
 
58 63
 	private String mailboxUid;
59 64
 
65
+	private boolean pfMailbox;
66
+
60 67
 	public MapiMailboxService(BmContext context, String domainUid, String mailboxUid) throws ServerFault {
61 68
 		this.context = context;
62 69
 		this.domainUid = domainUid;
63 70
 		this.mailboxUid = mailboxUid;
64 71
 		this.context = context;
65 72
 		this.mapiReplicaStore = new MapiReplicaStore(context.getDataSource());
73
+		this.pfMailbox = mailboxUid.equals(PublicFolders.mailboxGuid(domainUid));
66 74
 	}
67 75
 
68 76
 	@Override
... ...
@@ -70,17 +78,28 @@ public class MapiMailboxService implements IMapiMailbox {
70 78
 		replica.mailboxUid = this.mailboxUid;
71 79
 		try {
72 80
 			mapiReplicaStore.store(replica);
73
-
74
-			String faiContainerId = MapiFAIContainer.getIdentifier(replica);
75
-			ContainerDescriptor fais = ContainerDescriptor.create(faiContainerId, faiContainerId,
76
-					context.getSecurityContext().getSubject(), MapiFAIContainer.TYPE, domainUid, true);
77
-			IContainers contApi = context.provider().instance(IContainers.class);
78
-			contApi.create(faiContainerId, fais);
79
-			logger.info("Created container {}", faiContainerId);
80 81
 		} catch (SQLException e1) {
81 82
 			throw ServerFault.sqlFault(e1);
82 83
 		}
84
+		checkFaiContainer(replica);
85
+
86
+	}
83 87
 
88
+	private void checkFaiContainer(MapiReplica replica) {
89
+		String faiContainerId = MapiFAIContainer.getIdentifier(replica);
90
+		ContainerDescriptor fais = ContainerDescriptor.create(faiContainerId, faiContainerId,
91
+				context.getSecurityContext().getSubject(), MapiFAIContainer.TYPE, domainUid, true);
92
+		IContainers contApi = context.provider().instance(IContainers.class);
93
+		ContainerDescriptor current = contApi.getIfPresent(faiContainerId);
94
+		if (current == null) {
95
+			contApi.create(faiContainerId, fais);
96
+			logger.info("Created container {}", faiContainerId);
97
+		}
98
+		if (pfMailbox) {
99
+			logger.info("Setting domain-wide {} ACLs for PF FAI folder {}", domainUid, faiContainerId);
100
+			IContainerManagement mgmtApi = context.su().provider().instance(IContainerManagement.class, faiContainerId);
101
+			mgmtApi.setAccessControlList(Arrays.asList(AccessControlEntry.create(domainUid, Verb.All)));
102
+		}
84 103
 	}
85 104
 
86 105
 	@Override