Search in sources :

Example 56 with AuthenticatedClientSessionModel

use of org.keycloak.models.AuthenticatedClientSessionModel in project keycloak by keycloak.

the class UserSessionPersisterProviderTest method persistUserSession.

private void persistUserSession(KeycloakSession session, UserSessionModel userSession, boolean offline) {
    UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
    persister.createUserSession(userSession, offline);
    for (AuthenticatedClientSessionModel clientSession : userSession.getAuthenticatedClientSessions().values()) {
        persister.createClientSession(clientSession, offline);
    }
}
Also used : UserSessionPersisterProvider(org.keycloak.models.session.UserSessionPersisterProvider) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel)

Example 57 with AuthenticatedClientSessionModel

use of org.keycloak.models.AuthenticatedClientSessionModel in project keycloak by keycloak.

the class SamlProtocol method buildArtifactAndStoreResponse.

protected String buildArtifactAndStoreResponse(SAML2Object statusResponseType, UserSessionModel userSession) throws ArtifactResolverProcessingException, ConfigurationException, ProcessingException {
    String clientIdThatInitiatedLogout = userSession.getNote(SAML_LOGOUT_INITIATOR_CLIENT_ID);
    userSession.removeNote(SAML_LOGOUT_INITIATOR_CLIENT_ID);
    AuthenticatedClientSessionModel clientSessionModel = userSession.getAuthenticatedClientSessionByClient(clientIdThatInitiatedLogout);
    if (clientSessionModel == null) {
        throw new IllegalStateException("Initiator client id is unknown when artifact response is created");
    }
    return buildArtifactAndStoreResponse(statusResponseType, clientSessionModel);
}
Also used : AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel)

Example 58 with AuthenticatedClientSessionModel

use of org.keycloak.models.AuthenticatedClientSessionModel in project keycloak by keycloak.

the class MapUserSessionAdapter method getAuthenticatedClientSessions.

@Override
public Map<String, AuthenticatedClientSessionModel> getAuthenticatedClientSessions() {
    Map<String, AuthenticatedClientSessionModel> result = new HashMap<>();
    List<String> removedClientUUIDS = new LinkedList<>();
    // to avoid concurrentModificationException
    Map<String, String> authenticatedClientSessions = new HashMap<>(entity.getAuthenticatedClientSessions());
    authenticatedClientSessions.forEach((clientUUID, clientSessionId) -> {
        ClientModel client = realm.getClientById(clientUUID);
        if (client != null) {
            AuthenticatedClientSessionModel clientSession = session.sessions().getClientSession(this, client, clientSessionId, isOffline());
            if (clientSession != null) {
                result.put(clientUUID, clientSession);
            }
        } else {
            removedClientUUIDS.add(clientUUID);
        }
    });
    removeAuthenticatedClientSessions(removedClientUUIDS);
    return Collections.unmodifiableMap(result);
}
Also used : ClientModel(org.keycloak.models.ClientModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel) LinkedList(java.util.LinkedList)

Example 59 with AuthenticatedClientSessionModel

use of org.keycloak.models.AuthenticatedClientSessionModel in project keycloak by keycloak.

the class AbstractRARParserTest method fetchAuthorizationRequestContextHolder.

/**
 * Fetch the {@link org.keycloak.rar.AuthorizationRequestContext} for the current Client session from the server
 * then create a local representation of the data to avoid an infinite recursion when trying to serialize the
 * ClientScopeModel object.
 *
 * @return the {@link AuthorizationRequestContextHolder} local testsuite representation of the Authorization Request Context
 * with all the parsed authorization_detail objects.
 */
protected AuthorizationRequestContextHolder fetchAuthorizationRequestContextHolder(String userId) {
    AuthorizationRequestContextHolder authorizationRequestContextHolder = testingClient.server("test").fetch(session -> {
        final RealmModel realm = session.realms().getRealmByName("test");
        final UserModel user = session.users().getUserById(realm, userId);
        final UserSessionModel userSession = session.sessions().getUserSessionsStream(realm, user).findFirst().get();
        final ClientModel client = realm.getClientByClientId("test-app");
        String clientUUID = client.getId();
        AuthenticatedClientSessionModel clientSession = userSession.getAuthenticatedClientSessionByClient(clientUUID);
        session.getContext().setClient(client);
        List<AuthorizationRequestContextHolder.AuthorizationRequestHolder> authorizationRequestHolders = AuthorizationContextUtil.getAuthorizationRequestContextFromScopes(session, clientSession.getNote(OAuth2Constants.SCOPE)).getAuthorizationDetailEntries().stream().map(AuthorizationRequestContextHolder.AuthorizationRequestHolder::new).collect(Collectors.toList());
        return new AuthorizationRequestContextHolder(authorizationRequestHolders);
    }, AuthorizationRequestContextHolder.class);
    assertNotNull("the fetched AuthorizationRequestContext can't be null", authorizationRequestContextHolder);
    return authorizationRequestContextHolder;
}
Also used : RealmModel(org.keycloak.models.RealmModel) UserModel(org.keycloak.models.UserModel) ClientModel(org.keycloak.models.ClientModel) UserSessionModel(org.keycloak.models.UserSessionModel) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel)

Aggregations

AuthenticatedClientSessionModel (org.keycloak.models.AuthenticatedClientSessionModel)59 UserSessionModel (org.keycloak.models.UserSessionModel)35 RealmModel (org.keycloak.models.RealmModel)25 ClientModel (org.keycloak.models.ClientModel)23 Test (org.junit.Test)16 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)13 UserModel (org.keycloak.models.UserModel)12 KeycloakSession (org.keycloak.models.KeycloakSession)11 ModelTest (org.keycloak.testsuite.arquillian.annotation.ModelTest)11 HashMap (java.util.HashMap)10 Map (java.util.Map)9 ClientSessionContext (org.keycloak.models.ClientSessionContext)9 LinkedList (java.util.LinkedList)8 DefaultClientSessionContext (org.keycloak.services.util.DefaultClientSessionContext)8 OAuthErrorException (org.keycloak.OAuthErrorException)6 VerificationException (org.keycloak.common.VerificationException)6 AccessToken (org.keycloak.representations.AccessToken)6 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)6 HashSet (java.util.HashSet)5 List (java.util.List)5