integration.admin-client: Add exact search for all dedicated user attributes (#13361)

Closes #13360
This commit is contained in:
Markus Till 2022-08-25 08:57:31 +02:00 committed by GitHub
parent c98a760beb
commit 7f999a4629
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View file

@ -127,6 +127,22 @@ public interface UsersResource {
@Produces(MediaType.APPLICATION_JSON)
List<UserRepresentation> search(@QueryParam("username") String username, @QueryParam("exact") Boolean exact);
@GET
@Produces(MediaType.APPLICATION_JSON)
List<UserRepresentation> searchByUsername(@QueryParam("username") String username, @QueryParam("exact") Boolean exact);
@GET
@Produces(MediaType.APPLICATION_JSON)
List<UserRepresentation> searchByEmail(@QueryParam("email") String email, @QueryParam("exact") Boolean exact);
@GET
@Produces(MediaType.APPLICATION_JSON)
List<UserRepresentation> searchByFirstName(@QueryParam("firstName") String email, @QueryParam("exact") Boolean exact);
@GET
@Produces(MediaType.APPLICATION_JSON)
List<UserRepresentation> searchByLastName(@QueryParam("lastName") String email, @QueryParam("exact") Boolean exact);
/**
* Search for users whose username or email matches the value provided by {@code search}. The {@code search}
* argument also allows finding users by specific attributes as follows:

View file

@ -678,6 +678,16 @@ public class UserTest extends AbstractAdminTest {
assertEquals(9, users.size());
}
@Test
public void searchByEmailExactMatch() {
createUsers();
List<UserRepresentation> users = realm.users().searchByEmail("user1@localhost", true);
assertEquals(1, users.size());
users = realm.users().search("@localhost", true);
assertEquals(0, users.size());
}
@Test
public void searchByUsername() {
createUsers();
@ -750,10 +760,27 @@ public class UserTest extends AbstractAdminTest {
List<UserRepresentation> users = realm.users().search("username1", true);
assertEquals(1, users.size());
users = realm.users().searchByUsername("username1", true);
assertEquals(1, users.size());
users = realm.users().search("user", true);
assertEquals(0, users.size());
}
@Test
public void searchByFirstNameExact() {
createUsers();
List<UserRepresentation> users = realm.users().searchByFirstName("First1", true);
assertEquals(1, users.size());
}
@Test
public void searchByLastNameExact() {
createUsers();
List<UserRepresentation> users = realm.users().searchByLastName("Last1", true);
assertEquals(1, users.size());
}
@Test
public void searchByFirstNameNullForLastName() {
UserRepresentation user = new UserRepresentation();