aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/BaseProtocolEncoder.java2
-rw-r--r--src/main/java/org/traccar/database/DeviceManager.java11
-rw-r--r--src/main/java/org/traccar/database/IdentityManager.java2
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java2
-rw-r--r--src/test/java/org/traccar/TestIdentityManager.java2
5 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolEncoder.java b/src/main/java/org/traccar/BaseProtocolEncoder.java
index 69d1fe6f5..b6df07b98 100644
--- a/src/main/java/org/traccar/BaseProtocolEncoder.java
+++ b/src/main/java/org/traccar/BaseProtocolEncoder.java
@@ -46,7 +46,7 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter
protected void initDevicePassword(Command command, String defaultPassword) {
if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
String password = Context.getIdentityManager()
- .getDevicePassword(command.getDeviceId(), defaultPassword);
+ .getDevicePassword(command.getDeviceId(), getProtocolName(), defaultPassword);
command.set(Command.KEY_DEVICE_PASSWORD, password);
}
}
diff --git a/src/main/java/org/traccar/database/DeviceManager.java b/src/main/java/org/traccar/database/DeviceManager.java
index d5b1c8c0d..51f35b3db 100644
--- a/src/main/java/org/traccar/database/DeviceManager.java
+++ b/src/main/java/org/traccar/database/DeviceManager.java
@@ -116,13 +116,20 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
}
@Override
- public String getDevicePassword(long id, String defaultPassword) {
+ public String getDevicePassword(long id, String protocol, String defaultPassword) {
- String password = getById(id).getString(Command.KEY_DEVICE_PASSWORD);
+ String password = lookupAttributeString(id, Command.KEY_DEVICE_PASSWORD, null, false);
if (password != null) {
return password;
}
+ if (protocol != null) {
+ password = Context.getConfig().getString(protocol + "." + Command.KEY_DEVICE_PASSWORD);
+ if (password != null) {
+ return password;
+ }
+ }
+
return defaultPassword;
}
diff --git a/src/main/java/org/traccar/database/IdentityManager.java b/src/main/java/org/traccar/database/IdentityManager.java
index b30537f4f..af6a6ce71 100644
--- a/src/main/java/org/traccar/database/IdentityManager.java
+++ b/src/main/java/org/traccar/database/IdentityManager.java
@@ -26,7 +26,7 @@ public interface IdentityManager {
Device getByUniqueId(String uniqueId) throws Exception;
- String getDevicePassword(long id, String defaultPassword);
+ String getDevicePassword(long id, String protocol, String defaultPassword);
Position getLastPosition(long deviceId);
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
index 2185b707e..06a379862 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -254,7 +254,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
sendAcknowledge(status, event, checksum, channel, remoteAddress);
String devicePassword = Context.getIdentityManager()
- .getDevicePassword(deviceSession.getDeviceId(), DEFAULT_DEVICE_PASSWORD);
+ .getDevicePassword(deviceSession.getDeviceId(), getProtocolName(), DEFAULT_DEVICE_PASSWORD);
sendEventResponse(event, devicePassword, channel, remoteAddress);
}
diff --git a/src/test/java/org/traccar/TestIdentityManager.java b/src/test/java/org/traccar/TestIdentityManager.java
index 3febe3b83..af5dd22df 100644
--- a/src/test/java/org/traccar/TestIdentityManager.java
+++ b/src/test/java/org/traccar/TestIdentityManager.java
@@ -30,7 +30,7 @@ public final class TestIdentityManager implements IdentityManager {
}
@Override
- public String getDevicePassword(long id, String defaultPassword) {
+ public String getDevicePassword(long id, String protocol, String defaultPassword) {
return defaultPassword;
}