forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getAll() organization and organization members only returns the first…
… 10 items Closes keycloak#34975 Signed-off-by: Martin Kanis <[email protected]> (cherry picked from commit 7e3e46d)
- Loading branch information
1 parent
69001b3
commit ea13176
Showing
13 changed files
with
98 additions
and
36 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
docs/documentation/upgrading/topics/changes/changes-26_0_7.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= Deprecating `getAll()` methods in `Organizations` and `OrganizationMembers` APIs | ||
|
||
`getAll()` methods in `Organizations` and `OrganizationMembers` APIs are now deprecated and will be removed in the next major release. | ||
Instead, use corresponding `list(first, max)` methods in `Organizations` and `OrganizationMembers` APIs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package org.keycloak.testsuite.organization.member; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
@@ -33,13 +34,15 @@ | |
import static org.keycloak.testsuite.broker.BrokerTestTools.waitForPage; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import jakarta.ws.rs.BadRequestException; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.Response.Status; | ||
import java.io.IOException; | ||
import java.util.stream.Stream; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
@@ -51,6 +54,7 @@ | |
import org.keycloak.models.UserModel; | ||
import org.keycloak.models.utils.KeycloakModelUtils; | ||
import org.keycloak.organization.OrganizationProvider; | ||
import org.keycloak.representations.idm.AbstractUserRepresentation; | ||
import org.keycloak.representations.idm.IdentityProviderRepresentation; | ||
import org.keycloak.representations.idm.MemberRepresentation; | ||
import org.keycloak.representations.idm.OrganizationRepresentation; | ||
|
@@ -133,11 +137,11 @@ public void testGetAll() { | |
OrganizationResource organization = testRealm().organizations().get(createOrganization().getId()); | ||
List<UserRepresentation> expected = new ArrayList<>(); | ||
|
||
for (int i = 0; i < 5; i++) { | ||
for (int i = 0; i < 15; i++) { | ||
expected.add(addMember(organization, "member-" + i + "@neworg.org")); | ||
} | ||
|
||
List<MemberRepresentation> existing = organization.members().getAll(); | ||
List<MemberRepresentation> existing = organization.members().list(-1, -1); | ||
assertFalse(existing.isEmpty()); | ||
assertEquals(expected.size(), existing.size()); | ||
for (UserRepresentation expectedRep : expected) { | ||
|
@@ -150,6 +154,14 @@ public void testGetAll() { | |
assertEquals(expectedRep.getLastName(), existingRep.getLastName()); | ||
assertTrue(expectedRep.isEnabled()); | ||
} | ||
|
||
List<String> concatenatedList = Stream.of( | ||
organization.members().list(0, 5).stream().map(AbstractUserRepresentation::getId).toList(), | ||
organization.members().list(5, 5).stream().map(AbstractUserRepresentation::getId).toList(), | ||
organization.members().list(10, 5).stream().map(AbstractUserRepresentation::getId).toList()) | ||
.flatMap(Collection::stream).toList(); | ||
|
||
assertThat(concatenatedList, containsInAnyOrder(expected.stream().map(AbstractUserRepresentation::getId).toArray())); | ||
} | ||
|
||
@Test | ||
|
@@ -176,7 +188,7 @@ public void testGetAllDisabledOrganization() { | |
assertThat(existingOrg.isEnabled(), is(false)); | ||
|
||
// now fetch all users from the org - unmanaged users should still be enabled, but managed ones should not. | ||
List<MemberRepresentation> existing = organization.members().getAll(); | ||
List<MemberRepresentation> existing = organization.members().list(-1, -1); | ||
assertThat(existing, not(empty())); | ||
assertThat(existing, hasSize(6)); | ||
for (UserRepresentation user : existing) { | ||
|
@@ -461,7 +473,7 @@ public void testUserFederatedBeforeTheIDPBoundWithAnOrgIsNotMember() { | |
} | ||
|
||
//check the federated user is not a member | ||
assertThat(testRealm().organizations().get(id).members().getAll(), hasSize(0)); | ||
assertThat(testRealm().organizations().get(id).members().list(-1, -1), hasSize(0)); | ||
} | ||
|
||
@Test | ||
|
@@ -475,8 +487,8 @@ public void testMemberInMultipleOrganizations() { | |
|
||
orgb.members().addMember(member.getId()).close(); | ||
|
||
Assert.assertTrue(orga.members().getAll().stream().map(UserRepresentation::getId).anyMatch(member.getId()::equals)); | ||
Assert.assertTrue(orgb.members().getAll().stream().map(UserRepresentation::getId).anyMatch(member.getId()::equals)); | ||
Assert.assertTrue(orga.members().list(-1, -1).stream().map(UserRepresentation::getId).anyMatch(member.getId()::equals)); | ||
Assert.assertTrue(orgb.members().list(-1, -1).stream().map(UserRepresentation::getId).anyMatch(member.getId()::equals)); | ||
String orgbId = orgb.toRepresentation().getId(); | ||
String orgaId = orga.toRepresentation().getId(); | ||
List<String> memberOfOrgs = orga.members().member(member.getId()).getOrganizations().stream().map(OrganizationRepresentation::getId).toList(); | ||
|
@@ -488,7 +500,7 @@ public void testMemberInMultipleOrganizations() { | |
public void testManagedMemberOnlyRemovedFromHomeOrganization() { | ||
OrganizationResource orga = testRealm().organizations().get(createOrganization("org-a").getId()); | ||
assertBrokerRegistration(orga, bc.getUserEmail(), "[email protected]"); | ||
UserRepresentation memberOrgA = orga.members().getAll().get(0); | ||
UserRepresentation memberOrgA = orga.members().list(-1, -1).get(0); | ||
realmsResouce().realm(bc.consumerRealmName()).users().get(memberOrgA.getId()).logout(); | ||
realmsResouce().realm(bc.providerRealmName()).logoutAll(); | ||
|
||
|
@@ -500,21 +512,21 @@ public void testManagedMemberOnlyRemovedFromHomeOrganization() { | |
.build(); | ||
realmsResouce().realm(bc.providerRealmName()).users().create(memberOrgB).close(); | ||
assertBrokerRegistration(orgb, memberOrgB.getUsername(), "[email protected]"); | ||
memberOrgB = orgb.members().getAll().get(0); | ||
memberOrgB = orgb.members().list(-1, -1).get(0); | ||
|
||
orga.members().addMember(memberOrgB.getId()).close(); | ||
assertThat(orga.members().getAll().size(), is(2)); | ||
assertThat(orga.members().list(-1, -1).size(), is(2)); | ||
OrganizationMemberResource memberOrgBInOrgA = orga.members().member(memberOrgB.getId()); | ||
memberOrgB = memberOrgBInOrgA.toRepresentation(); | ||
memberOrgBInOrgA.delete().close(); | ||
assertThat(orga.members().getAll().size(), is(1)); | ||
assertThat(orga.members().getAll().get(0).getId(), is(memberOrgA.getId())); | ||
assertThat(orgb.members().getAll().size(), is(1)); | ||
assertThat(orga.members().list(-1, -1).size(), is(1)); | ||
assertThat(orga.members().list(-1, -1).get(0).getId(), is(memberOrgA.getId())); | ||
assertThat(orgb.members().list(-1, -1).size(), is(1)); | ||
|
||
orgb.members().member(memberOrgB.getId()).delete().close(); | ||
assertThat(orga.members().getAll().size(), is(1)); | ||
assertThat(orga.members().getAll().get(0).getId(), is(memberOrgA.getId())); | ||
assertThat(orgb.members().getAll().size(), is(0)); | ||
assertThat(orga.members().list(-1, -1).size(), is(1)); | ||
assertThat(orga.members().list(-1, -1).get(0).getId(), is(memberOrgA.getId())); | ||
assertThat(orgb.members().list(-1, -1).size(), is(0)); | ||
} | ||
|
||
@Test | ||
|