aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-03-08 22:41:32 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-03-08 22:41:32 +1300
commit8cd4f224572e55cd3c87119db24b8adcf1f0351a (patch)
treeb324d393317c6eefdc5e6dd33f1283c697e99f53 /src/org/traccar
parent1f2328bd8f4e341dda897fcd52418beb6cf1b83a (diff)
downloadtrackermap-server-8cd4f224572e55cd3c87119db24b8adcf1f0351a.tar.gz
trackermap-server-8cd4f224572e55cd3c87119db24b8adcf1f0351a.tar.bz2
trackermap-server-8cd4f224572e55cd3c87119db24b8adcf1f0351a.zip
Start refactoring permissions manager
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/database/PermissionsManager.java32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 29228ceeb..854732fa2 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,13 +34,21 @@ public class PermissionsManager {
private final Map<Long, User> users = new HashMap<>();
- private final Map<Long, Set<Long>> permissions = new HashMap<>();
+ private final Map<Long, Set<Long>> groupPermissions = new HashMap<>();
+ private final Map<Long, Set<Long>> devicePermissions = new HashMap<>();
- private Set<Long> getPermissions(long userId) {
- if (!permissions.containsKey(userId)) {
- permissions.put(userId, new HashSet<Long>());
+ private Set<Long> getGroupPermissions(long userId) {
+ if (!groupPermissions.containsKey(userId)) {
+ groupPermissions.put(userId, new HashSet<Long>());
}
- return permissions.get(userId);
+ return groupPermissions.get(userId);
+ }
+
+ private Set<Long> getDevicePermissions(long userId) {
+ if (!devicePermissions.containsKey(userId)) {
+ devicePermissions.put(userId, new HashSet<Long>());
+ }
+ return devicePermissions.get(userId);
}
public PermissionsManager(DataManager dataManager) {
@@ -50,14 +58,14 @@ public class PermissionsManager {
public final void refresh() {
users.clear();
- permissions.clear();
+ devicePermissions.clear();
try {
server = dataManager.getServer();
for (User user : dataManager.getUsers()) {
users.put(user.getId(), user);
}
for (DevicePermission permission : dataManager.getPermissions()) {
- getPermissions(permission.getUserId()).add(permission.getDeviceId());
+ getDevicePermissions(permission.getUserId()).add(permission.getDeviceId());
}
} catch (SQLException error) {
Log.warning(error);
@@ -80,12 +88,16 @@ public class PermissionsManager {
}
}
+ public Collection<Long> allowedGroups(long userId) {
+ return getGroupPermissions(userId);
+ }
+
public Collection<Long> allowedDevices(long userId) {
- return getPermissions(userId);
+ return getDevicePermissions(userId);
}
public void checkDevice(long userId, long deviceId) throws SecurityException {
- if (!getPermissions(userId).contains(deviceId)) {
+ if (!getDevicePermissions(userId).contains(deviceId)) {
throw new SecurityException("Device access denied");
}
}