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);
}
}
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);
}
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);
}
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;
}
Aggregations