From b4770c30fdb4bd596bd504eaa3be771b876a0e65 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Wed, 6 Apr 2022 07:37:21 -0300 Subject: [PATCH] Fixing NPE when querying resources by type Closes #11137 --- .../keycloak/authorization/store/PolicyStore.java | 2 +- .../authorization/ResourceManagementTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/server-spi-private/src/main/java/org/keycloak/authorization/store/PolicyStore.java b/server-spi-private/src/main/java/org/keycloak/authorization/store/PolicyStore.java index a3b2be9b8f..61c4530be5 100644 --- a/server-spi-private/src/main/java/org/keycloak/authorization/store/PolicyStore.java +++ b/server-spi-private/src/main/java/org/keycloak/authorization/store/PolicyStore.java @@ -126,7 +126,7 @@ public interface PolicyStore { default List findByResourceType(ResourceServer resourceServer, String resourceType) { List result = new LinkedList<>(); - findByResourceType((ResourceServer) null, resourceType, result::add); + findByResourceType(resourceServer, resourceType, result::add); return result; } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/ResourceManagementTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/ResourceManagementTest.java index d6459a025b..602258f710 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/ResourceManagementTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/ResourceManagementTest.java @@ -70,6 +70,21 @@ public class ResourceManagementTest extends AbstractAuthorizationTest { assertEquals(1, attributes.get("b").size()); } + @Test + public void testCreateWithResourceType() { + ResourceRepresentation newResource = new ResourceRepresentation(); + + newResource.setName("test"); + newResource.setDisplayName("display"); + newResource.setType("some-type"); + + newResource = doCreateResource(newResource); + + ResourceResource resource = getClientResource().authorization().resources().resource(newResource.getId()); + + assertTrue(resource.permissions().isEmpty()); + } + @Test public void failCreateWithSameName() { ResourceRepresentation newResource = createResource();