aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/PermissionsManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-27 17:00:45 +1200
committerGitHub <noreply@github.com>2017-07-27 17:00:45 +1200
commit495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598 (patch)
tree4b65fbe2d6081f31762a0d8aa790b9fcf81e81f7 /src/org/traccar/database/PermissionsManager.java
parent194263a9dc8040ebcbf62c80733aca5097eb3e36 (diff)
parent49fa4893269b1732806f7176c279742291e02edf (diff)
downloadtrackermap-server-495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598.tar.gz
trackermap-server-495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598.tar.bz2
trackermap-server-495b2aa2d2b17bd1a5803ea0bd7dcc64bc81c598.zip
Merge pull request #3391 from Abyss777/refactor_drivers_groups
Split Drivers and Groups management
Diffstat (limited to 'src/org/traccar/database/PermissionsManager.java')
-rw-r--r--src/org/traccar/database/PermissionsManager.java46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index b38ecf9bf..3b03c1900 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -18,6 +18,7 @@ package org.traccar.database;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Attribute;
+import org.traccar.model.BaseModel;
import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Driver;
@@ -51,7 +52,7 @@ public class PermissionsManager {
this.dataManager = dataManager;
this.usersManager = usersManager;
refreshServer();
- refreshPermissions();
+ refreshDeviceAndGroupPermissions();
}
public User getUser(long userId) {
@@ -94,11 +95,12 @@ public class PermissionsManager {
}
}
- public final void refreshPermissions() {
+ public final void refreshDeviceAndGroupPermissions() {
groupPermissions.clear();
devicePermissions.clear();
try {
- GroupTree groupTree = new GroupTree(Context.getDeviceManager().getAllGroups(),
+ GroupTree groupTree = new GroupTree(Context.getGroupsManager().getItems(
+ Context.getGroupsManager().getAllItems()),
Context.getDeviceManager().getAllDevices());
for (Permission groupPermission : dataManager.getPermissions(User.class, Group.class)) {
Set<Long> userGroupPermissions = getGroupPermissions(groupPermission.getOwnerId());
@@ -117,9 +119,9 @@ public class PermissionsManager {
}
groupDevices.clear();
- for (Group group : Context.getDeviceManager().getAllGroups()) {
- for (Device device : groupTree.getDevices(group.getId())) {
- getGroupDevices(group.getId()).add(device.getId());
+ for (long groupId : Context.getGroupsManager().getAllItems()) {
+ for (Device device : groupTree.getDevices(groupId)) {
+ getGroupDevices(groupId).add(device.getId());
}
}
@@ -159,14 +161,14 @@ public class PermissionsManager {
public void checkManager(long userId, long managedUserId) throws SecurityException {
checkManager(userId);
- if (!usersManager.getManagedItems(userId).contains(managedUserId)) {
+ if (!usersManager.getUserItems(userId).contains(managedUserId)) {
throw new SecurityException("User access denied");
}
}
public void checkUserLimit(long userId) throws SecurityException {
int userLimit = getUser(userId).getUserLimit();
- if (userLimit != -1 && usersManager.getManagedItems(userId).size() >= userLimit) {
+ if (userLimit != -1 && usersManager.getUserItems(userId).size() >= userLimit) {
throw new SecurityException("Manager user limit reached");
}
}
@@ -176,9 +178,9 @@ public class PermissionsManager {
if (deviceLimit != -1) {
int deviceCount = 0;
if (isManager(userId)) {
- deviceCount = Context.getDeviceManager().getManagedDevices(userId).size();
+ deviceCount = Context.getDeviceManager().getManagedItems(userId).size();
} else {
- deviceCount = getDevicePermissions(userId).size();
+ deviceCount = Context.getDeviceManager().getUserItems(userId).size();
}
if (deviceCount >= deviceLimit) {
throw new SecurityException("User device limit reached");
@@ -254,7 +256,7 @@ public class PermissionsManager {
public void checkGroup(long userId, long groupId) throws SecurityException {
if (!getGroupPermissions(userId).contains(groupId) && !isAdmin(userId)) {
checkManager(userId);
- for (long managedUserId : usersManager.getManagedItems(userId)) {
+ for (long managedUserId : usersManager.getUserItems(userId)) {
if (getGroupPermissions(managedUserId).contains(groupId)) {
return;
}
@@ -264,10 +266,10 @@ public class PermissionsManager {
}
public void checkDevice(long userId, long deviceId) throws SecurityException {
- if (!getDevicePermissions(userId).contains(deviceId) && !isAdmin(userId)) {
+ if (!Context.getDeviceManager().getUserItems(userId).contains(deviceId) && !isAdmin(userId)) {
checkManager(userId);
- for (long managedUserId : usersManager.getManagedItems(userId)) {
- if (getDevicePermissions(managedUserId).contains(deviceId)) {
+ for (long managedUserId : usersManager.getUserItems(userId)) {
+ if (Context.getDeviceManager().getUserItems(managedUserId).contains(deviceId)) {
return;
}
}
@@ -283,7 +285,7 @@ public class PermissionsManager {
public void checkPermission(Class<?> object, long userId, long objectId)
throws SecurityException {
- SimpleObjectManager manager = null;
+ SimpleObjectManager<? extends BaseModel> manager = null;
if (object.equals(Device.class)) {
checkDevice(userId, objectId);
@@ -314,6 +316,18 @@ public class PermissionsManager {
}
}
+ public void refreshAllUsersPermissions() {
+ if (Context.getGeofenceManager() != null) {
+ Context.getGeofenceManager().refreshUserItems();
+ }
+ Context.getCalendarManager().refreshUserItems();
+ Context.getDriversManager().refreshUserItems();
+ Context.getAttributesManager().refreshUserItems();
+ if (Context.getNotificationManager() != null) {
+ Context.getNotificationManager().refresh();
+ }
+ }
+
public void refreshAllExtendedPermissions() {
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refreshExtendedPermissions();
@@ -326,7 +340,7 @@ public class PermissionsManager {
if (permission.getOwnerClass().equals(User.class)) {
if (permission.getPropertyClass().equals(Device.class)
|| permission.getPropertyClass().equals(Group.class)) {
- refreshPermissions();
+ refreshDeviceAndGroupPermissions();
refreshAllExtendedPermissions();
} else if (permission.getPropertyClass().equals(ManagedUser.class)) {
usersManager.refreshUserItems();