protected UserModel importUserFromLDAP( KeycloakSession session, RealmModel realm, LDAPObject ldapUser) { String ldapUsername = LDAPUtils.getUsername(ldapUser, ldapIdentityStore.getConfig()); LDAPUtils.checkUuid(ldapUser, ldapIdentityStore.getConfig()); UserModel imported = session.userStorage().addUser(realm, ldapUsername); imported.setEnabled(true); Set<UserFederationMapperModel> federationMappers = realm.getUserFederationMappersByFederationProvider(getModel().getId()); for (UserFederationMapperModel mapperModel : federationMappers) { if (logger.isTraceEnabled()) { logger.tracef("Using mapper %s during import user from LDAP", mapperModel); } LDAPFederationMapper ldapMapper = getMapper(mapperModel); ldapMapper.onImportUserFromLDAP(mapperModel, this, ldapUser, imported, realm, true); } String userDN = ldapUser.getDn().toString(); imported.setFederationLink(model.getId()); imported.setSingleAttribute(LDAPConstants.LDAP_ID, ldapUser.getUuid()); imported.setSingleAttribute(LDAPConstants.LDAP_ENTRY_DN, userDN); logger.debugf( "Imported new user from LDAP to Keycloak DB. Username: [%s], Email: [%s], LDAP_ID: [%s], LDAP Entry DN: [%s]", imported.getUsername(), imported.getEmail(), ldapUser.getUuid(), userDN); return proxy(realm, imported, ldapUser); }
protected UserModel proxy(RealmModel realm, UserModel local, LDAPObject ldapObject) { UserModel proxied = local; switch (editMode) { case READ_ONLY: proxied = new ReadonlyLDAPUserModelDelegate(local, this); break; case WRITABLE: proxied = new WritableLDAPUserModelDelegate(local, this, ldapObject); break; case UNSYNCED: proxied = new UnsyncedLDAPUserModelDelegate(local, this); } Set<UserFederationMapperModel> federationMappers = realm.getUserFederationMappersByFederationProvider(model.getId()); for (UserFederationMapperModel mapperModel : federationMappers) { LDAPFederationMapper ldapMapper = getMapper(mapperModel); proxied = ldapMapper.proxy(mapperModel, this, ldapObject, proxied, realm); } return proxied; }