mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
Fix NPE in LDAPUtils.loadAllLDAPObjects when batch size is set to value <= 0
Signed-off-by: Stefan Guilhen <sguilhen@redhat.com> Closes #39022
This commit is contained in:
parent
636fffe0bc
commit
9976f9380c
@ -310,8 +310,8 @@ public class LDAPUtils {
|
||||
* @return
|
||||
*/
|
||||
public static List<LDAPObject> loadAllLDAPObjects(LDAPQuery ldapQuery, LDAPConfig ldapConfig) {
|
||||
boolean pagination = ldapConfig.isPagination();
|
||||
if (pagination) {
|
||||
|
||||
if (ldapConfig.isPagination() && ldapConfig.getBatchSizeForSync() > 0) {
|
||||
// For now reuse globally configured batch size in LDAP provider page
|
||||
int pageSize = ldapConfig.getBatchSizeForSync();
|
||||
|
||||
|
||||
@ -952,5 +952,39 @@ public class LDAPGroupMapperTest extends AbstractLDAPTest {
|
||||
Assert.assertEquals("localuser", localGroupMembers.get(0));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11_fetchUsersGroupsWithPaginationAndInvalidBatchSize() {
|
||||
testingClient.server().run(session -> {
|
||||
LDAPTestContext ctx = LDAPTestContext.init(session);
|
||||
RealmModel appRealm = ctx.getRealm();
|
||||
|
||||
// batch size 0 effectively disables pagination, code must fall back to non-paginated search
|
||||
ComponentModel mapperModel = LDAPTestUtils.getLdapProviderModel(appRealm);
|
||||
LDAPTestUtils.updateConfigOptions(mapperModel, LDAPConstants.BATCH_SIZE_FOR_SYNC, "0");
|
||||
appRealm.updateComponent(mapperModel);
|
||||
});
|
||||
|
||||
testingClient.server().run(session -> {
|
||||
LDAPTestContext ctx = LDAPTestContext.init(session);
|
||||
RealmModel appRealm = ctx.getRealm();
|
||||
|
||||
// verify that getting the user's groups still works
|
||||
UserModel john = session.users().getUserByUsername(appRealm, "johnkeycloak");
|
||||
Set<GroupModel> johnGroups = john.getGroupsStream().collect(Collectors.toSet());
|
||||
Assert.assertEquals(4, johnGroups.size());
|
||||
});
|
||||
|
||||
String configuredBatchSize = ldapRule.getConfig().get(LDAPConstants.BATCH_SIZE_FOR_SYNC);
|
||||
testingClient.server().run(session -> {
|
||||
LDAPTestContext ctx = LDAPTestContext.init(session);
|
||||
RealmModel appRealm = ctx.getRealm();
|
||||
|
||||
// revert batch size change
|
||||
ComponentModel mapperModel = LDAPTestUtils.getLdapProviderModel(appRealm);
|
||||
LDAPTestUtils.updateConfigOptions(mapperModel, LDAPConstants.BATCH_SIZE_FOR_SYNC, configuredBatchSize);
|
||||
appRealm.updateComponent(mapperModel);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user