use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class SamlSessionUtils method getClientSession.
public static AuthenticatedClientSessionModel getClientSession(KeycloakSession session, RealmModel realm, String sessionIndex) {
if (sessionIndex == null) {
return null;
}
String[] parts = PATTERN.split(sessionIndex);
if (parts.length != 2) {
return null;
}
String userSessionId = parts[0];
String clientUUID = parts[1];
UserSessionModel userSession = new UserSessionCrossDCManager(session).getUserSessionWithClient(realm, userSessionId, false, clientUUID);
if (userSession == null) {
return null;
}
return userSession.getAuthenticatedClientSessionByClient(clientUUID);
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class SamlSessionUtils method getSessionIndex.
public static String getSessionIndex(AuthenticatedClientSessionModel clientSession) {
UserSessionModel userSession = clientSession.getUserSession();
ClientModel client = clientSession.getClient();
return userSession.getId() + DELIMITER + client.getId();
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class TestingResourceProvider method removeUserSession.
@POST
@Path("/remove-user-session")
@Produces(MediaType.APPLICATION_JSON)
public Response removeUserSession(@QueryParam("realm") final String name, @QueryParam("session") final String sessionId) {
RealmModel realm = getRealmByName(name);
UserSessionModel sessionModel = session.sessions().getUserSession(realm, sessionId);
if (sessionModel == null) {
throw new NotFoundException("Session not found");
}
session.sessions().removeUserSession(realm, sessionModel);
return Response.noContent().build();
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class TestingResourceProvider method getLastSessionRefresh.
@GET
@Path("/get-last-session-refresh")
@Produces(MediaType.APPLICATION_JSON)
public Integer getLastSessionRefresh(@QueryParam("realm") final String name, @QueryParam("session") final String sessionId, @QueryParam("offline") boolean offline) {
RealmModel realm = getRealmByName(name);
UserSessionModel sessionModel = offline ? session.sessions().getOfflineUserSession(realm, sessionId) : session.sessions().getUserSession(realm, sessionId);
if (sessionModel == null) {
throw new NotFoundException("Session not found");
}
return sessionModel.getLastSessionRefresh();
}
use of org.keycloak.models.UserSessionModel in project keycloak by keycloak.
the class LoginTimeoutValidationTest method testIsLoginTimeoutValid.
@Test
@ModelTest
public void testIsLoginTimeoutValid(KeycloakSession keycloakSession) {
RealmModel realm = keycloakSession.realms().getRealmByName("test");
UserSessionModel userSession = keycloakSession.sessions().createUserSession(realm, keycloakSession.users().getUserByUsername(realm, "user1"), "user1", "127.0.0.1", "form", true, null, null);
ClientModel client = realm.getClientByClientId("account");
AuthenticationSessionModel authSession = keycloakSession.authenticationSessions().createRootAuthenticationSession(realm).createAuthenticationSession(client);
ClientSessionCode clientSessionCode = new ClientSessionCode(keycloakSession, realm, authSession);
/*
* KEYCLOAK-10636 Large Login timeout causes login failure
* realm > Realm setting > Tokens > Login timeout
*/
// Login timeout
int accessCodeLifespanLoginOrig = realm.getAccessCodeLifespanLogin();
realm.setAccessCodeLifespanLogin(Integer.MAX_VALUE);
Assert.assertTrue("Login validataion with large Login Timeout failed", clientSessionCode.isActionActive(ClientSessionCode.ActionType.LOGIN));
realm.setAccessCodeLifespanLogin(accessCodeLifespanLoginOrig);
/*
* KEYCLOAK-10637 Large Login Action timeout causes login failure
* realm > Realm setting > Tokens > Login Action timeout
*/
// Login Action timeout
int accessCodeLifespanUserActionOrig = realm.getAccessCodeLifespanUserAction();
realm.setAccessCodeLifespanUserAction(Integer.MAX_VALUE);
Assert.assertTrue("Login validataion with large Login Action Timeout failed", clientSessionCode.isActionActive(ClientSessionCode.ActionType.USER));
realm.setAccessCodeLifespanUserAction(accessCodeLifespanUserActionOrig);
}
Aggregations