use of org.keycloak.storage.client.ClientStorageProviderModel in project keycloak by keycloak.
the class ClientStorageTest method testNoCache.
@Test
public void testNoCache() {
testIsCached();
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.NO_CACHE);
realm.updateComponent(model);
});
testNotCached();
// test twice because updating component should evict
testNotCached();
// set it back
setDefaultCachePolicy();
testIsCached();
}
use of org.keycloak.storage.client.ClientStorageProviderModel in project keycloak by keycloak.
the class ClientStorageTest method testMaxLifespan.
@Test
public void testMaxLifespan() {
testIsCached();
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.MAX_LIFESPAN);
model.setMaxLifespan(1 * 60 * 60 * 1000);
realm.updateComponent(model);
});
testIsCached();
// 1/2 hour in future
setTimeOffset(1 / 2 * 60 * 60);
testIsCached();
// 2 hours in future
setTimeOffset(2 * 60 * 60);
testNotCached();
testIsCached();
setDefaultCachePolicy();
testIsCached();
}
use of org.keycloak.storage.client.ClientStorageProviderModel in project keycloak by keycloak.
the class ClientStorageTest method testWeeklyEviction.
@Test
public void testWeeklyEviction() {
testIsCached();
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findAny().get();
Calendar eviction = Calendar.getInstance();
eviction.add(Calendar.HOUR, 4 * 24);
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.EVICT_WEEKLY);
model.setEvictionDay(eviction.get(DAY_OF_WEEK));
model.setEvictionHour(eviction.get(HOUR_OF_DAY));
model.setEvictionMinute(eviction.get(MINUTE));
realm.updateComponent(model);
});
testIsCached();
// 2 days in future
setTimeOffset(2 * 24 * 60 * 60);
testIsCached();
// 5 days in future
setTimeOffset(5 * 24 * 60 * 60);
testNotCached();
testIsCached();
setDefaultCachePolicy();
testIsCached();
}
use of org.keycloak.storage.client.ClientStorageProviderModel in project keycloak by keycloak.
the class RealmCacheSession method validateCache.
protected ClientModel validateCache(RealmModel realm, CachedClient cached) {
if (!realm.getId().equals(cached.getRealm())) {
return null;
}
StorageId storageId = new StorageId(cached.getId());
if (!storageId.isLocal()) {
ComponentModel component = realm.getComponent(storageId.getProviderId());
ClientStorageProviderModel model = new ClientStorageProviderModel(component);
// its also hard to test stuff
if (model.shouldInvalidate(cached)) {
registerClientInvalidation(cached.getId(), cached.getClientId(), realm.getId());
return getClientDelegate().getClientById(realm, cached.getId());
}
}
ClientAdapter adapter = new ClientAdapter(realm, cached, this);
return adapter;
}
use of org.keycloak.storage.client.ClientStorageProviderModel in project keycloak by keycloak.
the class ClientStorageTest method setDefaultCachePolicy.
private void setDefaultCachePolicy() {
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
ClientStorageProviderModel model = realm.getClientStorageProvidersStream().findFirst().get();
model.setCachePolicy(CacheableStorageProviderModel.CachePolicy.DEFAULT);
realm.updateComponent(model);
});
}
Aggregations