Search in sources :

Example 36 with ComponentModel

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

the class UserStorageProvidersTestUtils method getStorageProvider.

public static UserStorageProvider getStorageProvider(KeycloakSession session, RealmModel realm, String componentId) {
    ComponentModel model = realm.getComponent(componentId);
    if (model == null)
        return null;
    UserStorageProviderModel storageModel = new UserStorageProviderModel(model);
    UserStorageProviderFactory factory = (UserStorageProviderFactory) session.getKeycloakSessionFactory().getProviderFactory(UserStorageProvider.class, model.getProviderId());
    if (factory == null) {
        throw new ModelException("Could not find UserStorageProviderFactory for: " + model.getProviderId());
    }
    return getStorageProviderInstance(session, storageModel, factory);
}
Also used : UserStorageProvider(org.keycloak.storage.UserStorageProvider) ModelException(org.keycloak.models.ModelException) UserStorageProviderFactory(org.keycloak.storage.UserStorageProviderFactory) ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 37 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 38 with ComponentModel

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

the class ClientPoliciesUtil method getExecutorProvider.

private static ClientPolicyExecutorProvider getExecutorProvider(KeycloakSession session, RealmModel realm, String providerId, JsonNode config) {
    ComponentModel componentModel = new JsonConfigComponentModel(ClientPolicyExecutorProvider.class, realm.getId(), providerId, config);
    ClientPolicyExecutorProvider executorProvider = session.getComponentProvider(ClientPolicyExecutorProvider.class, componentModel.getId(), sessionFactory -> componentModel);
    if (executorProvider == null) {
        // condition's provider not found. just skip it.
        throw new IllegalStateException("Executor with provider ID " + providerId + " not found");
    }
    ClientPolicyExecutorConfigurationRepresentation configuration = (ClientPolicyExecutorConfigurationRepresentation) JsonSerialization.mapper.convertValue(config, executorProvider.getExecutorConfigurationClass());
    executorProvider.setupConfiguration(configuration);
    return executorProvider;
}
Also used : ClientPolicyExecutorProvider(org.keycloak.services.clientpolicy.executor.ClientPolicyExecutorProvider) ComponentModel(org.keycloak.component.ComponentModel) JsonConfigComponentModel(org.keycloak.component.JsonConfigComponentModel) ClientPolicyExecutorConfigurationRepresentation(org.keycloak.representations.idm.ClientPolicyExecutorConfigurationRepresentation) JsonConfigComponentModel(org.keycloak.component.JsonConfigComponentModel)

Example 39 with ComponentModel

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

the class ClientPoliciesUtil method getConditionProvider.

private static ClientPolicyConditionProvider getConditionProvider(KeycloakSession session, RealmModel realm, String providerId, JsonNode config) {
    ComponentModel componentModel = new JsonConfigComponentModel(ClientPolicyConditionProvider.class, realm.getId(), providerId, config);
    ClientPolicyConditionProvider conditionProvider = session.getComponentProvider(ClientPolicyConditionProvider.class, componentModel.getId(), sessionFactory -> componentModel);
    if (conditionProvider == null) {
        // condition's provider not found. just skip it.
        throw new IllegalStateException("Condition with provider ID " + providerId + " not found");
    }
    ClientPolicyConditionConfigurationRepresentation configuration = (ClientPolicyConditionConfigurationRepresentation) JsonSerialization.mapper.convertValue(config, conditionProvider.getConditionConfigurationClass());
    conditionProvider.setupConfiguration(configuration);
    return conditionProvider;
}
Also used : ClientPolicyConditionProvider(org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider) ClientPolicyConditionConfigurationRepresentation(org.keycloak.representations.idm.ClientPolicyConditionConfigurationRepresentation) ComponentModel(org.keycloak.component.ComponentModel) JsonConfigComponentModel(org.keycloak.component.JsonConfigComponentModel) JsonConfigComponentModel(org.keycloak.component.JsonConfigComponentModel)

Example 40 with ComponentModel

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

the class ClientStorageProviderResource method getSimpleName.

/**
 * Need this for admin console to display simple name of provider when displaying client detail
 *
 * KEYCLOAK-4328
 *
 * @param id
 * @return
 */
@GET
@Path("{id}/name")
@NoCache
@Produces(MediaType.APPLICATION_JSON)
public Map<String, String> getSimpleName(@PathParam("id") String id) {
    auth.clients().requireList();
    ComponentModel model = realm.getComponent(id);
    if (model == null) {
        throw new NotFoundException("Could not find component");
    }
    if (!model.getProviderType().equals(ClientStorageProvider.class.getName())) {
        throw new NotFoundException("found, but not a ClientStorageProvider");
    }
    Map<String, String> data = new HashMap<>();
    data.put("id", model.getId());
    data.put("name", model.getName());
    return data;
}
Also used : HashMap(java.util.HashMap) ComponentModel(org.keycloak.component.ComponentModel) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

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