diff --git a/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/UsersResource.java b/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/UsersResource.java index 06e00542f8..adff9c7bef 100755 --- a/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/UsersResource.java +++ b/integration/admin-client/src/main/java/org/keycloak/admin/client/resource/UsersResource.java @@ -127,6 +127,22 @@ public interface UsersResource { @Produces(MediaType.APPLICATION_JSON) List search(@QueryParam("username") String username, @QueryParam("exact") Boolean exact); + @GET + @Produces(MediaType.APPLICATION_JSON) + List searchByUsername(@QueryParam("username") String username, @QueryParam("exact") Boolean exact); + + @GET + @Produces(MediaType.APPLICATION_JSON) + List searchByEmail(@QueryParam("email") String email, @QueryParam("exact") Boolean exact); + + @GET + @Produces(MediaType.APPLICATION_JSON) + List searchByFirstName(@QueryParam("firstName") String email, @QueryParam("exact") Boolean exact); + + @GET + @Produces(MediaType.APPLICATION_JSON) + List 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: diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java index 08b0b26265..51d0fed322 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java @@ -678,6 +678,16 @@ public class UserTest extends AbstractAdminTest { assertEquals(9, users.size()); } + @Test + public void searchByEmailExactMatch() { + createUsers(); + List 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 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 users = realm.users().searchByFirstName("First1", true); + assertEquals(1, users.size()); + } + + @Test + public void searchByLastNameExact() { + createUsers(); + List users = realm.users().searchByLastName("Last1", true); + assertEquals(1, users.size()); + } + @Test public void searchByFirstNameNullForLastName() { UserRepresentation user = new UserRepresentation();