Skip to content

Commit

Permalink
CB-5158 do not send event to initiator for generating domain (#2655)
Browse files Browse the repository at this point in the history
Co-authored-by: kseniaguzeeva <[email protected]>
  • Loading branch information
yagudin10 and kseniaguzeeva authored May 27, 2024
1 parent c893e47 commit 57a5171
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,24 @@ public synchronized WebUserContext getUserContext() {
@Override
public void close() {
super.close();
cleanUpSession();
cleanUpSession(true);
}

public void close(boolean clearTokens) {
cleanUpSession();
public void close(boolean clearTokens, boolean sendSessionExpiredEvent) {
cleanUpSession(sendSessionExpiredEvent);
}

private void cleanUpSession() {
var sessionExpiredEvent = new WSSessionExpiredEvent();
private void cleanUpSession(boolean sendSessionExpiredEvent) {
application.getEventController().addEvent(new WSEventDeleteTempFile(getSessionId()));
synchronized (sessionEventHandlers) {
var sessionExpiredEvent = new WSSessionExpiredEvent();
for (CBWebSessionEventHandler sessionEventHandler : sessionEventHandlers) {
try {
sessionEventHandler.handleWebSessionEvent(sessionExpiredEvent);
} catch (DBException e) {
log.warn("Failed to send session expiration event", e);
if (sendSessionExpiredEvent) {
try {
sessionEventHandler.handleWebSessionEvent(sessionExpiredEvent);
} catch (DBException e) {
log.warn("Failed to send session expiration event", e);
}
}
sessionEventHandler.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public void close() {
}

@Override
public void close(boolean clearTokens) {
public void close(boolean clearTokens, boolean sendSessionExpiredEvent) {
try {
resetNavigationModel();
resetSessionCache();
Expand All @@ -660,7 +660,7 @@ public void close(boolean clearTokens) {
}
}
this.userContext.setUser(null);
super.close(clearTokens);
super.close(clearTokens, sendSessionExpiredEvent);
}

private List<WebAuthInfo> clearAuthTokens() throws DBException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void handleEvent(@NotNull EVENT event) {
case CLOSE_USER_SESSIONS:
if (event instanceof WSUserCloseSessionsEvent closeSessionsEvent) {
if (closeSessionsEvent.getSessionIds().isEmpty()) {
sessionManager.closeAllSessions();
sessionManager.closeAllSessions(closeSessionsEvent.getSessionId());
} else {
sessionManager.closeSessions(closeSessionsEvent.getSessionIds());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.cloudbeaver.registry.WebHandlerRegistry;
import io.cloudbeaver.registry.WebSessionHandlerDescriptor;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.events.WSWebUtils;
import io.cloudbeaver.service.DBWSessionHandler;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -364,7 +365,7 @@ public void closeSessions(@NotNull List<String> smSessionsId) {
var session = iterator.next();
if (smSessionsId.contains(session.getUserContext().getSmSessionId())) {
iterator.remove();
session.close(false);
session.close(false, true);
}
}
}
Expand All @@ -373,12 +374,12 @@ public void closeSessions(@NotNull List<String> smSessionsId) {
/**
* Closes all sessions in session manager.
*/
public void closeAllSessions() {
public void closeAllSessions(@Nullable String initiatorSessionId) {
synchronized (sessionMap) {
for (Iterator<BaseWebSession> iterator = sessionMap.values().iterator(); iterator.hasNext(); ) {
var session = iterator.next();
iterator.remove();
session.close(false);
session.close(false, !WSWebUtils.isSessionIdEquals(session, initiatorSessionId));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ public void invalidateAllTokens() throws DBCException {
} catch (SQLException e) {
throw new DBCException("Session invalidation failed", e);
}
application.getEventController().addEvent(new WSUserCloseSessionsEvent(List.of()));
application.getEventController().addEvent(new WSUserCloseSessionsEvent(List.of(), getSmSessionId(), getUserId()));
}

private void invalidateAllUserTokens(@NotNull String userId) throws DBCException {
Expand Down Expand Up @@ -2399,7 +2399,7 @@ protected void killAllExistsUserSessions(
List<String> smSessionsId = findActiveUserSessions(userId, currentTime)
.stream().map(SMActiveSession::sessionId).collect(Collectors.toList());
deleteSessionsTokens(smSessionsId);
application.getEventController().addEvent(new WSUserCloseSessionsEvent(smSessionsId));
application.getEventController().addEvent(new WSUserCloseSessionsEvent(smSessionsId, getSmSessionId(), getUserId()));
}

/**
Expand Down

0 comments on commit 57a5171

Please sign in to comment.