aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java19
-rw-r--r--src/org/traccar/database/PermissionsManager.java4
2 files changed, 21 insertions, 2 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 530ec1779..c98a5ede7 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -31,6 +31,7 @@ import java.util.Map;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.traccar.Config;
+import org.traccar.helper.Clazz;
import org.traccar.helper.DriverDelegate;
import org.traccar.helper.Log;
import org.traccar.model.Device;
@@ -385,6 +386,24 @@ public class DataManager implements IdentityManager {
.executeUpdate();
}
+ public <T> Collection<T> get(Class<T> clazz) throws SQLException {
+ if (clazz.equals(User.class)) {
+ return (Collection<T>) getUsers();
+ } else if (clazz.equals(Device.class)) {
+ return (Collection<T>) getAllDevices();
+ }
+ return null;
+ }
+
+ public <T> T get(T entity) throws Exception {
+ if (entity instanceof User) {
+ return (T) getUser(Clazz.getId(entity));
+ } else if (entity instanceof Device) {
+ return (T) getDeviceById(Clazz.getId(entity));
+ }
+ return null;
+ }
+
public void add(Object entity) throws SQLException {
if (entity instanceof User) {
addUser((User) entity);
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 138641973..0a43f4ff4 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -67,7 +67,7 @@ public class PermissionsManager {
}
}
- private void checkUser(long userId, long otherUserId) throws SecurityException {
+ public void checkUser(long userId, long otherUserId) throws SecurityException {
if (userId != otherUserId) {
checkAdmin(userId);
}
@@ -77,7 +77,7 @@ public class PermissionsManager {
return getNotNull(userId);
}
- private void checkDevice(long userId, long deviceId) throws SecurityException {
+ public void checkDevice(long userId, long deviceId) throws SecurityException {
if (!getNotNull(userId).contains(deviceId)) {
throw new SecurityException("Device access denied");
}