Browse code

BM-14040 Feat: Add user logout internal api to invalidate all user sessions

Anthony Prades authored on 28/12/2018 10:01:32
Showing 24 changed files
... ...
@@ -85,6 +85,8 @@
85 85
       <plugin id="net.bluemind.authentication.provider"/>
86 86
       <plugin id="net.bluemind.authentication.service"/>
87 87
       <plugin id="net.bluemind.authentication.sqlschema"/>
88
+      <plugin id="net.bluemind.authentication.mgmt.api"/>
89
+      <plugin id="net.bluemind.authentication.mgmt.service"/>
88 90
       <plugin id="net.bluemind.backend.cyrus"/>
89 91
       <plugin id="net.bluemind.backend.cyrus.mailboxesdb"/>
90 92
       <plugin id="net.bluemind.backend.cyrus.partitions"/>
91 93
new file mode 100644
... ...
@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src"/>
6
+	<classpathentry kind="src" path="generated"/>
7
+	<classpathentry kind="output" path="bin"/>
8
+</classpath>
0 9
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.authentication.mgmt.api</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.authentication.mgmt.api
4
+Bundle-SymbolicName: net.bluemind.authentication.mgmt.api
5
+Bundle-Version: 4.1.0.qualifier
6
+Bundle-Vendor: bluemind.net
7
+Automatic-Module-Name: net.bluemind.authentication.mgmt.api
8
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Require-Bundle: net.bluemind.core.commons
10
+Export-Package: net.bluemind.authentication.mgmt.api
0 11
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+source.. = src/,\
2
+           generated/
3
+bin.includes = META-INF/,\
4
+               .
0 5
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <parent>
4
+    <groupId>net.bluemind</groupId>
5
+    <version>4.1.0-SNAPSHOT</version>
6
+    <artifactId>net.bluemind.authentication.mgmt.plugins</artifactId>
7
+  </parent>
8
+  <artifactId>net.bluemind.authentication.mgmt.api</artifactId>
9
+  <packaging>eclipse-plugin</packaging>
10
+</project>
0 11
new file mode 100644
... ...
@@ -0,0 +1,46 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
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
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.authentication.mgmt.api;
20
+
21
+import javax.ws.rs.POST;
22
+import javax.ws.rs.Path;
23
+import javax.ws.rs.PathParam;
24
+
25
+import net.bluemind.core.api.BMApi;
26
+import net.bluemind.core.api.fault.ServerFault;
27
+
28
+/**
29
+ * SessionsMgmt service
30
+ *
31
+ */
32
+@BMApi(version = "3", internal = true)
33
+@Path("/sessionsmgmt")
34
+public interface ISessionsMgmt {
35
+	/**
36
+	 * Close all Blue-Mind sessions of requested user.
37
+	 * <p>
38
+	 * Only token from global domain are allowed to do this.
39
+	 * 
40
+	 * @param latd login at domain
41
+	 * @throws ServerFault
42
+	 */
43
+	@POST
44
+	@Path("{latd}/logout")
45
+	public void logoutUser(@PathParam("latd") String latd);
46
+}
0 47
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src">
6
+		<attributes>
7
+			<attribute name="test" value="true"/>
8
+		</attributes>
9
+	</classpathentry>
10
+	<classpathentry kind="output" path="bin"/>
11
+</classpath>
0 12
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.authentication.mgmt.service.tests</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,17 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.authentication.mgmt.service.tests
4
+Bundle-SymbolicName: net.bluemind.authentication.mgmt.service.tests
5
+Bundle-Version: 4.1.0.qualifier
6
+Automatic-Module-Name: net.bluemind.authentication.mgmt.service.tests
7
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8
+Require-Bundle: org.junit,
9
+ com.google.guava,
10
+ net.bluemind.tests.defaultdata,
11
+ net.bluemind.config,
12
+ net.bluemind.core.jdbc.testshelper,
13
+ net.bluemind.authentication.api,
14
+ net.bluemind.core.rest.http,
15
+ net.bluemind.authentication.mgmt.api,
16
+ net.bluemind.system.state,
17
+ net.bluemind.pool
0 18
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+source.. = src/
2
+output.. = bin/
3
+bin.includes = META-INF/,\
4
+               .
0 5
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+	<modelVersion>4.0.0</modelVersion>
4
+	<parent>
5
+		<groupId>net.bluemind</groupId>
6
+		<version>4.1.0-SNAPSHOT</version>
7
+		<artifactId>net.bluemind.authentication.mgmt.plugins</artifactId>
8
+	</parent>
9
+	<artifactId>net.bluemind.authentication.mgmt.service.tests</artifactId>
10
+	<packaging>eclipse-test-plugin</packaging>
11
+	<build>
12
+		<plugins>
13
+			<plugin>
14
+				<groupId>org.eclipse.tycho</groupId>
15
+				<artifactId>target-platform-configuration</artifactId>
16
+				<configuration>
17
+					<dependency-resolution>
18
+						<extraRequirements>
19
+							<requirement>
20
+								<type>eclipse-feature</type>
21
+								<id>net.bluemind.tests.feature</id>
22
+								<versionRange>0.0.0</versionRange>
23
+							</requirement>
24
+						</extraRequirements>
25
+					</dependency-resolution>
26
+				</configuration>
27
+			</plugin>
28
+		</plugins>
29
+	</build>
30
+</project>
0 31
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+[{ 
2
+ 	"name":"bluemind/postgres-tests" 
3
+ 	},{
4
+ 	"name":"bluemind/elasticsearch-tests"
5
+ 	}]
0 6
new file mode 100644
... ...
@@ -0,0 +1,166 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
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
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.authentication.mgmt.service.tests;
20
+
21
+import static org.junit.Assert.assertEquals;
22
+import static org.junit.Assert.assertTrue;
23
+import static org.junit.Assert.fail;
24
+
25
+import java.util.Map;
26
+
27
+import org.junit.After;
28
+import org.junit.Before;
29
+import org.junit.Test;
30
+import org.vertx.java.core.AsyncResult;
31
+import org.vertx.java.core.Handler;
32
+
33
+import com.google.common.collect.Lists;
34
+import com.google.common.util.concurrent.SettableFuture;
35
+
36
+import net.bluemind.authentication.api.IAuthentication;
37
+import net.bluemind.authentication.api.LoginResponse;
38
+import net.bluemind.authentication.api.LoginResponse.Status;
39
+import net.bluemind.authentication.mgmt.api.ISessionsMgmt;
40
+import net.bluemind.core.api.fault.ErrorCode;
41
+import net.bluemind.core.api.fault.ServerFault;
42
+import net.bluemind.core.context.SecurityContext;
43
+import net.bluemind.core.jdbc.JdbcTestHelper;
44
+import net.bluemind.core.rest.ServerSideServiceProvider;
45
+import net.bluemind.core.rest.http.ClientSideServiceProvider;
46
+import net.bluemind.domain.api.DomainSettingsKeys;
47
+import net.bluemind.domain.api.IDomainSettings;
48
+import net.bluemind.lib.vertx.VertxPlatform;
49
+import net.bluemind.mailbox.api.Mailbox.Routing;
50
+import net.bluemind.pool.impl.BmConfIni;
51
+import net.bluemind.server.api.Server;
52
+import net.bluemind.system.state.StateContext;
53
+import net.bluemind.tests.defaultdata.PopulateHelper;
54
+
55
+public class SessionsMgmtTests {
56
+
57
+	@Before
58
+	public void setup() throws Exception {
59
+		JdbcTestHelper.getInstance().beforeTest();
60
+
61
+		final SettableFuture<Void> future = SettableFuture.<Void>create();
62
+		Handler<AsyncResult<Void>> done = new Handler<AsyncResult<Void>>() {
63
+
64
+			@Override
65
+			public void handle(AsyncResult<Void> event) {
66
+				future.set(null);
67
+			}
68
+		};
69
+		VertxPlatform.spawnVerticles(done);
70
+		future.get();
71
+
72
+		Server esServer = new Server();
73
+		esServer.ip = new BmConfIni().get("es-host");
74
+		esServer.tags = Lists.newArrayList("bm/es");
75
+
76
+		PopulateHelper.initGlobalVirt(esServer);
77
+
78
+		PopulateHelper.addDomainAdmin("admin0", "global.virt", Routing.external);
79
+
80
+		PopulateHelper.createTestDomain("bm.lan", esServer);
81
+		IDomainSettings settings = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
82
+				.instance(IDomainSettings.class, "bm.lan");
83
+		Map<String, String> domainSettings = settings.get();
84
+		domainSettings.put(DomainSettingsKeys.mail_routing_relay.name(), "external@test.fr");
85
+		domainSettings.put(DomainSettingsKeys.domain_max_basic_account.name(), "");
86
+		settings.set(domainSettings);
87
+		PopulateHelper.addDomainAdmin("admin", "bm.lan", Routing.external);
88
+		PopulateHelper.addUser("toto", "bm.lan", Routing.external);
89
+		PopulateHelper.addSimpleUser("simple", "bm.lan", Routing.external);
90
+
91
+		StateContext.setState("reset");
92
+		StateContext.setState("core.started");
93
+	}
94
+
95
+	@After
96
+	public void after() throws Exception {
97
+		JdbcTestHelper.getInstance().afterTest();
98
+	}
99
+
100
+	private void initState() {
101
+		StateContext.setState("core.stopped");
102
+		StateContext.setState("core.started");
103
+		StateContext.setState("core.started");
104
+	}
105
+
106
+	private IAuthentication getAutenticationService(String sessionId) throws ServerFault {
107
+		return ClientSideServiceProvider.getProvider("http://127.0.0.1:8090", sessionId)
108
+				.instance(IAuthentication.class);
109
+	}
110
+
111
+	private ISessionsMgmt getSessionsMgmtService(String sessionId) throws ServerFault {
112
+		return ClientSideServiceProvider.getProvider("http://127.0.0.1:8090", sessionId).instance(ISessionsMgmt.class);
113
+	}
114
+
115
+	@Test
116
+	public void testLogoutLatd() throws Exception {
117
+		initState();
118
+		IAuthentication authentication = getAutenticationService(null);
119
+		LoginResponse response1 = authentication.login("admin@bm.lan", "admin", "junit");
120
+		assertEquals(Status.Ok, response1.status);
121
+
122
+		LoginResponse response2 = authentication.login("admin@bm.lan", "admin", "junit");
123
+		assertEquals(Status.Ok, response2.status);
124
+
125
+		LoginResponse response3 = authentication.login("admin0@global.virt", "admin", "junit");
126
+		assertEquals(Status.Ok, response3.status);
127
+
128
+		assertEquals(Status.Ok, authentication.login("admin@bm.lan", response1.authKey, "junit").status);
129
+		assertEquals(Status.Ok, authentication.login("admin@bm.lan", response2.authKey, "junit").status);
130
+		assertEquals(Status.Ok, authentication.login("admin0@global.virt", response3.authKey, "junit").status);
131
+
132
+		try {
133
+			getSessionsMgmtService(null).logoutUser("admin@bm.lan");
134
+			fail("Test must throw an exception");
135
+		} catch (ServerFault sf) {
136
+			assertEquals(ErrorCode.PERMISSION_DENIED, sf.getCode());
137
+		}
138
+
139
+		try {
140
+			ISessionsMgmt sessionsMgmt = getSessionsMgmtService(
141
+					authentication.login("toto@bm.lan", "toto", "junit").authKey);
142
+			sessionsMgmt.logoutUser("admin@bm.lan");
143
+			fail("Test must throw an exception");
144
+		} catch (ServerFault sf) {
145
+			assertEquals(ErrorCode.PERMISSION_DENIED, sf.getCode());
146
+			assertTrue(sf.getMessage().contains("toto@bm.lan"));
147
+		}
148
+
149
+		try {
150
+			ISessionsMgmt sessionsMgmt = getSessionsMgmtService(
151
+					authentication.login("admin@bm.lan", "admin", "junit").authKey);
152
+			sessionsMgmt.logoutUser("admin@bm.lan");
153
+			fail("Test must throw an exception");
154
+		} catch (ServerFault sf) {
155
+			assertEquals(ErrorCode.PERMISSION_DENIED, sf.getCode());
156
+			assertTrue(sf.getMessage().contains("admin@bm.lan"));
157
+		}
158
+
159
+		ISessionsMgmt sessionsMgmt = getSessionsMgmtService(
160
+				authentication.login("admin0@global.virt", "admin", "junit").authKey);
161
+		sessionsMgmt.logoutUser("admin@bm.lan");
162
+		assertEquals(Status.Bad, authentication.login("admin@bm.lan", response1.authKey, "junit").status);
163
+		assertEquals(Status.Bad, authentication.login("admin@bm.lan", response2.authKey, "junit").status);
164
+		assertEquals(Status.Ok, authentication.login("admin0@global.virt", response3.authKey, "junit").status);
165
+	}
166
+}
0 167
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src"/>
6
+	<classpathentry kind="output" path="bin"/>
7
+</classpath>
0 8
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.authentication.mgmt.service</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,16 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.authentication.mgmt.service
4
+Bundle-SymbolicName: net.bluemind.authentication.mgmt.service;singleton:=true
5
+Bundle-Version: 4.1.0.qualifier
6
+Bundle-Vendor: bluemind.net
7
+Automatic-Module-Name: net.bluemind.authentication.mgmt.service
8
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Require-Bundle: net.bluemind.authentication.mgmt.api,
10
+ net.bluemind.core.rest,
11
+ net.bluemind.slf4j,
12
+ net.bluemind.core.container.service,
13
+ net.bluemind.role.api,
14
+ net.bluemind.user.api,
15
+ net.bluemind.core.sessions,
16
+ com.google.guava;bundle-version="19.0.0"
0 17
new file mode 100644
... ...
@@ -0,0 +1,5 @@
1
+source.. = src/
2
+output.. = bin/
3
+bin.includes = META-INF/,\
4
+               .,\
5
+               plugin.xml
0 6
new file mode 100644
... ...
@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<plugin>
4
+  <extension
5
+         point="net.bluemind.core.rest.apiEndpoint">
6
+      <endpoint
7
+            api="net.bluemind.authentication.mgmt.api.ISessionsMgmt">
8
+      </endpoint>
9
+   </extension>
10
+   <extension
11
+         point="net.bluemind.core.rest.serviceFactory">
12
+      <serviceFactory
13
+            class="net.bluemind.authentication.mgmt.service.SessionsMgmtFactory">
14
+      </serviceFactory>
15
+   </extension>
16
+</plugin>
0 17
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <parent>
4
+    <groupId>net.bluemind</groupId>
5
+    <version>4.1.0-SNAPSHOT</version>
6
+    <artifactId>net.bluemind.authentication.mgmt.plugins</artifactId>
7
+  </parent>
8
+  <artifactId>net.bluemind.authentication.mgmt.service</artifactId>
9
+  <packaging>eclipse-plugin</packaging>
10
+</project>
0 11
new file mode 100644
... ...
@@ -0,0 +1,81 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
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
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.authentication.mgmt.service;
20
+
21
+import java.util.Iterator;
22
+
23
+import org.slf4j.Logger;
24
+import org.slf4j.LoggerFactory;
25
+
26
+import com.google.common.base.Splitter;
27
+
28
+import net.bluemind.authentication.mgmt.api.ISessionsMgmt;
29
+import net.bluemind.core.container.model.ItemValue;
30
+import net.bluemind.core.container.service.internal.RBACManager;
31
+import net.bluemind.core.context.SecurityContext;
32
+import net.bluemind.core.rest.BmContext;
33
+import net.bluemind.core.rest.ServerSideServiceProvider;
34
+import net.bluemind.core.sessions.Sessions;
35
+import net.bluemind.lib.vertx.VertxPlatform;
36
+import net.bluemind.role.api.BasicRoles;
37
+import net.bluemind.user.api.IUser;
38
+import net.bluemind.user.api.User;
39
+
40
+public class SessionsMgmt implements ISessionsMgmt {
41
+	private static final Logger logger = LoggerFactory.getLogger(SessionsMgmt.class);
42
+	protected static final Splitter atSplitter = Splitter.on('@').trimResults().omitEmptyStrings();
43
+
44
+	private BmContext context;
45
+
46
+	public SessionsMgmt(BmContext context) {
47
+		this.context = context;
48
+	}
49
+
50
+	@Override
51
+	public void logoutUser(String latd) {
52
+		RBACManager.forContext(context).check(BasicRoles.ROLE_SYSTEM_MANAGER);
53
+
54
+		Iterator<String> splitted = atSplitter.split(latd).iterator();
55
+		String localPart = splitted.next();
56
+		String domainPart = splitted.next();
57
+
58
+		IUser userService = ServerSideServiceProvider.getProvider(context.getSecurityContext()).instance(IUser.class,
59
+				domainPart);
60
+
61
+		ItemValue<User> user = userService.byLogin(localPart);
62
+		if (user == null) {
63
+			logger.warn(String.format("User %s not found", latd));
64
+			return;
65
+		}
66
+
67
+		Sessions.get().asMap().values().stream().filter(sc -> sc.getSubject().equals(user.uid))
68
+				.forEach(this::invalidateSession);
69
+	}
70
+
71
+	private void invalidateSession(SecurityContext sc) {
72
+		if (sc.getSessionId() != null) {
73
+			if (logger.isDebugEnabled()) {
74
+				logger.debug("logout user {} session {}", sc.getSubject(), sc.getSessionId());
75
+			}
76
+
77
+			Sessions.get().invalidate(sc.getSessionId());
78
+			VertxPlatform.eventBus().publish("core.user.push.queue.removed", "client.session." + sc.getSessionId());
79
+		}
80
+	}
81
+}
0 82
new file mode 100644
... ...
@@ -0,0 +1,35 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
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
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.authentication.mgmt.service;
20
+
21
+import net.bluemind.authentication.mgmt.api.ISessionsMgmt;
22
+import net.bluemind.core.rest.BmContext;
23
+import net.bluemind.core.rest.ServerSideServiceProvider;
24
+
25
+public class SessionsMgmtFactory implements ServerSideServiceProvider.IServerSideServiceFactory<ISessionsMgmt> {
26
+	@Override
27
+	public Class<ISessionsMgmt> factoryClass() {
28
+		return ISessionsMgmt.class;
29
+	}
30
+
31
+	@Override
32
+	public ISessionsMgmt instance(BmContext context, String... params) {
33
+		return new SessionsMgmt(context);
34
+	}
35
+}
0 36
new file mode 100644
... ...
@@ -0,0 +1,16 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+	<modelVersion>4.0.0</modelVersion>
4
+	<parent>
5
+		<groupId>net.bluemind</groupId>
6
+		<artifactId>net.bluemind.authentication.plugins</artifactId>
7
+		<version>4.1.0-SNAPSHOT</version>
8
+	</parent>
9
+	<artifactId>net.bluemind.authentication.mgmt.plugins</artifactId>
10
+	<packaging>pom</packaging>
11
+	<modules>
12
+		<module>net.bluemind.authentication.mgmt.api</module>
13
+		<module>net.bluemind.authentication.mgmt.service</module>
14
+		<module>net.bluemind.authentication.mgmt.service.tests</module>
15
+	</modules>
16
+</project>
... ...
@@ -9,6 +9,7 @@
9 9
 	<artifactId>net.bluemind.authentication.plugins</artifactId>
10 10
 	<packaging>pom</packaging>
11 11
 	<modules>
12
+		<module>mgmt</module>
12 13
 		<module>net.bluemind.authentication.api</module>
13 14
 		<module>net.bluemind.authentication.handler</module>
14 15
 		<module>net.bluemind.authentication.handler.tests</module>