Search in sources :

Example 6 with ClientStorageProviderModel

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();
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 7 with ClientStorageProviderModel

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();
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 8 with ClientStorageProviderModel

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();
}
Also used : RealmModel(org.keycloak.models.RealmModel) Calendar(java.util.Calendar) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 9 with ClientStorageProviderModel

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;
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel) StorageId(org.keycloak.storage.StorageId)

Example 10 with ClientStorageProviderModel

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);
    });
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel)

Aggregations

ClientStorageProviderModel (org.keycloak.storage.client.ClientStorageProviderModel)12 RealmModel (org.keycloak.models.RealmModel)7 Test (org.junit.Test)4 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)4 ComponentModel (org.keycloak.component.ComponentModel)3 ModelException (org.keycloak.models.ModelException)3 Calendar (java.util.Calendar)2 ClientModel (org.keycloak.models.ClientModel)2 ClientScopeModel (org.keycloak.models.ClientScopeModel)2 KeycloakSession (org.keycloak.models.KeycloakSession)2 UserConsentModel (org.keycloak.models.UserConsentModel)2 UserModel (org.keycloak.models.UserModel)2 RealmManager (org.keycloak.services.managers.RealmManager)2 StorageId (org.keycloak.storage.StorageId)2 IClient (com.openshift.restclient.IClient)1 UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)1 ClientStorageProvider (org.keycloak.storage.client.ClientStorageProvider)1 ClientStorageProviderFactory (org.keycloak.storage.client.ClientStorageProviderFactory)1