From 497787d2cdbfd48ca40d605ef2206613c932e130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adamczyk=20B=C5=82a=C5=BCej?= Date: Mon, 10 Feb 2020 14:38:34 -0300 Subject: [PATCH] [KEYCLOAK-10696] - fixed missing client role attributes after import --- .../org/keycloak/models/utils/RepresentationToModel.java | 3 +++ .../keycloak/testsuite/exportimport/ExportImportTest.java | 4 ++++ .../tests/base/src/test/resources/testrealm.json | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java b/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java index e224b14391..58a4cc9eb0 100755 --- a/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java +++ b/server-spi-private/src/main/java/org/keycloak/models/utils/RepresentationToModel.java @@ -628,6 +628,9 @@ public class RepresentationToModel { // Application role may already exists (for example if it is defaultRole) RoleModel role = roleRep.getId() != null ? client.addRole(roleRep.getId(), roleRep.getName()) : client.addRole(roleRep.getName()); role.setDescription(roleRep.getDescription()); + if (roleRep.getAttributes() != null) { + roleRep.getAttributes().forEach((key, value) -> role.setAttribute(key, value)); + } } } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java index 947087c523..def8d2c8db 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java @@ -315,6 +315,7 @@ public class ExportImportTest extends AbstractKeycloakTest { Map> roleAttributes = adminClient.realm("test").roles().get("attribute-role").toRepresentation().getAttributes(); String testAppId = adminClient.realm("test").clients().findByClientId("test-app").get(0).getId(); String sampleClientRoleId = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getId(); + String sampleClientRoleAttribute = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getAttributes().get("sample-client-role-attribute").get(0); // Delete some realm (and some data in admin realm) adminClient.realm("test").remove(); @@ -365,6 +366,9 @@ public class ExportImportTest extends AbstractKeycloakTest { String importedSampleClientRoleId = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getId(); assertEquals(sampleClientRoleId, importedSampleClientRoleId); + String importedSampleClientRoleAttribute = adminClient.realm("test").clients().get(testAppId).roles().get("sample-client-role").toRepresentation().getAttributes().get("sample-client-role-attribute").get(0); + assertEquals(sampleClientRoleAttribute, importedSampleClientRoleAttribute); + checkEventsConfig(adminClient.realm("test").getRealmEventsConfig()); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json b/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json index d7f39158fd..2c849831af 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/testrealm.json @@ -473,7 +473,12 @@ }, { "name": "sample-client-role", - "description": "Sample client role" + "description": "Sample client role", + "attributes": { + "sample-client-role-attribute": [ + "sample-client-role-attribute-value" + ] + } }, { "name": "customer-admin-composite-role",