Merge pull request #3530 from mposolda/master

KEYCLOAK-3944 Imported legacy LDAP Federation provider doesn't have d…
This commit is contained in:
Marek Posolda 2016-11-21 18:25:44 +01:00 committed by GitHub
commit 68701900d8
3 changed files with 15 additions and 4 deletions

View file

@ -301,7 +301,7 @@ public class RepresentationToModel {
String parentId = newRealm.getId();
importComponents(newRealm, components, parentId);
}
importUserFederationProvidersAndMappers(rep, newRealm);
importUserFederationProvidersAndMappers(session, rep, newRealm);
if (rep.getGroups() != null) {
@ -358,7 +358,7 @@ public class RepresentationToModel {
}
}
public static void importUserFederationProvidersAndMappers(RealmRepresentation rep, RealmModel newRealm) {
public static void importUserFederationProvidersAndMappers(KeycloakSession session, RealmRepresentation rep, RealmModel newRealm) {
// providers to convert to component model
Set<String> convertSet = new HashSet<>();
convertSet.add(LDAPConstants.LDAP_PROVIDER);
@ -382,6 +382,10 @@ public class RepresentationToModel {
}
newRealm.setUserFederationProviders(providerModels);
}
// This is for case, when you have hand-written JSON file with LDAP userFederationProvider, but WITHOUT any userFederationMappers configured. Default LDAP mappers need to be created in that case.
Set<String> storageProvidersWhichShouldImportDefaultMappers = new HashSet<>(userStorageModels.keySet());
if (rep.getUserFederationMappers() != null) {
// Remove builtin mappers for federation providers, which have some mappers already provided in JSON (likely due to previous export)
@ -409,11 +413,18 @@ public class RepresentationToModel {
ComponentModel mapper = convertFedMapperToComponent(newRealm, parent, representation, newMapperType);
newRealm.importComponentModel(mapper);
storageProvidersWhichShouldImportDefaultMappers.remove(representation.getFederationProviderDisplayName());
} else {
newRealm.addUserFederationMapper(toModel(newRealm, representation));
}
}
}
for (String providerDisplayName : storageProvidersWhichShouldImportDefaultMappers) {
ComponentUtil.notifyCreated(session, newRealm, userStorageModels.get(providerDisplayName));
}
}
protected static void importComponents(RealmModel newRealm, MultivaluedHashMap<String, ComponentExportRepresentation> components, String parentId) {

View file

@ -97,7 +97,7 @@ public class LDAPLegacyImportTest {
} catch (IOException e) {
throw new RuntimeException(e);
}
RepresentationToModel.importUserFederationProvidersAndMappers(imported, appRealm);
RepresentationToModel.importUserFederationProvidersAndMappers(session, imported, appRealm);
ldapModel = appRealm.getComponents(appRealm.getId(), UserStorageProvider.class.getName()).get(0);
// Delete all LDAP users and add some new for testing
LDAPStorageProvider ldapFedProvider = LDAPTestUtils.getLdapProvider(session, ldapModel);

View file

@ -1788,7 +1788,7 @@ module.controller('LDAPUserStorageCtrl', function($scope, $location, Notificatio
$scope.save = function() {
$scope.changed = false;
if (!parseInt($scope.instance.config['batchSizeForSync'][0])) {
if (!$scope.instance.config['batchSizeForSync'] || !parseInt($scope.instance.config['batchSizeForSync'][0])) {
$scope.instance.config['batchSizeForSync'] = [ DEFAULT_BATCH_SIZE ];
} else {
$scope.instance.config['batchSizeForSync'][0] = parseInt($scope.instance.config.batchSizeForSync).toString();