diff options
author | Abyss777 <abyss@fox5.ru> | 2017-07-19 15:24:55 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-07-19 15:24:55 +0500 |
commit | a9478ded48de140d47d17def1ee5329267fe6088 (patch) | |
tree | adc5a9177fd5adcf10a8b56ee4620780dfc13cd9 /src/org/traccar/database/PermissionsManager.java | |
parent | cb0d7cccaecfe049e04defd90884976ac1e982f9 (diff) | |
download | trackermap-server-a9478ded48de140d47d17def1ee5329267fe6088.tar.gz trackermap-server-a9478ded48de140d47d17def1ee5329267fe6088.tar.bz2 trackermap-server-a9478ded48de140d47d17def1ee5329267fe6088.zip |
Refactored four managers
Diffstat (limited to 'src/org/traccar/database/PermissionsManager.java')
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 73 |
1 files changed, 29 insertions, 44 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index 82ca6af49..f88e14bfe 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -298,52 +298,37 @@ public class PermissionsManager { } } - public void checkGeofence(long userId, long geofenceId) throws SecurityException { - if (!Context.getGeofenceManager().checkGeofence(userId, geofenceId) && !isAdmin(userId)) { - checkManager(userId); - for (long managedUserId : getUserPermissions(userId)) { - if (Context.getGeofenceManager().checkGeofence(managedUserId, geofenceId)) { - return; - } - } - throw new SecurityException("Geofence access denied"); - } - } - - public void checkAttribute(long userId, long attributeId) throws SecurityException { - if (!Context.getAttributesManager().checkAttribute(userId, attributeId) && !isAdmin(userId)) { - checkManager(userId); - for (long managedUserId : getUserPermissions(userId)) { - if (Context.getAttributesManager().checkAttribute(managedUserId, attributeId)) { - return; - } - } - throw new SecurityException("Attribute access denied"); - } - } - - public void checkDriver(long userId, long driverId) throws SecurityException { - if (!Context.getDriversManager().checkDriver(userId, driverId) && !isAdmin(userId)) { - checkManager(userId); - for (long managedUserId : getUserPermissions(userId)) { - if (Context.getDriversManager().checkDriver(managedUserId, driverId)) { - return; - } - } - throw new SecurityException("Driver access denied"); - } - } - - - public void checkCalendar(long userId, long calendarId) throws SecurityException { - if (!Context.getCalendarManager().checkCalendar(userId, calendarId) && !isAdmin(userId)) { - checkManager(userId); - for (long managedUserId : getUserPermissions(userId)) { - if (Context.getCalendarManager().checkCalendar(managedUserId, calendarId)) { - return; + public void checkPermission(String object, long userId, long objectId) throws SecurityException { + SimpleObjectManager manager = null; + + switch (object) { + case "geofence": + manager = Context.getGeofenceManager(); + break; + case "attribute": + manager = Context.getAttributesManager(); + break; + case "driver": + manager = Context.getDriversManager(); + break; + case "calendar": + manager = Context.getCalendarManager(); + break; + default: + throw new IllegalArgumentException("Unknown object type"); + } + + if (manager != null) { + if (manager.checkItemPermission(userId, objectId) && !isAdmin(userId)) { + checkManager(userId); + for (long managedUserId : getUserPermissions(userId)) { + if (manager.checkItemPermission(managedUserId, objectId)) { + return; + } } + throw new SecurityException(object.substring(0, 1).toUpperCase() + object.substring(1) + + " access denied"); } - throw new SecurityException("Calendar access denied"); } } |