Search in sources :

Example 1 with HotRodClientException

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

the class RemoteCacheProvider method loadRemoteCache.

protected synchronized RemoteCache loadRemoteCache(String cacheName) {
    RemoteCache remoteCache = InfinispanUtil.getRemoteCache(cacheManager.getCache(cacheName));
    if (remoteCache != null) {
        logger.infof("Hotrod version for remoteCache %s: %s", remoteCache.getName(), remoteCache.getRemoteCacheManager().getConfiguration().version());
    }
    Boolean remoteStoreSecurity = config.getBoolean("remoteStoreSecurityEnabled");
    if (remoteStoreSecurity == null) {
        try {
            logger.debugf("Detecting remote security settings of HotRod server, cache %s. Disable by explicitly setting \"remoteStoreSecurityEnabled\" property in spi=connectionsInfinispan/provider=default", cacheName);
            remoteStoreSecurity = false;
            final RemoteCache<Object, Object> scriptCache = remoteCache.getRemoteCacheManager().getCache(SCRIPT_CACHE_NAME);
            if (scriptCache == null) {
                logger.debug("Cannot detect remote security settings of HotRod server, disabling.");
            } else {
                scriptCache.containsKey("");
            }
        } catch (HotRodClientException ex) {
            logger.debug("Seems that HotRod server requires authentication, enabling.");
            remoteStoreSecurity = true;
        }
    }
    if (remoteStoreSecurity) {
        logger.infof("Remote store security for cache %s is enabled. Disable by setting \"remoteStoreSecurityEnabled\" property to \"false\" in spi=connectionsInfinispan/provider=default", cacheName);
        RemoteCacheManager securedMgr = getOrCreateSecuredRemoteCacheManager(config, cacheName, remoteCache.getRemoteCacheManager());
        return securedMgr.getCache(remoteCache.getName());
    } else {
        logger.infof("Remote store security for cache %s is disabled. If server fails to connect to remote JDG server, enable it.", cacheName);
        return remoteCache;
    }
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) RemoteCache(org.infinispan.client.hotrod.RemoteCache) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 2 with HotRodClientException

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

the class InfinispanTokenRevocationStoreProvider method isRevoked.

@Override
public boolean isRevoked(String tokenId) {
    try {
        BasicCache<String, ActionTokenValueEntity> cache = tokenCache.get();
        ActionTokenValueEntity existing = cache.get(tokenId);
        if (existing == null) {
            return false;
        }
        return existing.getNotes().containsKey(REVOKED_KEY);
    } 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 trying to get revoked token %s", tokenId);
        }
        return false;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 3 with HotRodClientException

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

the class InfinispanOAuth2DeviceTokenStoreProvider method deny.

@Override
public boolean deny(RealmModel realm, String userCode) {
    try {
        OAuth2DeviceCodeModel deviceCode = findDeviceCodeByUserCode(realm, userCode);
        if (deviceCode == null) {
            return false;
        }
        OAuth2DeviceCodeModel denied = deviceCode.deny();
        BasicCache<String, ActionTokenValueEntity> cache = codeCache.get();
        cache.replace(denied.serializeKey(), new ActionTokenValueEntity(denied.toMap()));
        return 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 denying device user code %s", userCode);
        }
        return false;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) OAuth2DeviceCodeModel(org.keycloak.models.OAuth2DeviceCodeModel) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 4 with HotRodClientException

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

the class InfinispanOAuth2DeviceTokenStoreProvider method approve.

@Override
public boolean approve(RealmModel realm, String userCode, String userSessionId, Map<String, String> additionalParams) {
    try {
        OAuth2DeviceCodeModel deviceCode = findDeviceCodeByUserCode(realm, userCode);
        if (deviceCode == null) {
            return false;
        }
        OAuth2DeviceCodeModel approved = deviceCode.approve(userSessionId, additionalParams);
        // Update the device code with approved status
        BasicCache<String, ActionTokenValueEntity> cache = codeCache.get();
        cache.replace(approved.serializeKey(), new ActionTokenValueEntity(approved.toMap()));
        return 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 verifying device user code %s", userCode);
        }
        return false;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) OAuth2DeviceCodeModel(org.keycloak.models.OAuth2DeviceCodeModel) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

Example 5 with HotRodClientException

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

the class InfinispanOAuth2DeviceTokenStoreProvider method getByDeviceCode.

@Override
public OAuth2DeviceCodeModel getByDeviceCode(RealmModel realm, String deviceCode) {
    try {
        BasicCache<String, ActionTokenValueEntity> cache = codeCache.get();
        ActionTokenValueEntity existing = cache.get(OAuth2DeviceCodeModel.createKey(deviceCode));
        if (existing == null) {
            return null;
        }
        return OAuth2DeviceCodeModel.fromCache(realm, deviceCode, 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 getting device code %s", deviceCode);
        }
        return null;
    }
}
Also used : ActionTokenValueEntity(org.keycloak.models.sessions.infinispan.entities.ActionTokenValueEntity) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException)

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