Search in sources :

Example 11 with ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity 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 ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity 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 ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity 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 ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity 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 ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity 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

ActionTokenValueEntity (org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity)18 HotRodClientException (org.infinispan.client.hotrod.exceptions.HotRodClientException)14 UUID (java.util.UUID)4 ActionTokenReducedKey (org.keycloak.models.sessions.infinispan.entities.ActionTokenReducedKey)3 OAuth2DeviceCodeModel (org.keycloak.models.OAuth2DeviceCodeModel)2 InfinispanConnectionProvider (org.keycloak.connections.infinispan.InfinispanConnectionProvider)1 OAuth2DeviceUserCodeModel (org.keycloak.models.OAuth2DeviceUserCodeModel)1