Hi Michael, sorry for late response,
Is that still topical for you?
Does your code actually print out anything ("Removing already existing offline
user")? i.e. are there offline sessions actually?
Cheers,
Dmitry Telegin
CTO, Acutus s.r.o.
Keycloak Consulting and Training
Pod lipami street 339/52, 130 00 Prague 3, Czech Republic
+42 (022) 888-30-71
E-mail: info(a)acutus.pro
On Sat, 2018-07-07 at 09:44 +0200, Michael Hunziker wrote:
Hi everyone!
I need some advice in implementing an EventListenerProvider that makes sure
that there is only one offline session/token per user (as soon as the user
logs in on another device the provider should make sure that the other
session/token is deleted).
I would expect that calling
"userSessionProvider.removeOfflineUserSession(realmModel, userSession);"
should be enough in the code below... But it does not delete anything in
"OFFLINE_CLIENT_SESSION" and "OFFLINE_USER_SESSION".
Am I missing something? Is this even doable?
Cheers Michael
@Override
public void onEvent(Event event) {
final String realmId = event.getRealmId();
final String userId = event.getUserId();
final EventType eventType = event.getType();
if (isRelevantEvent(realmId, eventType) && userId != null) {
RealmModel realmModel = realmProvider.getRealm(realmId);
UserModel userModel = session.users().getUserById(userId,
realmModel);
final UserSessionProvider userSessionProvider =
session.sessions();
final List<UserSessionModel> userSessions =
userSessionProvider.getOfflineUserSessions(realmModel, userModel);
userSessions.stream()
.filter(userSession ->
!userSession.getId().equals(event.getSessionId()))
.forEach(userSession -> {
log.warn("Removing already existing offline user
session {}", userSession.getId());
userSessionProvider.removeOfflineUserSession(realmModel, userSession);
});
}
}
private boolean isRelevantEvent(final String realmId, final EventType
eventType) {
return eventType != null && eventType == EventType.LOGIN &&
realmId != null && realmId.equals(MY_REALM);
}
_______________________________________________
keycloak-user mailing list
keycloak-user(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user