Skip to content

Commit

Permalink
KEYCLOAK-14106 Adding a role to a composite role does not work with k…
Browse files Browse the repository at this point in the history
…cadm
  • Loading branch information
martin-kanis authored and hmlnarik committed Jul 3, 2020
1 parent 7247734 commit 7fea677
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class LIST_OF_ROLES extends ArrayList<RoleRepresentation>{};
public static class LIST_OF_NODES extends ArrayList<ObjectNode>{};

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) {
Expand All @@ -60,11 +60,11 @@ public static void removeClientRoles(String rootUrl, String realm, String auth,
}

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<RoleRepresentation> getRealmRoles(String rootUrl, String realm, String auth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ public static void resetUserPassword(String rootUrl, String realm, String auth,
}

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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,25 +434,21 @@ public static void doDeleteJSON(String resourceUrl, String auth, Object content)
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<ObjectNode> 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);
}
Expand Down

0 comments on commit 7fea677

Please sign in to comment.