Skip to content

Commit 57a5171

Browse files
CB-5158 do not send event to initiator for generating domain (#2655)
Co-authored-by: kseniaguzeeva <[email protected]>
1 parent c893e47 commit 57a5171

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/BaseWebSession.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,24 @@ public synchronized WebUserContext getUserContext() {
173173
@Override
174174
public void close() {
175175
super.close();
176-
cleanUpSession();
176+
cleanUpSession(true);
177177
}
178178

179-
public void close(boolean clearTokens) {
180-
cleanUpSession();
179+
public void close(boolean clearTokens, boolean sendSessionExpiredEvent) {
180+
cleanUpSession(sendSessionExpiredEvent);
181181
}
182182

183-
private void cleanUpSession() {
184-
var sessionExpiredEvent = new WSSessionExpiredEvent();
183+
private void cleanUpSession(boolean sendSessionExpiredEvent) {
185184
application.getEventController().addEvent(new WSEventDeleteTempFile(getSessionId()));
186185
synchronized (sessionEventHandlers) {
186+
var sessionExpiredEvent = new WSSessionExpiredEvent();
187187
for (CBWebSessionEventHandler sessionEventHandler : sessionEventHandlers) {
188-
try {
189-
sessionEventHandler.handleWebSessionEvent(sessionExpiredEvent);
190-
} catch (DBException e) {
191-
log.warn("Failed to send session expiration event", e);
188+
if (sendSessionExpiredEvent) {
189+
try {
190+
sessionEventHandler.handleWebSessionEvent(sessionExpiredEvent);
191+
} catch (DBException e) {
192+
log.warn("Failed to send session expiration event", e);
193+
}
192194
}
193195
sessionEventHandler.close();
194196
}

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ public void close() {
645645
}
646646

647647
@Override
648-
public void close(boolean clearTokens) {
648+
public void close(boolean clearTokens, boolean sendSessionExpiredEvent) {
649649
try {
650650
resetNavigationModel();
651651
resetSessionCache();
@@ -660,7 +660,7 @@ public void close(boolean clearTokens) {
660660
}
661661
}
662662
this.userContext.setUser(null);
663-
super.close(clearTokens);
663+
super.close(clearTokens, sendSessionExpiredEvent);
664664
}
665665

666666
private List<WebAuthInfo> clearAuthTokens() throws DBException {

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/events/WSUserEventHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void handleEvent(@NotNull EVENT event) {
3737
case CLOSE_USER_SESSIONS:
3838
if (event instanceof WSUserCloseSessionsEvent closeSessionsEvent) {
3939
if (closeSessionsEvent.getSessionIds().isEmpty()) {
40-
sessionManager.closeAllSessions();
40+
sessionManager.closeAllSessions(closeSessionsEvent.getSessionId());
4141
} else {
4242
sessionManager.closeSessions(closeSessionsEvent.getSessionIds());
4343
}

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/session/WebSessionManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.cloudbeaver.registry.WebHandlerRegistry;
2626
import io.cloudbeaver.registry.WebSessionHandlerDescriptor;
2727
import io.cloudbeaver.server.CBApplication;
28+
import io.cloudbeaver.server.events.WSWebUtils;
2829
import io.cloudbeaver.service.DBWSessionHandler;
2930
import jakarta.servlet.http.HttpServletRequest;
3031
import jakarta.servlet.http.HttpServletResponse;
@@ -364,7 +365,7 @@ public void closeSessions(@NotNull List<String> smSessionsId) {
364365
var session = iterator.next();
365366
if (smSessionsId.contains(session.getUserContext().getSmSessionId())) {
366367
iterator.remove();
367-
session.close(false);
368+
session.close(false, true);
368369
}
369370
}
370371
}
@@ -373,12 +374,12 @@ public void closeSessions(@NotNull List<String> smSessionsId) {
373374
/**
374375
* Closes all sessions in session manager.
375376
*/
376-
public void closeAllSessions() {
377+
public void closeAllSessions(@Nullable String initiatorSessionId) {
377378
synchronized (sessionMap) {
378379
for (Iterator<BaseWebSession> iterator = sessionMap.values().iterator(); iterator.hasNext(); ) {
379380
var session = iterator.next();
380381
iterator.remove();
381-
session.close(false);
382+
session.close(false, !WSWebUtils.isSessionIdEquals(session, initiatorSessionId));
382383
}
383384
}
384385
}

server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ public void invalidateAllTokens() throws DBCException {
19051905
} catch (SQLException e) {
19061906
throw new DBCException("Session invalidation failed", e);
19071907
}
1908-
application.getEventController().addEvent(new WSUserCloseSessionsEvent(List.of()));
1908+
application.getEventController().addEvent(new WSUserCloseSessionsEvent(List.of(), getSmSessionId(), getUserId()));
19091909
}
19101910

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

24052405
/**

0 commit comments

Comments
 (0)