use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class UserSessionProviderTest method testUpdateClientSession.
@Test
@ModelTest
public void testUpdateClientSession(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
UserSessionModel[] sessions = createSessions(session);
String userSessionId = sessions[0].getId();
String clientUUID = realm.getClientByClientId("test-app").getId();
UserSessionModel userSession = session.sessions().getUserSession(realm, userSessionId);
AuthenticatedClientSessionModel clientSession = userSession.getAuthenticatedClientSessions().get(clientUUID);
int time = clientSession.getTimestamp();
assertNull(clientSession.getAction());
clientSession.setAction(AuthenticatedClientSessionModel.Action.LOGGED_OUT.name());
clientSession.setTimestamp(time + 10);
AuthenticatedClientSessionModel updated = session.sessions().getUserSession(realm, userSessionId).getAuthenticatedClientSessions().get(clientUUID);
assertEquals(AuthenticatedClientSessionModel.Action.LOGGED_OUT.name(), updated.getAction());
assertEquals(time + 10, updated.getTimestamp());
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class UserSessionProviderTest method testRestartSession.
@Test
@ModelTest
public void testRestartSession(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
int started = Time.currentTime();
UserSessionModel[] sessions = createSessions(session);
Time.setOffset(100);
UserSessionModel userSession = session.sessions().getUserSession(realm, sessions[0].getId());
assertSession(userSession, session.users().getUserByUsername(realm, "user1"), "127.0.0.1", started, started, "test-app", "third-party");
userSession.restartSession(realm, session.users().getUserByUsername(realm, "user2"), "user2", "127.0.0.6", "form", true, null, null);
userSession = session.sessions().getUserSession(realm, sessions[0].getId());
assertSession(userSession, session.users().getUserByUsername(realm, "user2"), "127.0.0.6", started + 100, started + 100);
Time.setOffset(0);
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class UserSessionProviderTest method testUpdateSession.
@Test
@ModelTest
public void testUpdateSession(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
UserSessionModel[] sessions = createSessions(session);
int lastRefresh = Time.currentTime();
session.sessions().getUserSession(realm, sessions[0].getId()).setLastSessionRefresh(lastRefresh);
assertEquals(lastRefresh, session.sessions().getUserSession(realm, sessions[0].getId()).getLastSessionRefresh());
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class UserSessionProviderTest method testGetUserSessions.
@Test
@ModelTest
public void testGetUserSessions(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
UserSessionModel[] sessions = createSessions(session);
assertSessions(session.sessions().getUserSessionsStream(realm, session.users().getUserByUsername(realm, "user1")).collect(Collectors.toList()), sessions[0], sessions[1]);
assertSessions(session.sessions().getUserSessionsStream(realm, session.users().getUserByUsername(realm, "user2")).collect(Collectors.toList()), sessions[2]);
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class UserSessionProviderTest method testRemoveUserSession.
@Test
@ModelTest
public void testRemoveUserSession(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
UserSessionModel userSession = createSessions(session)[0];
session.sessions().removeUserSession(realm, userSession);
assertNull(session.sessions().getUserSession(realm, userSession.getId()));
}
Aggregations