Search in sources :

Example 1 with CachedUserConsents

use of org.keycloak.models.cache.infinispan.entities.CachedUserConsents in project keycloak by keycloak.

the class UserCacheSession method getConsentsStream.

@Override
public Stream<UserConsentModel> getConsentsStream(RealmModel realm, String userId) {
    logger.tracev("getConsents: {0}", userId);
    String cacheKey = getConsentCacheKey(userId);
    if (realmInvalidations.contains(realm.getId()) || invalidations.contains(userId) || invalidations.contains(cacheKey)) {
        return getDelegate().getConsentsStream(realm, userId);
    }
    CachedUserConsents cached = cache.get(cacheKey, CachedUserConsents.class);
    if (cached == null) {
        Long loaded = cache.getCurrentRevision(cacheKey);
        List<UserConsentModel> consents = getDelegate().getConsentsStream(realm, userId).collect(Collectors.toList());
        cached = new CachedUserConsents(loaded, cacheKey, realm, consents);
        cache.addRevisioned(cached, startupRevision);
        return consents.stream();
    } else {
        return cached.getConsents().values().stream().map(cachedConsent -> toConsentModel(realm, cachedConsent)).filter(Objects::nonNull);
    }
}
Also used : InvalidationEvent(org.keycloak.models.cache.infinispan.events.InvalidationEvent) ClientModel(org.keycloak.models.ClientModel) ReadOnlyUserModelDelegate(org.keycloak.models.utils.ReadOnlyUserModelDelegate) CachedUser(org.keycloak.models.cache.infinispan.entities.CachedUser) ClientStorageProvider(org.keycloak.storage.client.ClientStorageProvider) ProtocolMapperModel(org.keycloak.models.ProtocolMapperModel) UserConsentsUpdatedEvent(org.keycloak.models.cache.infinispan.events.UserConsentsUpdatedEvent) KeycloakModelUtils(org.keycloak.models.utils.KeycloakModelUtils) Logger(org.jboss.logging.Logger) CacheableStorageProviderModel(org.keycloak.storage.CacheableStorageProviderModel) HashMap(java.util.HashMap) OnUserCache(org.keycloak.models.cache.OnUserCache) UserFederationLinkRemovedEvent(org.keycloak.models.cache.infinispan.events.UserFederationLinkRemovedEvent) StorageId(org.keycloak.storage.StorageId) KeycloakTransaction(org.keycloak.models.KeycloakTransaction) UserCacheRealmInvalidationEvent(org.keycloak.models.cache.infinispan.events.UserCacheRealmInvalidationEvent) HashSet(java.util.HashSet) ClusterProvider(org.keycloak.cluster.ClusterProvider) UserUpdatedEvent(org.keycloak.models.cache.infinispan.events.UserUpdatedEvent) UserModel(org.keycloak.models.UserModel) UserListQuery(org.keycloak.models.cache.infinispan.entities.UserListQuery) CachedUserConsent(org.keycloak.models.cache.infinispan.entities.CachedUserConsent) UserConsentModel(org.keycloak.models.UserConsentModel) Map(java.util.Map) ComponentModel(org.keycloak.component.ComponentModel) CachedUserConsents(org.keycloak.models.cache.infinispan.entities.CachedUserConsents) GroupModel(org.keycloak.models.GroupModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) FederatedIdentityModel(org.keycloak.models.FederatedIdentityModel) ClientScopeModel(org.keycloak.models.ClientScopeModel) RealmModel(org.keycloak.models.RealmModel) CachedFederatedIdentityLinks(org.keycloak.models.cache.infinispan.entities.CachedFederatedIdentityLinks) InIdentityProviderPredicate(org.keycloak.models.cache.infinispan.stream.InIdentityProviderPredicate) UserStorageProvider(org.keycloak.storage.UserStorageProvider) UserFederationLinkUpdatedEvent(org.keycloak.models.cache.infinispan.events.UserFederationLinkUpdatedEvent) KeycloakSession(org.keycloak.models.KeycloakSession) Set(java.util.Set) RoleModel(org.keycloak.models.RoleModel) IdentityProviderModel(org.keycloak.models.IdentityProviderModel) CachedUserModel(org.keycloak.models.cache.CachedUserModel) Collectors(java.util.stream.Collectors) UserFullInvalidationEvent(org.keycloak.models.cache.infinispan.events.UserFullInvalidationEvent) Objects(java.util.Objects) UserProvider(org.keycloak.models.UserProvider) ServiceAccountConstants(org.keycloak.common.constants.ServiceAccountConstants) List(java.util.List) Stream(java.util.stream.Stream) UserCache(org.keycloak.models.cache.UserCache) Objects(java.util.Objects) CachedUserConsents(org.keycloak.models.cache.infinispan.entities.CachedUserConsents) UserConsentModel(org.keycloak.models.UserConsentModel)

Example 2 with CachedUserConsents

use of org.keycloak.models.cache.infinispan.entities.CachedUserConsents in project keycloak by keycloak.

the class UserCacheSession method getConsentByClient.

@Override
public UserConsentModel getConsentByClient(RealmModel realm, String userId, String clientId) {
    logger.tracev("getConsentByClient: {0}", userId);
    String cacheKey = getConsentCacheKey(userId);
    if (realmInvalidations.contains(realm.getId()) || invalidations.contains(userId) || invalidations.contains(cacheKey)) {
        return getDelegate().getConsentByClient(realm, userId, clientId);
    }
    CachedUserConsents cached = cache.get(cacheKey, CachedUserConsents.class);
    if (cached == null) {
        Long loaded = cache.getCurrentRevision(cacheKey);
        List<UserConsentModel> consents = getDelegate().getConsentsStream(realm, userId).collect(Collectors.toList());
        cached = new CachedUserConsents(loaded, cacheKey, realm, consents);
        cache.addRevisioned(cached, startupRevision);
    }
    CachedUserConsent cachedConsent = cached.getConsents().get(clientId);
    if (cachedConsent == null)
        return null;
    return toConsentModel(realm, cachedConsent);
}
Also used : CachedUserConsents(org.keycloak.models.cache.infinispan.entities.CachedUserConsents) CachedUserConsent(org.keycloak.models.cache.infinispan.entities.CachedUserConsent) UserConsentModel(org.keycloak.models.UserConsentModel)

Aggregations

UserConsentModel (org.keycloak.models.UserConsentModel)2 CachedUserConsent (org.keycloak.models.cache.infinispan.entities.CachedUserConsent)2 CachedUserConsents (org.keycloak.models.cache.infinispan.entities.CachedUserConsents)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Logger (org.jboss.logging.Logger)1 ClusterProvider (org.keycloak.cluster.ClusterProvider)1 ServiceAccountConstants (org.keycloak.common.constants.ServiceAccountConstants)1 ComponentModel (org.keycloak.component.ComponentModel)1 ClientModel (org.keycloak.models.ClientModel)1 ClientScopeModel (org.keycloak.models.ClientScopeModel)1 FederatedIdentityModel (org.keycloak.models.FederatedIdentityModel)1 GroupModel (org.keycloak.models.GroupModel)1 IdentityProviderModel (org.keycloak.models.IdentityProviderModel)1