Hi!
Thanks.
I tried adding "User Session Count Limiter" to my authentication flow, but it did not seem to help. I was still able to keep two active sessions on two different devices.
Thereafter I modified my custom authenticator as follows.
I added the following code at the place where all normal checks (password and OTP verification) were succesful:
final List<UserSessionModel> activeSessions = lockUserSessionsForModification(session, () -> session.sessions().getUserSessionsStream(context.getRealm(), context.getUser()).collect(Collectors.toList()));
if (!activeSessions.isEmpty()) {
logoutOldestSession(activeSessions);
}
context.success();
logoutOldestSession looks like this:
private void logoutOldestSession(List<UserSessionModel> sessions) {
final Optional<UserSessionModel> oldest = sessions.stream().sorted(comparingInt(UserSessionModel::getLastSessionRefresh)).findFirst();
oldest.ifPresent(userSession -> backchannelLogout(session, userSession, true));
}This kind of works. If I
1. log in under user A on device 1,
2. log in under user A on dervice 2,
3. refresh the web application in the browser on device 1,
then, on device 1 I get redirected to the login page.
What I want is different in two ways:
1. I want the user on device 1 to be redirected to the login page more or less immediately (ideally -- even if they don't do anything in the browser).
2. The login page on device 1 should contain a message telling the user that they were logged out because of a login on another device.
Are these things achievable?
If yes, how?
Thanks