Search in sources :

Example 16 with ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity in project keycloak by keycloak.

the class InfinispanActionTokenStoreProvider method remove.

@Override
public ActionTokenValueModel remove(ActionTokenKeyModel actionTokenKey) {
    if (actionTokenKey == null || actionTokenKey.getUserId() == null || actionTokenKey.getActionId() == null) {
        return null;
    }
    ActionTokenReducedKey key = new ActionTokenReducedKey(actionTokenKey.getUserId(), actionTokenKey.getActionId(), actionTokenKey.getActionVerificationNonce());
    ActionTokenValueEntity value = this.actionKeyCache.get(key);
    if (value != null) {
        this.tx.remove(actionKeyCache, key);
    }
    return value;
}
Also used : ActionTokenReducedKey(org.keycloak.models.sessions.infinispan.entities.ActionTokenReducedKey) ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity)

Example 17 with ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity in project keycloak by keycloak.

the class InfinispanCodeToTokenStoreProvider method remove.

@Override
public Map<String, String> remove(UUID codeId) {
    try {
        BasicCache<UUID, ActionTokenValueEntity> cache = codeCache.get();
        ActionTokenValueEntity existing = cache.remove(codeId);
        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 code %s", codeId);
        }
        return null;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) UUID(java.util.UUID)

Example 18 with ActionTokenValueEntity

use of org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity in project keycloak by keycloak.

the class InfinispanCodeToTokenStoreProvider method put.

@Override
public void put(UUID codeId, int lifespanSeconds, Map<String, String> codeData) {
    ActionTokenValueEntity tokenValue = new ActionTokenValueEntity(codeData);
    try {
        BasicCache<UUID, ActionTokenValueEntity> cache = codeCache.get();
        long lifespanMs = InfinispanUtil.toHotrodTimeMs(cache, Time.toMillis(lifespanSeconds));
        cache.put(codeId, 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 code %s", codeId);
        }
        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