From b7c98ed4332404fa00d2b995a7fcb7fa806c952f Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Tue, 3 Jan 2017 08:42:46 +0100 Subject: [PATCH] KEYCLOAK-2980 Fix admin query for resource path --- .../org/keycloak/events/jpa/JpaAdminEventQuery.java | 2 +- .../org/keycloak/events/admin/AdminEventQuery.java | 6 +++--- .../testsuite/admin/event/AdminEventTest.java | 4 ++-- .../events/AdminEventStoreProviderTest.java | 13 +++++++------ .../admin/messages/admin-messages_en.properties | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java b/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java index 9c3e534230..15c58c225c 100755 --- a/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java +++ b/model/jpa/src/main/java/org/keycloak/events/jpa/JpaAdminEventQuery.java @@ -111,7 +111,7 @@ public class JpaAdminEventQuery implements AdminEventQuery { @Override public AdminEventQuery resourcePath(String resourcePath) { Expression rPath = root.get("resourcePath"); - predicates.add(cb.like(rPath, "%"+resourcePath+"%")); + predicates.add(cb.like(rPath, resourcePath.replace('*', '%'))); return this; } diff --git a/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEventQuery.java b/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEventQuery.java index 8035a14c3b..5702298190 100644 --- a/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEventQuery.java +++ b/server-spi-private/src/main/java/org/keycloak/events/admin/AdminEventQuery.java @@ -81,11 +81,11 @@ public interface AdminEventQuery { AdminEventQuery resourceType(ResourceType ... resourceTypes); /** - * Search by resource path. Supports wildcards * and **. For example: + * Search by resource path. Supports wildcard *. For example: * * * @param resourcePath diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java index 3d33fdc436..96e29204ed 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java @@ -57,9 +57,9 @@ public class AdminEventTest extends AbstractEventTest { return testRealmResource().getAdminEvents(); } - private void createUser(String username) { + private String createUser(String username) { UserRepresentation user = createUserRepresentation(username, username + "@foo.com", "foo", "bar", true); - ApiUtil.createUserWithAdminClient(testRealmResource(), user); + return ApiUtil.createUserWithAdminClient(testRealmResource(), user); } private void updateRealm() { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java index 055ed5d605..0db44be958 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java @@ -152,12 +152,13 @@ public class AdminEventStoreProviderTest extends AbstractEventsTest { testing().onAdminEvent(create(oldest, "realmId", OperationType.CREATE, "realmId", "clientId2", "userId", "127.0.0.1", "/admin/realms/master", "error"), false); testing().onAdminEvent(create("realmId", OperationType.CREATE, "realmId", "clientId", "userId2", "127.0.0.1", "/admin/realms/master", "error"), false); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/admin", null, null, null, null).size()); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/realms", null, null, null, null).size()); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/master", null, null, null, null).size()); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/admin/realms", null, null, null, null).size()); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/realms/master", null, null, null, null).size()); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/admin/realms/master", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/admin/*", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "*/realms/*", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "*/master", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/admin/realms/*", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "*/realms/master", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/admin/*/master", null, null, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, "/ad*/*/master", null, null, null, null).size()); } @Test diff --git a/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties b/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties index 0106590b45..7480ef8baa 100644 --- a/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties +++ b/themes/src/main/resources/theme/base/admin/messages/admin-messages_en.properties @@ -821,7 +821,7 @@ resource-types=Resource Types select-operations.placeholder=Select operations... select-resource-types.placeholder=Select resource types... resource-path=Resource Path -resource-path.tooltip=Filter by resource path. Supports wildcards '*' to match a single part of the path and '**' matches multiple parts. For example 'realms/*/clients/asbc' matches client with id asbc in any realm, while or 'realms/master/**' matches anything in the master realm. +resource-path.tooltip=Filter by resource path. Supports wildcard '*' (for example 'users/*'). date-(from)=Date (From) date-(to)=Date (To) authentication-details=Authentication Details