Search in sources :

Example 81 with ComponentModel

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

the class LDAPUtils method createQueryForUserSearch.

public static LDAPQuery createQueryForUserSearch(LDAPStorageProvider ldapProvider, RealmModel realm) {
    LDAPQuery ldapQuery = new LDAPQuery(ldapProvider);
    LDAPConfig config = ldapProvider.getLdapIdentityStore().getConfig();
    ldapQuery.setSearchScope(config.getSearchScope());
    ldapQuery.setSearchDn(config.getUsersDn());
    ldapQuery.addObjectClasses(config.getUserObjectClasses());
    String customFilter = config.getCustomUserSearchFilter();
    if (customFilter != null) {
        Condition customFilterCondition = new LDAPQueryConditionsBuilder().addCustomLDAPFilter(customFilter);
        ldapQuery.addWhereCondition(customFilterCondition);
    }
    List<ComponentModel> mapperModels = realm.getComponentsStream(ldapProvider.getModel().getId(), LDAPStorageMapper.class.getName()).collect(Collectors.toList());
    ldapQuery.addMappers(mapperModels);
    return ldapQuery;
}
Also used : Condition(org.keycloak.storage.ldap.idm.query.Condition) LDAPQuery(org.keycloak.storage.ldap.idm.query.internal.LDAPQuery) ComponentModel(org.keycloak.component.ComponentModel) LDAPQueryConditionsBuilder(org.keycloak.storage.ldap.idm.query.internal.LDAPQueryConditionsBuilder)

Example 82 with ComponentModel

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

the class GroupLDAPStorageMapperFactory method onCreate.

@Override
public void onCreate(KeycloakSession session, RealmModel realm, ComponentModel model) {
    ComponentModel parentModel = realm.getComponent(model.getParentId());
    UserStorageProviderModel parent = new UserStorageProviderModel(parentModel);
    onParentUpdate(realm, parent, parent, model);
    setDefaultGroupsPath(realm, model);
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 83 with ComponentModel

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

the class RoleLDAPStorageMapperFactory method onUpdate.

@Override
public void onUpdate(KeycloakSession session, RealmModel realm, ComponentModel oldModel, ComponentModel newModel) {
    ComponentModel parentModel = realm.getComponent(newModel.getParentId());
    UserStorageProviderModel parent = new UserStorageProviderModel(parentModel);
    onParentUpdate(realm, parent, parent, newModel);
}
Also used : ComponentModel(org.keycloak.component.ComponentModel) UserStorageProviderModel(org.keycloak.storage.UserStorageProviderModel)

Example 84 with ComponentModel

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

the class FullNameLDAPStorageMapperFactory method validateConfiguration.

@Override
public void validateConfiguration(KeycloakSession session, RealmModel realm, ComponentModel config) throws ComponentValidationException {
    checkMandatoryConfigAttribute(FullNameLDAPStorageMapper.LDAP_FULL_NAME_ATTRIBUTE, "LDAP Full Name Attribute", config);
    boolean readOnly = AbstractLDAPStorageMapper.parseBooleanParameter(config, FullNameLDAPStorageMapper.READ_ONLY);
    boolean writeOnly = AbstractLDAPStorageMapper.parseBooleanParameter(config, FullNameLDAPStorageMapper.WRITE_ONLY);
    ComponentModel parent = realm.getComponent(config.getParentId());
    if (parent == null) {
        throw new ComponentValidationException("can't find parent component model");
    }
    LDAPConfig cfg = new LDAPConfig(parent.getConfig());
    UserStorageProvider.EditMode editMode = cfg.getEditMode();
    if (writeOnly && cfg.getEditMode() != UserStorageProvider.EditMode.WRITABLE) {
        throw new ComponentValidationException("ldapErrorCantWriteOnlyForReadOnlyLdap");
    }
    if (writeOnly && readOnly) {
        throw new ComponentValidationException("ldapErrorCantWriteOnlyAndReadOnly");
    }
}
Also used : ComponentValidationException(org.keycloak.component.ComponentValidationException) UserStorageProvider(org.keycloak.storage.UserStorageProvider) LDAPConfig(org.keycloak.storage.ldap.LDAPConfig) ComponentModel(org.keycloak.component.ComponentModel)

Example 85 with ComponentModel

use of org.keycloak.component.ComponentModel 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)

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