Search in sources :

Example 1 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class UserCacheSession method cacheUser.

protected UserModel cacheUser(RealmModel realm, UserModel delegate, Long revision) {
    int notBefore = getDelegate().getNotBeforeOfUser(realm, delegate);
    StorageId storageId = delegate.getFederationLink() != null ? new StorageId(delegate.getFederationLink(), delegate.getId()) : new StorageId(delegate.getId());
    CachedUser cached = null;
    UserAdapter adapter = null;
    if (!storageId.isLocal()) {
        ComponentModel component = realm.getComponent(storageId.getProviderId());
        UserStorageProviderModel model = new UserStorageProviderModel(component);
        if (!model.isEnabled()) {
            return new ReadOnlyUserModelDelegate(delegate) {

                @Override
                public boolean isEnabled() {
                    return false;
                }
            };
        }
        UserStorageProviderModel.CachePolicy policy = model.getCachePolicy();
        if (policy != null && policy == UserStorageProviderModel.CachePolicy.NO_CACHE) {
            return delegate;
        }
        cached = new CachedUser(revision, realm, delegate, notBefore);
        adapter = new UserAdapter(cached, this, session, realm);
        onCache(realm, adapter, delegate);
        long lifespan = model.getLifespan();
        if (lifespan > 0) {
            cache.addRevisioned(cached, startupRevision, lifespan);
        } else {
            cache.addRevisioned(cached, startupRevision);
        }
    } else {
        cached = new CachedUser(revision, realm, delegate, notBefore);
        adapter = new UserAdapter(cached, this, session, realm);
        onCache(realm, adapter, delegate);
        cache.addRevisioned(cached, startupRevision);
    }
    return adapter;
}
Also used : ReadOnlyUserModelDelegate(org.keycloak.models.utils.ReadOnlyUserModelDelegate) ComponentModel(org.keycloak.component.ComponentModel) CachedUser(org.keycloak.models.cache.infinispan.entities.CachedUser) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel) StorageId(org.keycloak.storage.StorageId)

Example 2 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class UserCacheSession method validateCache.

protected UserModel validateCache(RealmModel realm, CachedUser cached) {
    if (!realm.getId().equals(cached.getRealm())) {
        return null;
    }
    StorageId storageId = cached.getFederationLink() != null ? new StorageId(cached.getFederationLink(), cached.getId()) : new StorageId(cached.getId());
    if (!storageId.isLocal()) {
        ComponentModel component = realm.getComponent(storageId.getProviderId());
        CacheableStorageProviderModel model = new CacheableStorageProviderModel(component);
        // its also hard to test stuff
        if (model.shouldInvalidate(cached)) {
            registerUserInvalidation(realm, cached);
            return getDelegate().getUserById(realm, cached.getId());
        }
    }
    return new UserAdapter(cached, this, session, realm);
}
Also used : CacheableStorageProviderModel(org.keycloak.storage.CacheableStorageProviderModel) ComponentModel(org.keycloak.component.ComponentModel) StorageId(org.keycloak.storage.StorageId)

Example 3 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class RealmCacheSession method cacheClient.

protected ClientModel cacheClient(RealmModel realm, ClientModel delegate, Long revision) {
    if (invalidations.contains(delegate.getId()))
        return delegate;
    StorageId storageId = new StorageId(delegate.getId());
    CachedClient cached = null;
    ClientAdapter adapter = null;
    if (!storageId.isLocal()) {
        ComponentModel component = realm.getComponent(storageId.getProviderId());
        ClientStorageProviderModel model = new ClientStorageProviderModel(component);
        if (!model.isEnabled()) {
            return delegate;
        }
        ClientStorageProviderModel.CachePolicy policy = model.getCachePolicy();
        if (policy != null && policy == ClientStorageProviderModel.CachePolicy.NO_CACHE) {
            return delegate;
        }
        cached = new CachedClient(revision, realm, delegate);
        adapter = new ClientAdapter(realm, cached, this);
        long lifespan = model.getLifespan();
        if (lifespan > 0) {
            cache.addRevisioned(cached, startupRevision, lifespan);
        } else {
            cache.addRevisioned(cached, startupRevision);
        }
    } else {
        cached = new CachedClient(revision, realm, delegate);
        adapter = new ClientAdapter(realm, cached, this);
        cache.addRevisioned(cached, startupRevision);
    }
    return adapter;
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) ClientStorageProviderModel(org.keycloak.storage.client.ClientStorageProviderModel) StorageId(org.keycloak.storage.StorageId)

Example 4 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class MapComponentEntity method toModel.

static ComponentModel toModel(MapComponentEntity entity) {
    ComponentModel model = new ComponentModel();
    model.setId(entity.getId());
    model.setName(entity.getName());
    model.setProviderId(entity.getProviderId());
    model.setProviderType(entity.getProviderType());
    model.setSubType(entity.getSubType());
    model.setParentId(entity.getParentId());
    Map<String, List<String>> config = entity.getConfig();
    model.setConfig(config == null ? null : new MultivaluedHashMap<>(config));
    return model;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentModel(org.keycloak.component.ComponentModel) List(java.util.List)

Example 5 with ComponentModel

use of org.keycloak.component.ComponentModel in project keycloak by keycloak.

the class RepresentationToModel method convertFedMapperToComponent.

public static ComponentModel convertFedMapperToComponent(RealmModel realm, ComponentModel parent, UserFederationMapperRepresentation rep, String newMapperType) {
    ComponentModel mapper = new ComponentModel();
    mapper.setId(rep.getId());
    mapper.setName(rep.getName());
    mapper.setProviderId(rep.getFederationMapperType());
    mapper.setProviderType(newMapperType);
    mapper.setParentId(parent.getId());
    if (rep.getConfig() != null) {
        for (Map.Entry<String, String> entry : rep.getConfig().entrySet()) {
            mapper.getConfig().putSingle(entry.getKey(), entry.getValue());
        }
    }
    return mapper;
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) ArtifactBindingUtils.computeArtifactBindingIdentifierString(org.keycloak.protocol.saml.util.ArtifactBindingUtils.computeArtifactBindingIdentifierString) Map(java.util.Map) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) HashMap(java.util.HashMap)

Aggregations

ComponentModel (org.keycloak.component.ComponentModel)155 RealmModel (org.keycloak.models.RealmModel)74 Test (org.junit.Test)52 LDAPStorageProvider (org.keycloak.storage.ldap.LDAPStorageProvider)46 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)34 UserModel (org.keycloak.models.UserModel)29 HashMap (java.util.HashMap)22 UserStorageProviderModel (org.keycloak.storage.UserStorageProviderModel)22 GroupModel (org.keycloak.models.GroupModel)21 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)18 SynchronizationResult (org.keycloak.storage.user.SynchronizationResult)18 ComponentValidationException (org.keycloak.component.ComponentValidationException)16 UserStorageProvider (org.keycloak.storage.UserStorageProvider)16 LDAPStorageMapper (org.keycloak.storage.ldap.mappers.LDAPStorageMapper)15 GroupLDAPStorageMapper (org.keycloak.storage.ldap.mappers.membership.group.GroupLDAPStorageMapper)15 Path (javax.ws.rs.Path)14 DeclarativeUserProfileProvider (org.keycloak.userprofile.DeclarativeUserProfileProvider)13 ModelException (org.keycloak.models.ModelException)11 UPAttribute (org.keycloak.userprofile.config.UPAttribute)11 UPConfig (org.keycloak.userprofile.config.UPConfig)11