KEYCLOAK-14106 Adding a role to a composite role does not work with kcadm
This commit is contained in:
parent
7247734a0f
commit
7fea6776f8
5 changed files with 12 additions and 16 deletions
|
@ -24,6 +24,6 @@ import static org.keycloak.client.admin.cli.util.HttpUtil.getIdForType;
|
||||||
public class ClientOperations {
|
public class ClientOperations {
|
||||||
|
|
||||||
public static String getIdFromClientId(String rootUrl, String realm, String auth, String clientId) {
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,11 @@ import static org.keycloak.client.admin.cli.util.HttpUtil.getIdForType;
|
||||||
public class GroupOperations {
|
public class GroupOperations {
|
||||||
|
|
||||||
public static String getIdFromName(String rootUrl, String realm, String auth, String groupname) {
|
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) {
|
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) {
|
public static void addRealmRoles(String rootUrl, String realm, String auth, String groupid, List<?> roles) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class RoleOperations {
|
||||||
public static class LIST_OF_NODES extends ArrayList<ObjectNode>{};
|
public static class LIST_OF_NODES extends ArrayList<ObjectNode>{};
|
||||||
|
|
||||||
public static String getIdFromRoleName(String adminRoot, String realm, String auth, String rname) {
|
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) {
|
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) {
|
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) {
|
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) {
|
public static List<RoleRepresentation> getRealmRoles(String rootUrl, String realm, String auth) {
|
||||||
|
|
|
@ -91,6 +91,6 @@ public class UserOperations {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIdFromUsername(String rootUrl, String realm, String auth, String username) {
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,25 +434,21 @@ public class HttpUtil {
|
||||||
checkSuccess(resourceUrl, response);
|
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);
|
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);
|
List<ObjectNode> users = doGetJSON(RoleOperations.LIST_OF_NODES.class, resourceUrl, auth);
|
||||||
|
|
||||||
ObjectNode user;
|
ObjectNode user;
|
||||||
try {
|
try {
|
||||||
user = new LocalSearch(users).exactMatchOne(attrValue, attrName);
|
user = new LocalSearch(users).exactMatchOne(attrValue, inputAttrName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Multiple " + resourceEndpoint + " found for " + attrName + ": " + attrValue, e);
|
throw new RuntimeException("Multiple " + resourceEndpoint + " found for " + attrName + ": " + attrValue, e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue