Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty;
import org.jkiss.dbeaver.model.websocket.event.permissions.WSObjectPermissionEvent;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -61,22 +60,13 @@ public void handleEvent(@NotNull WSObjectPermissionEvent event) {
yield null;
}
};
if (runnable == null) {
if (runnable == null || event.getSessionId() == null) {
return;
}
log.debug(event.getTopicId() + " event handled");
Collection<BaseWebSession> allSessions = CBApplication.getInstance().getSessionManager().getAllActiveSessions();
for (var activeUserSession : allSessions) {
if (!isAcceptableInSession(activeUserSession, event)) {
log.debug("Cannot handle %s event '%s' in session %s".formatted(
event.getTopicId(),
event.getId(),
activeUserSession.getSessionId()
));
continue;
}
BaseWebSession webSession = WebAppUtils.getWebApplication().getSessionManager().findSessionBySmId(event.getSessionId());
if (webSession != null) {
log.debug("%s event '%s' handled".formatted(event.getTopicId(), event.getId()));
runnable.accept(activeUserSession);
runnable.accept(webSession);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@

@Override
@Nullable
public WebSession findWebSession(HttpServletRequest request) {
public WebSession findWebSession(@NotNull HttpServletRequest request) {
String sessionId = getSessionId(request);
synchronized (sessionMap) {
var session = sessionMap.get(sessionId);
Expand All @@ -294,8 +294,22 @@
}
}

@Nullable
@Override
public BaseWebSession findSessionBySmId(@NotNull String smSessionId) {
synchronized (sessionMap) {
for (BaseWebSession session : sessionMap.values()) {
if (Objects.equals(session.getUserContext().getSmSessionId(), smSessionId)) {
return session;
}
}
}
return null;
}

@Nullable

Check warning on line 310 in server/bundles/io.cloudbeaver.server.ce/src/io/cloudbeaver/service/session/CBSessionManager.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '284'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server.ce/src/io/cloudbeaver/service/session/CBSessionManager.java:310:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '284'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
@Override
public WebSession findWebSession(HttpServletRequest request, boolean errorOnNoFound) throws DBWebException {
public WebSession findWebSession(@NotNull HttpServletRequest request, boolean errorOnNoFound) throws DBWebException {
WebSession webSession = findWebSession(request);
if (webSession != null) {
return webSession;
Expand Down Expand Up @@ -323,6 +337,7 @@
}
}

@NotNull
@Override
public Collection<BaseWebSession> getAllActiveSessions() {
synchronized (sessionMap) {
Expand Down Expand Up @@ -452,12 +467,13 @@
/**
* Creates new web session or returns existing one.
*/
public WebSession createWebSession(WebHttpRequestInfo requestInfo) throws DBException {
@NotNull
public WebSession createWebSession(@NotNull WebHttpRequestInfo requestInfo) throws DBException {
String id = requestInfo.getId();
synchronized (sessionMap) {
BaseWebSession baseWebSession = sessionMap.get(id);
if (baseWebSession instanceof WebSession) {
return (WebSession) baseWebSession;
if (baseWebSession instanceof WebSession webSession) {
return webSession;
} else {
WebSession webSessionImpl = createWebSessionImpl(requestInfo);
sessionMap.put(id, webSessionImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@
BaseWebSession getSession(@NotNull String sessionId);

@Nullable
WebSession findWebSession(HttpServletRequest request);
WebSession findWebSession(@NotNull HttpServletRequest request);

WebSession findWebSession(HttpServletRequest request, boolean errorOnNoFound) throws DBWebException;
@Nullable
BaseWebSession findSessionBySmId(@NotNull String smSessionId);

@Nullable

Check warning on line 61 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/WebAppSessionManager.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '55'. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/WebAppSessionManager.java:61:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '55'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
WebSession findWebSession(@NotNull HttpServletRequest request, boolean errorOnNoFound) throws DBWebException;

@NotNull
Collection<BaseWebSession> getAllActiveSessions();

WebSession getOrRestoreWebSession(WebHttpRequestInfo httpRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,20 @@
import org.jkiss.dbeaver.model.websocket.WSEventHandler;
import org.jkiss.dbeaver.model.websocket.event.WSEvent;

import java.util.Collection;

public class WSDefaultEventHandler<EVENT extends WSEvent> implements WSEventHandler<EVENT> {

private static final Log log = Log.getLog(WSDefaultEventHandler.class);

@Override
public void handleEvent(@NotNull EVENT event) {
log.debug(event.getTopicId() + " event handled");
Collection<BaseWebSession> allSessions = WebAppUtils.getWebApplication()
.getSessionManager()
.getAllActiveSessions();
for (var activeUserSession : allSessions) {
if (!isAcceptableInSession(activeUserSession, event)) {
log.debug("Cannot handle " + event.getTopicId() + " event '" + event.getId() +
"' in session " + activeUserSession.getSessionId());
continue;
if (event.getSessionId() != null) {
BaseWebSession session = WebAppUtils.getWebApplication().getSessionManager().findSessionBySmId(event.getSessionId());
if (session != null) {
log.debug(event.getTopicId() + " event '" + event.getId() + "' handled in session '" + event.getSessionId() + "'");
updateSessionData(session, event);
} else {
log.debug(event.getTopicId() + " event '" + event.getId() + "' not handled: session '" + event.getSessionId() + "' was not found.");

Check warning on line 38 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/events/WSDefaultEventHandler.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Line is longer than 140 characters (found 148). Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/events/WSDefaultEventHandler.java:38:0: warning: Line is longer than 140 characters (found 148). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
}
log.debug(event.getTopicId() + " event '" + event.getId() + "' handled");
updateSessionData(activeUserSession, event);
}
}

Expand Down
Loading