KEYCLOAK-2720: Should not allow two groups with the same path.

This commit is contained in:
Stan Silvert 2016-11-01 16:08:30 -04:00
parent 2c287af977
commit facdd586a3
2 changed files with 14 additions and 0 deletions

View file

@ -48,6 +48,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.keycloak.services.ErrorResponse;
/** /**
* @author Bill Burke * @author Bill Burke
@ -139,6 +140,12 @@ public class GroupResource {
throw new NotFoundException("Could not find group by id"); 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); Response.ResponseBuilder builder = Response.status(204);
GroupModel child = null; GroupModel child = null;
if (rep.getId() != null) { if (rep.getId() != null) {

View file

@ -39,6 +39,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import org.keycloak.services.ErrorResponse;
/** /**
* @author Bill Burke * @author Bill Burke
@ -102,6 +103,12 @@ public class GroupsResource {
public Response addTopLevelGroup(GroupRepresentation rep) { public Response addTopLevelGroup(GroupRepresentation rep) {
auth.requireManage(); 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; GroupModel child = null;
Response.ResponseBuilder builder = Response.status(204); Response.ResponseBuilder builder = Response.status(204);
if (rep.getId() != null) { if (rep.getId() != null) {