diff --git a/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java b/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java index 0e24bdad7d..7c582e52a1 100644 --- a/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/role/MapRoleProvider.java @@ -70,6 +70,7 @@ public class MapRoleProvider implements RoleProvider { entity.setId(id); entity.setRealmId(realm.getId()); entity.setName(name); + entity.setClientRole(false); if (tx.read(entity.getId()) != null) { throw new ModelDuplicateException("Role exists: " + id); } @@ -200,7 +201,8 @@ public class MapRoleProvider implements RoleProvider { DefaultModelCriteria mcb = criteria(); mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId()) - .compare(SearchableFields.NAME, Operator.EQ, name); + .compare(SearchableFields.IS_CLIENT_ROLE, Operator.NE, true) + .compare(SearchableFields.NAME, Operator.EQ, name); String roleId = tx.read(withCriteria(mcb)) .map(entityToAdapterFunc(realm)) @@ -254,6 +256,7 @@ public class MapRoleProvider implements RoleProvider { } DefaultModelCriteria mcb = criteria(); mcb = mcb.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId()) + .compare(SearchableFields.IS_CLIENT_ROLE, Operator.NE, true) .or( mcb.compare(SearchableFields.NAME, Operator.ILIKE, "%" + search + "%"), mcb.compare(SearchableFields.DESCRIPTION, Operator.ILIKE, "%" + search + "%") diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/realm/RealmRolesTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/realm/RealmRolesTest.java index b7564965c5..3136a8a13e 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/realm/RealmRolesTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/realm/RealmRolesTest.java @@ -371,6 +371,12 @@ public class RealmRolesTest extends AbstractAdminTest { assertThat(expectedMembers, containsInAnyOrder("test-role-member", "test-role-member2")); } + // issue #9587 + @Test + public void testSearchForRealmRoles() { + resource.list("role-", true).stream().forEach(role -> assertThat("There is client role '" + role.getName() + "' among realm roles.", role.getClientRole(), is(false))); + } + @Test public void testSearchForRoles() {