Avoid unnecessary updates to the sessions during refreshes of tokens

Closes #28388

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2024-04-03 11:05:02 +02:00 committed by Alexander Schwartz
parent dc18bd4efb
commit 63e7523a6d
6 changed files with 29 additions and 0 deletions

View file

@ -136,6 +136,10 @@ public class AuthenticatedClientSessionAdapter implements AuthenticatedClientSes
@Override
public void setTimestamp(int timestamp) {
if (timestamp <= getTimestamp()) {
return;
}
ClientSessionUpdateTask task = new ClientSessionUpdateTask() {
@Override

View file

@ -158,6 +158,7 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
clientSessionUuids.forEach(clientSessionId -> this.clientSessionUpdateTx.addTask(clientSessionId, Tasks.removeSync()));
}
@Override
public String getId() {
return entity.getId();
}
@ -177,6 +178,7 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
return entity.getBrokerUserId();
}
@Override
public UserModel getUser() {
return this.user;
}
@ -192,6 +194,7 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
}
}
@Override
public String getIpAddress() {
return entity.getIpAddress();
}
@ -206,15 +209,22 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
return entity.isRememberMe();
}
@Override
public int getStarted() {
return entity.getStarted();
}
@Override
public int getLastSessionRefresh() {
return entity.getLastSessionRefresh();
}
@Override
public void setLastSessionRefresh(int lastSessionRefresh) {
if (lastSessionRefresh <= entity.getLastSessionRefresh()) {
return;
}
if (offline) {
// Received the message from the other DC that we should update the lastSessionRefresh in local cluster. Don't update DB in that case.
// The other DC already did.

View file

@ -182,6 +182,9 @@ public class PersistentAuthenticatedClientSessionAdapter implements Authenticate
@Override
public void setTimestamp(int timestamp) {
if (timestamp <= model.getTimestamp()) {
return;
}
model.setTimestamp(timestamp);
}

View file

@ -250,6 +250,9 @@ public class PersistentUserSessionAdapter implements OfflineUserSessionModel {
@Override
public void setLastSessionRefresh(int seconds) {
if (seconds <= getLastSessionRefresh()) {
return;
}
model.setLastSessionRefresh(seconds);
}

View file

@ -49,6 +49,11 @@ public interface AuthenticatedClientSessionModel extends CommonClientSessionMode
}
int getTimestamp();
/**
* Set the timestamp for the client session.
* If the timestamp is smaller or equal than the current timestamp, the operation is ignored.
*/
void setTimestamp(int timestamp);
/**

View file

@ -58,6 +58,10 @@ public interface UserSessionModel {
int getLastSessionRefresh();
/**
* Set the last session refresh timestamp for the user session.
* If the timestamp is smaller or equal than the current timestamp, the operation is ignored.
*/
void setLastSessionRefresh(int seconds);
boolean isOffline();