mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-5029 close all sessions with event (#2577)
* CB-5029 close all sessions with event * CB-5029 fixes after review * CB-5029 remove mac address from instance --------- Co-authored-by: kseniaguzeeva <112612526+kseniaguzeeva@users.noreply.github.com>
This commit is contained in:
@@ -31,4 +31,8 @@ public class WebGlobalWorkspace extends EclipseWorkspaceImpl {
|
||||
super(platform, eclipseWorkspace);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String initWorkspaceId() {
|
||||
return readWorkspaceIdProperty();
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,6 @@ import org.jkiss.dbeaver.model.security.SMObjectType;
|
||||
import org.jkiss.dbeaver.model.websocket.event.WSEventController;
|
||||
import org.jkiss.dbeaver.model.websocket.event.WSServerConfigurationChangedEvent;
|
||||
import org.jkiss.dbeaver.registry.BaseApplicationImpl;
|
||||
import org.jkiss.dbeaver.registry.BaseWorkspaceImpl;
|
||||
import org.jkiss.dbeaver.runtime.DBWorkbench;
|
||||
import org.jkiss.dbeaver.runtime.ui.DBPPlatformUI;
|
||||
import org.jkiss.dbeaver.utils.GeneralUtils;
|
||||
@@ -322,8 +321,6 @@ public abstract class CBApplication<T extends CBServerConfig> extends BaseWebApp
|
||||
System.setSecurityManager(new SecurityManager());
|
||||
}
|
||||
|
||||
saveWorkspaceId();
|
||||
|
||||
eventController.scheduleCheckJob();
|
||||
|
||||
runWebServer();
|
||||
@@ -333,16 +330,6 @@ public abstract class CBApplication<T extends CBServerConfig> extends BaseWebApp
|
||||
return;
|
||||
}
|
||||
|
||||
private void saveWorkspaceId() {
|
||||
final Path metadataFolder = GeneralUtils.getMetadataFolder();
|
||||
Properties props = BaseWorkspaceImpl.readWorkspaceInfo(metadataFolder);
|
||||
String workspaceIdProperty = "workspace-id";
|
||||
if (!props.contains(workspaceIdProperty)) {
|
||||
props.setProperty(workspaceIdProperty, CBPlatform.getInstance().getWorkspace().getWorkspaceId());
|
||||
BaseWorkspaceImpl.writeWorkspaceInfo(metadataFolder, props);
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeAdditionalConfiguration() {
|
||||
|
||||
}
|
||||
|
||||
+8
-2
@@ -17,6 +17,7 @@
|
||||
package io.cloudbeaver.server.events;
|
||||
|
||||
import io.cloudbeaver.server.CBPlatform;
|
||||
import io.cloudbeaver.service.session.WebSessionManager;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.dbeaver.model.websocket.WSEventHandler;
|
||||
import org.jkiss.dbeaver.model.websocket.event.WSAbstractEvent;
|
||||
@@ -31,15 +32,20 @@ public class WSUserEventHandler<EVENT extends WSAbstractEvent> implements WSEven
|
||||
if (eventType == null) {
|
||||
return;
|
||||
}
|
||||
WebSessionManager sessionManager = CBPlatform.getInstance().getSessionManager();
|
||||
switch (eventType) {
|
||||
case CLOSE_USER_SESSIONS:
|
||||
if (event instanceof WSUserCloseSessionsEvent closeSessionsEvent) {
|
||||
CBPlatform.getInstance().getSessionManager().closeSessions(closeSessionsEvent.getSessionIds());
|
||||
if (closeSessionsEvent.getSessionIds().isEmpty()) {
|
||||
sessionManager.closeAllSessions();
|
||||
} else {
|
||||
sessionManager.closeSessions(closeSessionsEvent.getSessionIds());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case USER_DELETED:
|
||||
if (event instanceof WSUserDeletedEvent userDeletedEvent) {
|
||||
CBPlatform.getInstance().getSessionManager().closeUserSession(userDeletedEvent.getUserId());
|
||||
sessionManager.closeUserSession(userDeletedEvent.getUserId());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
+19
-8
@@ -350,9 +350,9 @@ public class WebSessionManager {
|
||||
synchronized (sessionMap) {
|
||||
for (Iterator<BaseWebSession> iterator = sessionMap.values().iterator(); iterator.hasNext(); ) {
|
||||
var session = iterator.next();
|
||||
if (CommonUtils.equalObjects(session.getUserContext().getUserId(), userId)) {
|
||||
iterator.remove();
|
||||
session.close();
|
||||
if (CommonUtils.equalObjects(session.getUserContext().getUserId(), userId)) {
|
||||
iterator.remove();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -362,13 +362,24 @@ public class WebSessionManager {
|
||||
synchronized (sessionMap) {
|
||||
for (Iterator<BaseWebSession> iterator = sessionMap.values().iterator(); iterator.hasNext(); ) {
|
||||
var session = iterator.next();
|
||||
for (String smSessionId : smSessionsId) {
|
||||
if (CommonUtils.equalObjects(session.getUserContext().getSmSessionId(), smSessionId)) {
|
||||
iterator.remove();
|
||||
session.close(false);
|
||||
}
|
||||
if (smSessionsId.contains(session.getUserContext().getSmSessionId())) {
|
||||
iterator.remove();
|
||||
session.close(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes all sessions in session manager.
|
||||
*/
|
||||
public void closeAllSessions() {
|
||||
synchronized (sessionMap) {
|
||||
for (Iterator<BaseWebSession> iterator = sessionMap.values().iterator(); iterator.hasNext(); ) {
|
||||
var session = iterator.next();
|
||||
iterator.remove();
|
||||
session.close(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -49,7 +49,6 @@ import org.jkiss.dbeaver.model.security.exception.SMException;
|
||||
import org.jkiss.dbeaver.model.security.exception.SMRefreshTokenExpiredException;
|
||||
import org.jkiss.dbeaver.model.security.user.*;
|
||||
import org.jkiss.dbeaver.model.sql.SQLUtils;
|
||||
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
|
||||
import org.jkiss.dbeaver.model.websocket.event.WSUserCloseSessionsEvent;
|
||||
import org.jkiss.dbeaver.model.websocket.event.WSUserDeletedEvent;
|
||||
import org.jkiss.dbeaver.model.websocket.event.permissions.WSObjectPermissionEvent;
|
||||
@@ -208,7 +207,7 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
|
||||
} catch (SQLException e) {
|
||||
throw new DBCException("Error deleting user from database", e);
|
||||
}
|
||||
var event = new WSUserDeletedEvent(WSEventType.USER_DELETED, userId);
|
||||
var event = new WSUserDeletedEvent(userId);
|
||||
application.getEventController().addEvent(event);
|
||||
}
|
||||
|
||||
@@ -1844,6 +1843,7 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
|
||||
} catch (SQLException e) {
|
||||
throw new DBCException("Session invalidation failed", e);
|
||||
}
|
||||
application.getEventController().addEvent(new WSUserCloseSessionsEvent(List.of()));
|
||||
}
|
||||
|
||||
private void invalidateAllUserTokens(@NotNull String userId) throws DBCException {
|
||||
@@ -2337,7 +2337,7 @@ public class CBEmbeddedSecurityController<T extends WebAuthApplication>
|
||||
List<String> smSessionsId = findActiveUserSessions(userId, currentTime)
|
||||
.stream().map(SMActiveSession::sessionId).collect(Collectors.toList());
|
||||
deleteSessionsTokens(smSessionsId);
|
||||
application.getEventController().addEvent(new WSUserCloseSessionsEvent(smSessionsId, WSEventType.CLOSE_USER_SESSIONS));
|
||||
application.getEventController().addEvent(new WSUserCloseSessionsEvent(smSessionsId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-3
@@ -550,8 +550,6 @@ public class CBDatabase {
|
||||
}
|
||||
|
||||
private String getCurrentInstanceId() throws IOException {
|
||||
// 12 chars - mac address
|
||||
String macAddress = CommonUtils.toHexString(RuntimeUtils.getLocalMacAddress());
|
||||
// 16 chars - workspace ID
|
||||
String workspaceId = DBWorkbench.getPlatform().getWorkspace().getWorkspaceId();
|
||||
if (workspaceId.length() > 16) {
|
||||
@@ -559,7 +557,7 @@ public class CBDatabase {
|
||||
}
|
||||
|
||||
StringBuilder id = new StringBuilder(36);
|
||||
id.append(macAddress);
|
||||
id.append("000000000000"); // there was mac address, but it generates dynamically when docker is used
|
||||
id.append(":").append(workspaceId).append(":");
|
||||
while (id.length() < 36) {
|
||||
id.append("X");
|
||||
|
||||
Reference in New Issue
Block a user