Search in sources :

Example 11 with HotRodClientException

use of org.infinispan.client.hotrod.exceptions.HotRodClientException in project keycloak by keycloak.

the class InfinispanOAuth2DeviceTokenStoreProvider method put.

@Override
public void put(OAuth2DeviceCodeModel deviceCode, OAuth2DeviceUserCodeModel userCode, int lifespanSeconds) {
    ActionTokenValueEntity deviceCodeValue = new ActionTokenValueEntity(deviceCode.toMap());
    ActionTokenValueEntity userCodeValue = new ActionTokenValueEntity(userCode.serializeValue());
    try {
        BasicCache<String, ActionTokenValueEntity> cache = codeCache.get();
        cache.put(deviceCode.serializeKey(), deviceCodeValue, lifespanSeconds, TimeUnit.SECONDS);
        cache.put(userCode.serializeKey(), userCodeValue, lifespanSeconds, TimeUnit.SECONDS);
    } catch (HotRodClientException re) {
        // No need to retry. The hotrod (remoteCache) has some retries in itself in case of some random network error happened.
        if (logger.isDebugEnabled()) {
            logger.debugf(re, "Failed when adding device code %s and user code %s", deviceCode.getDeviceCode(), userCode.getUserCode());
        }
        throw re;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 12 with HotRodClientException

use of org.infinispan.client.hotrod.exceptions.HotRodClientException in project keycloak by keycloak.

the class InfinispanOAuth2DeviceTokenStoreProvider method removeDeviceCode.

@Override
public boolean removeDeviceCode(RealmModel realm, String deviceCode) {
    try {
        BasicCache<String, ActionTokenValueEntity> cache = codeCache.get();
        String key = OAuth2DeviceCodeModel.createKey(deviceCode);
        ActionTokenValueEntity existing = cache.remove(key);
        return existing == null ? false : true;
    } catch (HotRodClientException re) {
        // In case of lock conflict, we don't want to retry anyway as there was likely an attempt to remove the code from different place.
        if (logger.isDebugEnabled()) {
            logger.debugf(re, "Failed when removing device code %s", deviceCode);
        }
        return false;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 13 with HotRodClientException

use of org.infinispan.client.hotrod.exceptions.HotRodClientException in project keycloak by keycloak.

the class InfinispanOAuth2DeviceTokenStoreProvider method removeUserCode.

@Override
public boolean removeUserCode(RealmModel realm, String userCode) {
    try {
        BasicCache<String, ActionTokenValueEntity> cache = codeCache.get();
        String key = OAuth2DeviceUserCodeModel.createKey(realm, userCode);
        ActionTokenValueEntity existing = cache.remove(key);
        return existing == null ? false : true;
    } catch (HotRodClientException re) {
        // In case of lock conflict, we don't want to retry anyway as there was likely an attempt to remove the code from different place.
        if (logger.isDebugEnabled()) {
            logger.debugf(re, "Failed when removing user code %s", userCode);
        }
        return false;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 14 with HotRodClientException

use of org.infinispan.client.hotrod.exceptions.HotRodClientException in project keycloak by keycloak.

the class InfinispanPushedAuthzRequestStoreProvider method remove.

@Override
public Map<String, String> remove(UUID key) {
    try {
        BasicCache<UUID, ActionTokenValueEntity> cache = parDataCache.get();
        ActionTokenValueEntity existing = cache.remove(key);
        return existing == null ? null : existing.getNotes();
    } catch (HotRodClientException re) {
        // In case of lock conflict, we don't want to retry anyway as there was likely an attempt to remove the code from different place.
        if (logger.isDebugEnabled()) {
            logger.debugf(re, "Failed when removing PAR data for redirect URI %s", key);
        }
        return null;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) UUID(java.util.UUID)

Example 15 with HotRodClientException

use of org.infinispan.client.hotrod.exceptions.HotRodClientException in project keycloak by keycloak.

the class InfinispanPushedAuthzRequestStoreProvider method put.

@Override
public void put(UUID key, int lifespanSeconds, Map<String, String> codeData) {
    ActionTokenValueEntity tokenValue = new ActionTokenValueEntity(codeData);
    try {
        BasicCache<UUID, ActionTokenValueEntity> cache = parDataCache.get();
        long lifespanMs = InfinispanUtil.toHotrodTimeMs(cache, Time.toMillis(lifespanSeconds));
        cache.put(key, tokenValue, lifespanMs, TimeUnit.MILLISECONDS);
    } catch (HotRodClientException re) {
        // No need to retry. The hotrod (remoteCache) has some retries in itself in case of some random network error happened.
        if (logger.isDebugEnabled()) {
            logger.debugf(re, "Failed when adding PAR data for redirect URI: %s", key);
        }
        throw re;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) UUID(java.util.UUID)

Aggregations

HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)21 ActionTokenValueEntity (org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity)14 UUID (java.util.UUID)5 RemoteCache (org.infinispan.client.hotrod.RemoteCache)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Consumer (java.util.function.Consumer)2 OAuth2DeviceCodeModel (org.keycloak.models.OAuth2DeviceCodeModel)2 SessionUpdateTask (org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiFunction (java.util.function.BiFunction)1