From 7fea6776f84b8af94f45aa52308819471a81de75 Mon Sep 17 00:00:00 2001 From: Martin Kanis Date: Wed, 27 May 2020 14:04:00 +0200 Subject: [PATCH] KEYCLOAK-14106 Adding a role to a composite role does not work with kcadm --- .../admin/cli/operations/ClientOperations.java | 2 +- .../admin/cli/operations/GroupOperations.java | 4 ++-- .../admin/cli/operations/RoleOperations.java | 6 +++--- .../admin/cli/operations/UserOperations.java | 2 +- .../keycloak/client/admin/cli/util/HttpUtil.java | 14 +++++--------- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/ClientOperations.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/ClientOperations.java index 7de4e29baa..7106668241 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/ClientOperations.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/ClientOperations.java @@ -24,6 +24,6 @@ import static org.keycloak.client.admin.cli.util.HttpUtil.getIdForType; public class ClientOperations { public static String getIdFromClientId(String rootUrl, String realm, String auth, String clientId) { - return getIdForType(rootUrl, realm, auth, "clients", "clientId", clientId); + return getIdForType(rootUrl, realm, auth, "clients", "clientId", clientId, "clientId"); } } diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/GroupOperations.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/GroupOperations.java index a9cec66040..2a8d9c4971 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/GroupOperations.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/GroupOperations.java @@ -29,11 +29,11 @@ import static org.keycloak.client.admin.cli.util.HttpUtil.getIdForType; public class GroupOperations { public static String getIdFromName(String rootUrl, String realm, String auth, String groupname) { - return getIdForType(rootUrl, realm, auth, "groups", "name", groupname); + return getIdForType(rootUrl, realm, auth, "groups", "name", groupname, "name"); } public static String getIdFromPath(String rootUrl, String realm, String auth, String path) { - return getIdForType(rootUrl, realm, auth, "groups", "path", path); + return getIdForType(rootUrl, realm, auth, "groups", "path", path, "path"); } public static void addRealmRoles(String rootUrl, String realm, String auth, String groupid, List roles) { diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/RoleOperations.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/RoleOperations.java index c7e310844e..3dbbcf7bad 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/RoleOperations.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/RoleOperations.java @@ -38,7 +38,7 @@ public class RoleOperations { public static class LIST_OF_NODES extends ArrayList{}; public static String getIdFromRoleName(String adminRoot, String realm, String auth, String rname) { - return getIdForType(adminRoot, realm, auth, "roles", "name", rname); + return getIdForType(adminRoot, realm, auth, "roles", "search", rname, "name"); } public static void addRealmRoles(String rootUrl, String realm, String auth, String roleid, List roles) { @@ -60,11 +60,11 @@ public class RoleOperations { } public static String getRoleNameFromId(String adminRoot, String realm, String auth, String rid) { - return getAttrForType(adminRoot, realm, auth, "roles", "id", rid, "name"); + return getAttrForType(adminRoot, realm, auth, "roles", "id", rid, "id","name"); } public static String getClientRoleNameFromId(String adminRoot, String realm, String auth, String cid, String rid) { - return getAttrForType(adminRoot, realm, auth, "clients/" + cid + "/roles", "id", rid, "name"); + return getAttrForType(adminRoot, realm, auth, "clients/" + cid + "/roles", "id", rid, "id", "name"); } public static List getRealmRoles(String rootUrl, String realm, String auth) { diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/UserOperations.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/UserOperations.java index 593c97e313..8e561c3638 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/UserOperations.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/operations/UserOperations.java @@ -91,6 +91,6 @@ public class UserOperations { } public static String getIdFromUsername(String rootUrl, String realm, String auth, String username) { - return getIdForType(rootUrl, realm, auth, "users", "username", username); + return getIdForType(rootUrl, realm, auth, "users", "username", username, "username"); } } diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/util/HttpUtil.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/util/HttpUtil.java index ebc9b8d4a5..477216677d 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/util/HttpUtil.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/util/HttpUtil.java @@ -434,25 +434,21 @@ public class HttpUtil { checkSuccess(resourceUrl, response); } - public static String getIdForType(String rootUrl, String realm, String auth, String resourceEndpoint, String attrName, String attrValue) { + public static String getIdForType(String rootUrl, String realm, String auth, String resourceEndpoint, String attrName, String attrValue, String inputAttrName) { - return getAttrForType(rootUrl, realm, auth, resourceEndpoint, attrName, attrValue, "id"); + return getAttrForType(rootUrl, realm, auth, resourceEndpoint, attrName, attrValue, inputAttrName, "id"); } - public static String getAttrForType(String rootUrl, String realm, String auth, String resourceEndpoint, String attrName, String attrValue, String returnAttrName) { + public static String getAttrForType(String rootUrl, String realm, String auth, String resourceEndpoint, String attrName, String attrValue, String inputAttrName, String returnAttrName) { String resourceUrl = composeResourceUrl(rootUrl, realm, resourceEndpoint); - if ("roles".equals(resourceEndpoint)) { - resourceUrl = HttpUtil.addQueryParamsToUri(resourceUrl, "search", attrValue, "first", "0", "max", "2"); - } else { - resourceUrl = HttpUtil.addQueryParamsToUri(resourceUrl, attrName, attrValue, "first", "0", "max", "2"); - } + resourceUrl = HttpUtil.addQueryParamsToUri(resourceUrl, attrName, attrValue, "first", "0", "max", "2"); List users = doGetJSON(RoleOperations.LIST_OF_NODES.class, resourceUrl, auth); ObjectNode user; try { - user = new LocalSearch(users).exactMatchOne(attrValue, attrName); + user = new LocalSearch(users).exactMatchOne(attrValue, inputAttrName); } catch (Exception e) { throw new RuntimeException("Multiple " + resourceEndpoint + " found for " + attrName + ": " + attrValue, e); }