Fix - KEYCLOAK-99 UI: Users query should support wildcard
This commit is contained in:
parent
50d6d609b4
commit
5c541c5cf0
2 changed files with 35 additions and 6 deletions
|
@ -643,13 +643,13 @@ public class RealmAdapter implements RealmModel {
|
|||
for (Map.Entry<String, String> entry : attributes.entrySet()) {
|
||||
String attribute = null;
|
||||
if (entry.getKey().equals(UserModel.LOGIN_NAME)) {
|
||||
attribute = "loginName";
|
||||
attribute = "lower(loginName)";
|
||||
} else if (entry.getKey().equalsIgnoreCase(UserModel.FIRST_NAME)) {
|
||||
attribute = "firstName";
|
||||
attribute = "lower(firstName)";
|
||||
} else if (entry.getKey().equalsIgnoreCase(UserModel.LAST_NAME)) {
|
||||
attribute = "lastName";
|
||||
attribute = "lower(lastName)";
|
||||
} else if (entry.getKey().equalsIgnoreCase(UserModel.EMAIL)) {
|
||||
attribute = "email";
|
||||
attribute = "lower(email)";
|
||||
}
|
||||
if (attribute == null) continue;
|
||||
if (first) {
|
||||
|
@ -658,9 +658,11 @@ public class RealmAdapter implements RealmModel {
|
|||
} else {
|
||||
builder.append(" and ");
|
||||
}
|
||||
builder.append(attribute).append(" like lower('%").append(entry.getValue().toLowerCase()).append("%')");
|
||||
builder.append(attribute).append(" like '%").append(entry.getValue().toLowerCase()).append("%'");
|
||||
}
|
||||
TypedQuery<UserEntity> query = em.createQuery(builder.toString(), UserEntity.class);
|
||||
String q = builder.toString();
|
||||
System.out.println(q);
|
||||
TypedQuery<UserEntity> query = em.createQuery(q, UserEntity.class);
|
||||
List<UserEntity> results = query.getResultList();
|
||||
List<UserModel> users = new ArrayList<UserModel>();
|
||||
for (UserEntity entity : results) users.add(new UserAdapter(entity));
|
||||
|
|
|
@ -199,6 +199,15 @@ public class AdapterTest extends AbstractKeycloakTest {
|
|||
Assert.assertEquals(bburke.getEmail(), "bburke@redhat.com");
|
||||
}
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("bil burk", realmModel);
|
||||
Assert.assertEquals(userModels.size(), 1);
|
||||
UserModel bburke = userModels.get(0);
|
||||
Assert.assertEquals(bburke.getFirstName(), "Bill");
|
||||
Assert.assertEquals(bburke.getLastName(), "Burke");
|
||||
Assert.assertEquals(bburke.getEmail(), "bburke@redhat.com");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("bburke@redhat.com", realmModel);
|
||||
|
@ -209,6 +218,15 @@ public class AdapterTest extends AbstractKeycloakTest {
|
|||
Assert.assertEquals(bburke.getEmail(), "bburke@redhat.com");
|
||||
}
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("rke@redhat.com", realmModel);
|
||||
Assert.assertEquals(userModels.size(), 1);
|
||||
UserModel bburke = userModels.get(0);
|
||||
Assert.assertEquals(bburke.getFirstName(), "Bill");
|
||||
Assert.assertEquals(bburke.getLastName(), "Burke");
|
||||
Assert.assertEquals(bburke.getEmail(), "bburke@redhat.com");
|
||||
}
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("bburke", realmModel);
|
||||
Assert.assertEquals(userModels.size(), 1);
|
||||
|
@ -218,6 +236,15 @@ public class AdapterTest extends AbstractKeycloakTest {
|
|||
Assert.assertEquals(bburke.getEmail(), "bburke@redhat.com");
|
||||
}
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("BurK", realmModel);
|
||||
Assert.assertEquals(userModels.size(), 1);
|
||||
UserModel bburke = userModels.get(0);
|
||||
Assert.assertEquals(bburke.getFirstName(), "Bill");
|
||||
Assert.assertEquals(bburke.getLastName(), "Burke");
|
||||
Assert.assertEquals(bburke.getEmail(), "bburke@redhat.com");
|
||||
}
|
||||
|
||||
{
|
||||
List<UserModel> userModels = adapter.searchUsers("Burke", realmModel);
|
||||
Assert.assertEquals(userModels.size(), 1);
|
||||
|
|
Loading…
Reference in a new issue