Browse code

BM-15571 Fix: upgrader major version

Anthony Prades authored on 08/01/2020 13:38:57
Showing 3 changed files
... ...
@@ -29,7 +29,7 @@
29 29
             code="net.bluemind.system.ldap.export.upgrader.AddBmUuidIndex">
30 30
       </java>
31 31
       <java
32
-            code="net.bluemind.system.ldap.export.upgrader.AddBmHiddentAttribute">
32
+            code="net.bluemind.system.ldap.export.upgrader.AddBmHiddenAttribute">
33 33
       </java>
34 34
    </extension>
35 35
 </plugin>
36 36
new file mode 100644
... ...
@@ -0,0 +1,127 @@
1
+/* BEGIN LICENSE
2
+  * Copyright © Blue Mind SAS, 2012-2018
3
+  *
4
+  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+  * solution.
6
+  *
7
+  * This program is free software; you can redistribute it and/or modify
8
+  * it under the terms of either the GNU Affero General Public License as
9
+  * published by the Free Software Foundation (version 3 of the License).
10
+  *
11
+  * This program is distributed in the hope that it will be useful,
12
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+  *
15
+  * See LICENSE.txt
16
+  * END LICENSE
17
+  */
18
+package net.bluemind.system.ldap.export.upgrader;
19
+
20
+import java.io.IOException;
21
+import java.util.ArrayList;
22
+import java.util.List;
23
+import java.util.Set;
24
+
25
+import javax.sql.DataSource;
26
+
27
+import org.apache.directory.api.ldap.model.cursor.CursorException;
28
+import org.apache.directory.api.ldap.model.entry.Entry;
29
+import org.apache.directory.api.ldap.model.exception.LdapException;
30
+import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
31
+import org.apache.directory.api.ldap.model.message.ModifyRequestImpl;
32
+import org.apache.directory.ldap.client.api.LdapConnection;
33
+import org.slf4j.Logger;
34
+import org.slf4j.LoggerFactory;
35
+
36
+import net.bluemind.core.api.fault.ServerFault;
37
+import net.bluemind.core.container.model.ItemValue;
38
+import net.bluemind.core.context.SecurityContext;
39
+import net.bluemind.core.rest.BmContext;
40
+import net.bluemind.core.rest.ServerSideServiceProvider;
41
+import net.bluemind.core.task.service.IServerTaskMonitor;
42
+import net.bluemind.server.api.IServer;
43
+import net.bluemind.server.api.Server;
44
+import net.bluemind.system.ldap.export.LdapHelper;
45
+import net.bluemind.system.ldap.export.hook.LdapServerHook;
46
+import net.bluemind.system.schemaupgrader.IVersionedUpdater;
47
+import net.bluemind.system.schemaupgrader.UpdateAction;
48
+import net.bluemind.system.schemaupgrader.UpdateResult;
49
+
50
+public class AddBmHiddenAttribute implements IVersionedUpdater {
51
+	private static final Logger logger = LoggerFactory.getLogger(AddBmHiddenAttribute.class);
52
+
53
+	@Override
54
+	public int major() {
55
+		return 5;
56
+	}
57
+
58
+	@Override
59
+	public int buildNumber() {
60
+		return 47721;
61
+	}
62
+
63
+	@Override
64
+	public UpdateResult executeUpdate(IServerTaskMonitor monitor, DataSource pool, Set<UpdateAction> handledActions) {
65
+
66
+		BmContext context = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM).getContext();
67
+
68
+		List<ItemValue<Server>> directoryServers = new ArrayList<>();
69
+		try {
70
+			for (ItemValue<Server> server : context.provider().instance(IServer.class, "default").allComplete()) {
71
+				if (server.value.tags.contains(LdapServerHook.LDAPTAG)) {
72
+					directoryServers.add(server);
73
+				}
74
+			}
75
+			monitor.progress(1, String.format("Get hosts tagged as %s", LdapServerHook.LDAPTAG));
76
+		} catch (ServerFault e) {
77
+			monitor.end(false, String.format("Fail to get %s hosts: %s", LdapServerHook.LDAPTAG, e.getMessage()), "");
78
+			return UpdateResult.failed();
79
+		}
80
+
81
+		IServerTaskMonitor monitorByServer = monitor.subWork(1);
82
+
83
+		for (ItemValue<Server> directoryServer : directoryServers) {
84
+			try (LdapConnection ldapCon = LdapHelper.connectConfigDirectory(directoryServer)) {
85
+				modifyOlcDbIndex(ldapCon);
86
+
87
+				logger.info("Host: " + directoryServer.value.address() + " BlueMind schema updated.");
88
+				monitorByServer.progress(1, "Host: " + directoryServer.value.address() + " upgraded");
89
+			} catch (ServerFault | IOException | LdapException | CursorException e) {
90
+				String errorMsg = String.format("Fail to update LDAP configuration on host %s: %s",
91
+						directoryServer.value.address(), e.getMessage());
92
+				logger.error(errorMsg, e);
93
+				monitorByServer.end(false, errorMsg, "");
94
+
95
+				return UpdateResult.failed();
96
+			}
97
+		}
98
+		return UpdateResult.ok();
99
+	}
100
+
101
+	private void modifyOlcDbIndex(LdapConnection ldapCon)
102
+			throws LdapInvalidDnException, LdapException, CursorException {
103
+		Entry entry = ldapCon.lookup("cn={4}bluemind,cn=schema,cn=config");
104
+
105
+		if (entry != null) {
106
+			ModifyRequestImpl modifyRequest = new ModifyRequestImpl();
107
+			modifyRequest.setName(entry.getDn());
108
+			modifyRequest.replace("olcAttributeTypes",
109
+					"{0}( 1.3.6.1.4.1.39073.2.1 NAME 'bmUid' DESC 'BlueMind UID' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} SINGLE-VALUE )",
110
+					"{1}( 1.3.6.1.4.1.39073.2.2 NAME 'bmVersion' DESC 'BlueMind changset version' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )",
111
+					"{2}( 1.3.6.1.4.1.39073.2.3 NAME 'bmHidden' DESC 'BlueMind hidden status' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} SINGLE-VALUE )");
112
+			modifyRequest.replace("olcObjectClasses",
113
+					"{0}( 1.3.6.1.4.1.39073.1.1 NAME 'bmGroup' DESC 'BlueMind group' SUP top AUXILIARY MAY ( member $ mail $ bmUid $ bmHidden ) )",
114
+					"{1}( 1.3.6.1.4.1.39073.1.2 NAME 'bmUser' DESC 'BlueMind user' SUP top AUXILIARY MUST ( bmUid ) MAY ( bmHidden ) )",
115
+					"{2}( 1.3.6.1.4.1.39073.1.3 NAME 'bmDomain' DESC 'BlueMind domain' SUP top AUXILIARY MUST ( bmVersion ) )");
116
+			LdapHelper.modifyLdapEntry(ldapCon, modifyRequest);
117
+		} else {
118
+			throw new ServerFault("Unable to find entry DN: cn={4}bluemind,cn=schema,cn=config");
119
+		}
120
+	}
121
+
122
+	@Override
123
+	public boolean afterSchemaUpgrade() {
124
+		return true;
125
+	}
126
+
127
+}
0 128
deleted file mode 100644
... ...
@@ -1,127 +0,0 @@
1
-/* BEGIN LICENSE
2
-  * Copyright © Blue Mind SAS, 2012-2018
3
-  *
4
-  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
-  * solution.
6
-  *
7
-  * This program is free software; you can redistribute it and/or modify
8
-  * it under the terms of either the GNU Affero General Public License as
9
-  * published by the Free Software Foundation (version 3 of the License).
10
-  *
11
-  * This program is distributed in the hope that it will be useful,
12
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
-  *
15
-  * See LICENSE.txt
16
-  * END LICENSE
17
-  */
18
-package net.bluemind.system.ldap.export.upgrader;
19
-
20
-import java.io.IOException;
21
-import java.util.ArrayList;
22
-import java.util.List;
23
-import java.util.Set;
24
-
25
-import javax.sql.DataSource;
26
-
27
-import org.apache.directory.api.ldap.model.cursor.CursorException;
28
-import org.apache.directory.api.ldap.model.entry.Entry;
29
-import org.apache.directory.api.ldap.model.exception.LdapException;
30
-import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
31
-import org.apache.directory.api.ldap.model.message.ModifyRequestImpl;
32
-import org.apache.directory.ldap.client.api.LdapConnection;
33
-import org.slf4j.Logger;
34
-import org.slf4j.LoggerFactory;
35
-
36
-import net.bluemind.core.api.fault.ServerFault;
37
-import net.bluemind.core.container.model.ItemValue;
38
-import net.bluemind.core.context.SecurityContext;
39
-import net.bluemind.core.rest.BmContext;
40
-import net.bluemind.core.rest.ServerSideServiceProvider;
41
-import net.bluemind.core.task.service.IServerTaskMonitor;
42
-import net.bluemind.server.api.IServer;
43
-import net.bluemind.server.api.Server;
44
-import net.bluemind.system.ldap.export.LdapHelper;
45
-import net.bluemind.system.ldap.export.hook.LdapServerHook;
46
-import net.bluemind.system.schemaupgrader.IVersionedUpdater;
47
-import net.bluemind.system.schemaupgrader.UpdateAction;
48
-import net.bluemind.system.schemaupgrader.UpdateResult;
49
-
50
-public class AddBmHiddentAttribute implements IVersionedUpdater {
51
-	private static final Logger logger = LoggerFactory.getLogger(AddBmHiddentAttribute.class);
52
-
53
-	@Override
54
-	public int major() {
55
-		return 4;
56
-	}
57
-
58
-	@Override
59
-	public int buildNumber() {
60
-		return 44932;
61
-	}
62
-
63
-	@Override
64
-	public UpdateResult executeUpdate(IServerTaskMonitor monitor, DataSource pool, Set<UpdateAction> handledActions) {
65
-
66
-		BmContext context = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM).getContext();
67
-
68
-		List<ItemValue<Server>> directoryServers = new ArrayList<>();
69
-		try {
70
-			for (ItemValue<Server> server : context.provider().instance(IServer.class, "default").allComplete()) {
71
-				if (server.value.tags.contains(LdapServerHook.LDAPTAG)) {
72
-					directoryServers.add(server);
73
-				}
74
-			}
75
-			monitor.progress(1, String.format("Get hosts tagged as %s", LdapServerHook.LDAPTAG));
76
-		} catch (ServerFault e) {
77
-			monitor.end(false, String.format("Fail to get %s hosts: %s", LdapServerHook.LDAPTAG, e.getMessage()), "");
78
-			return UpdateResult.failed();
79
-		}
80
-
81
-		IServerTaskMonitor monitorByServer = monitor.subWork(1);
82
-
83
-		for (ItemValue<Server> directoryServer : directoryServers) {
84
-			try (LdapConnection ldapCon = LdapHelper.connectConfigDirectory(directoryServer)) {
85
-				modifyOlcDbIndex(ldapCon);
86
-
87
-				logger.info("Host: " + directoryServer.value.address() + " BlueMind schema updated.");
88
-				monitorByServer.progress(1, "Host: " + directoryServer.value.address() + " upgraded");
89
-			} catch (ServerFault | IOException | LdapException | CursorException e) {
90
-				String errorMsg = String.format("Fail to update LDAP configuration on host %s: %s",
91
-						directoryServer.value.address(), e.getMessage());
92
-				logger.error(errorMsg, e);
93
-				monitorByServer.end(false, errorMsg, "");
94
-
95
-				return UpdateResult.failed();
96
-			}
97
-		}
98
-		return UpdateResult.ok();
99
-	}
100
-
101
-	private void modifyOlcDbIndex(LdapConnection ldapCon)
102
-			throws LdapInvalidDnException, LdapException, CursorException {
103
-		Entry entry = ldapCon.lookup("cn={4}bluemind,cn=schema,cn=config");
104
-
105
-		if (entry != null) {
106
-			ModifyRequestImpl modifyRequest = new ModifyRequestImpl();
107
-			modifyRequest.setName(entry.getDn());
108
-			modifyRequest.replace("olcAttributeTypes",
109
-					"{0}( 1.3.6.1.4.1.39073.2.1 NAME 'bmUid' DESC 'BlueMind UID' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} SINGLE-VALUE )",
110
-					"{1}( 1.3.6.1.4.1.39073.2.2 NAME 'bmVersion' DESC 'BlueMind changset version' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )",
111
-					"{2}( 1.3.6.1.4.1.39073.2.3 NAME 'bmHidden' DESC 'BlueMind hidden status' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} SINGLE-VALUE )");
112
-			modifyRequest.replace("olcObjectClasses",
113
-					"{0}( 1.3.6.1.4.1.39073.1.1 NAME 'bmGroup' DESC 'BlueMind group' SUP top AUXILIARY MAY ( member $ mail $ bmUid $ bmHidden ) )",
114
-					"{1}( 1.3.6.1.4.1.39073.1.2 NAME 'bmUser' DESC 'BlueMind user' SUP top AUXILIARY MUST ( bmUid ) MAY ( bmHidden ) )",
115
-					"{2}( 1.3.6.1.4.1.39073.1.3 NAME 'bmDomain' DESC 'BlueMind domain' SUP top AUXILIARY MUST ( bmVersion ) )");
116
-			LdapHelper.modifyLdapEntry(ldapCon, modifyRequest);
117
-		} else {
118
-			throw new ServerFault("Unable to find entry DN: cn={4}bluemind,cn=schema,cn=config");
119
-		}
120
-	}
121
-
122
-	@Override
123
-	public boolean afterSchemaUpgrade() {
124
-		return true;
125
-	}
126
-
127
-}