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 @Override
public void setTimestamp(int timestamp) { public void setTimestamp(int timestamp) {
if (timestamp <= getTimestamp()) {
return;
}
ClientSessionUpdateTask task = new ClientSessionUpdateTask() { ClientSessionUpdateTask task = new ClientSessionUpdateTask() {
@Override @Override

View file

@ -158,6 +158,7 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
clientSessionUuids.forEach(clientSessionId -> this.clientSessionUpdateTx.addTask(clientSessionId, Tasks.removeSync())); clientSessionUuids.forEach(clientSessionId -> this.clientSessionUpdateTx.addTask(clientSessionId, Tasks.removeSync()));
} }
@Override
public String getId() { public String getId() {
return entity.getId(); return entity.getId();
} }
@ -177,6 +178,7 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
return entity.getBrokerUserId(); return entity.getBrokerUserId();
} }
@Override
public UserModel getUser() { public UserModel getUser() {
return this.user; return this.user;
} }
@ -192,6 +194,7 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
} }
} }
@Override
public String getIpAddress() { public String getIpAddress() {
return entity.getIpAddress(); return entity.getIpAddress();
} }
@ -206,15 +209,22 @@ public class UserSessionAdapter<T extends SessionRefreshStore & UserSessionProvi
return entity.isRememberMe(); return entity.isRememberMe();
} }
@Override
public int getStarted() { public int getStarted() {
return entity.getStarted(); return entity.getStarted();
} }
@Override
public int getLastSessionRefresh() { public int getLastSessionRefresh() {
return entity.getLastSessionRefresh(); return entity.getLastSessionRefresh();
} }
@Override
public void setLastSessionRefresh(int lastSessionRefresh) { public void setLastSessionRefresh(int lastSessionRefresh) {
if (lastSessionRefresh <= entity.getLastSessionRefresh()) {
return;
}
if (offline) { 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. // 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. // The other DC already did.

View file

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

View file

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

View file

@ -49,6 +49,11 @@ public interface AuthenticatedClientSessionModel extends CommonClientSessionMode
} }
int getTimestamp(); 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); void setTimestamp(int timestamp);
/** /**

View file

@ -58,6 +58,10 @@ public interface UserSessionModel {
int getLastSessionRefresh(); 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); void setLastSessionRefresh(int seconds);
boolean isOffline(); boolean isOffline();