KEYCLOAK-2720: Should not allow two groups with the same path.
This commit is contained in:
parent
2c287af977
commit
facdd586a3
2 changed files with 14 additions and 0 deletions
|
@ -48,6 +48,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.keycloak.services.ErrorResponse;
|
||||
|
||||
/**
|
||||
* @author Bill Burke
|
||||
|
@ -139,6 +140,12 @@ public class GroupResource {
|
|||
throw new NotFoundException("Could not find group by id");
|
||||
}
|
||||
|
||||
for (GroupModel group : group.getSubGroups()) {
|
||||
if (group.getName().equals(rep.getName())) {
|
||||
return ErrorResponse.exists("Parent already contains subgroup named '" + rep.getName() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
Response.ResponseBuilder builder = Response.status(204);
|
||||
GroupModel child = null;
|
||||
if (rep.getId() != null) {
|
||||
|
|
|
@ -39,6 +39,7 @@ import javax.ws.rs.core.Response;
|
|||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import org.keycloak.services.ErrorResponse;
|
||||
|
||||
/**
|
||||
* @author Bill Burke
|
||||
|
@ -102,6 +103,12 @@ public class GroupsResource {
|
|||
public Response addTopLevelGroup(GroupRepresentation rep) {
|
||||
auth.requireManage();
|
||||
|
||||
for (GroupModel group : realm.getGroups()) {
|
||||
if (group.getName().equals(rep.getName())) {
|
||||
return ErrorResponse.exists("Top level group named '" + rep.getName() + "' already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
GroupModel child = null;
|
||||
Response.ResponseBuilder builder = Response.status(204);
|
||||
if (rep.getId() != null) {
|
||||
|
|
Loading…
Reference in a new issue