Search in sources :

Example 1 with LDAPIdentityStore

use of org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore in project keycloak by keycloak.

the class LDAPIdentityStoreRegistry method getLdapStore.

public LDAPIdentityStore getLdapStore(KeycloakSession session, ComponentModel ldapModel, Map<ComponentModel, LDAPConfigDecorator> configDecorators) {
    LDAPIdentityStoreContext context = ldapStores.get(ldapModel.getId());
    // Ldap config might have changed for the realm. In this case, we must re-initialize
    MultivaluedHashMap<String, String> configModel = ldapModel.getConfig();
    LDAPConfig ldapConfig = new LDAPConfig(configModel);
    for (Map.Entry<ComponentModel, LDAPConfigDecorator> entry : configDecorators.entrySet()) {
        ComponentModel mapperModel = entry.getKey();
        LDAPConfigDecorator decorator = entry.getValue();
        decorator.updateLDAPConfig(ldapConfig, mapperModel);
    }
    if (context == null || !ldapConfig.equals(context.config)) {
        logLDAPConfig(session, ldapModel, ldapConfig);
        LDAPIdentityStore store = createLdapIdentityStore(session, ldapConfig);
        context = new LDAPIdentityStoreContext(ldapConfig, store);
        ldapStores.put(ldapModel.getId(), context);
    }
    return context.store;
}
Also used : LDAPIdentityStore(org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore) ComponentModel(org.keycloak.component.ComponentModel) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) LDAPConfigDecorator(org.keycloak.storage.ldap.mappers.LDAPConfigDecorator)

Example 2 with LDAPIdentityStore

use of org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore in project keycloak by keycloak.

the class LDAPStorageProviderFactory method create.

@Override
public LDAPStorageProvider create(KeycloakSession session, ComponentModel model) {
    Map<ComponentModel, LDAPConfigDecorator> configDecorators = getLDAPConfigDecorators(session, model);
    LDAPIdentityStore ldapIdentityStore = this.ldapStoreRegistry.getLdapStore(session, model, configDecorators);
    return new LDAPStorageProvider(this, session, model, ldapIdentityStore);
}
Also used : LDAPIdentityStore(org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore) ComponentModel(org.keycloak.component.ComponentModel) LDAPConfigDecorator(org.keycloak.storage.ldap.mappers.LDAPConfigDecorator)

Example 3 with LDAPIdentityStore

use of org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore in project keycloak by keycloak.

the class LDAPUtils method addUserToLDAP.

/**
 * @param ldapProvider
 * @param realm
 * @param user
 * @return newly created LDAPObject with all the attributes, uuid and DN properly set
 */
public static LDAPObject addUserToLDAP(LDAPStorageProvider ldapProvider, RealmModel realm, UserModel user) {
    LDAPObject ldapUser = new LDAPObject();
    LDAPIdentityStore ldapStore = ldapProvider.getLdapIdentityStore();
    LDAPConfig ldapConfig = ldapStore.getConfig();
    ldapUser.setRdnAttributeName(ldapConfig.getRdnLdapAttribute());
    ldapUser.setObjectClasses(ldapConfig.getUserObjectClasses());
    LDAPMappersComparator ldapMappersComparator = new LDAPMappersComparator(ldapConfig);
    realm.getComponentsStream(ldapProvider.getModel().getId(), LDAPStorageMapper.class.getName()).sorted(ldapMappersComparator.sortAsc()).forEachOrdered(mapperModel -> {
        LDAPStorageMapper ldapMapper = ldapProvider.getMapperManager().getMapper(mapperModel);
        ldapMapper.onRegisterUserToLDAP(ldapUser, user, realm);
    });
    LDAPUtils.computeAndSetDn(ldapConfig, ldapUser);
    ldapStore.add(ldapUser);
    return ldapUser;
}
Also used : LDAPIdentityStore(org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore) LDAPStorageMapper(org.keycloak.storage.ldap.mappers.LDAPStorageMapper) LDAPMappersComparator(org.keycloak.storage.ldap.mappers.LDAPMappersComparator) LDAPObject(org.keycloak.storage.ldap.idm.model.LDAPObject)

Aggregations

LDAPIdentityStore (org.keycloak.storage.ldap.idm.store.ldap.LDAPIdentityStore)3 ComponentModel (org.keycloak.component.ComponentModel)2 LDAPConfigDecorator (org.keycloak.storage.ldap.mappers.LDAPConfigDecorator)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)1 LDAPObject (org.keycloak.storage.ldap.idm.model.LDAPObject)1 LDAPMappersComparator (org.keycloak.storage.ldap.mappers.LDAPMappersComparator)1 LDAPStorageMapper (org.keycloak.storage.ldap.mappers.LDAPStorageMapper)1