From ce3a16ef9d235390e839e6c01bc2ccc96049ead6 Mon Sep 17 00:00:00 2001 From: jcardus Date: Sun, 11 Jul 2021 02:05:50 +0100 Subject: check permission types --- .../org/traccar/api/resource/PermissionsResource.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java index db16bf941..50ae11aaf 100644 --- a/src/main/java/org/traccar/api/resource/PermissionsResource.java +++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java @@ -20,6 +20,7 @@ import java.sql.SQLException; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -82,16 +83,13 @@ public class PermissionsResource extends BaseResource { return Response.noContent().build(); } - private void checkPermissionTypes(List> entities) throws ClassNotFoundException { - if (!entities.isEmpty()) { - Permission first = new Permission(entities.get(0)); - for (LinkedHashMap entity: entities) { - Permission permission = new Permission(entity); - if (!first.getOwnerClass().equals(permission.getOwnerClass()) - || !first.getPropertyClass().equals(permission.getPropertyClass())) { - throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build()); - } + private void checkPermissionTypes(List> entities) { + Set keys = null; + for (LinkedHashMap entity: entities) { + if (keys != null & !entity.keySet().equals(keys)) { + throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build()); } + keys = entity.keySet(); } } -- cgit v1.2.3