aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-08-28 10:59:15 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-08-28 10:59:15 +1200
commit037e0394d41c8c0557a28059a65373edaba0d929 (patch)
treead9798f4ceb49181190a03bf676c9c0435e1db35 /src/org/traccar/BaseProtocolEncoder.java
parent7eb57d7c23e68774197ab78986c0fbd2c02f6042 (diff)
downloadtrackermap-server-037e0394d41c8c0557a28059a65373edaba0d929.tar.gz
trackermap-server-037e0394d41c8c0557a28059a65373edaba0d929.tar.bz2
trackermap-server-037e0394d41c8c0557a28059a65373edaba0d929.zip
Allow to pass password in commands
Diffstat (limited to 'src/org/traccar/BaseProtocolEncoder.java')
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
index 050697801..2bf6cde66 100644
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ b/src/org/traccar/BaseProtocolEncoder.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.
@@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import org.traccar.helper.Log;
import org.traccar.model.Command;
+import org.traccar.model.Device;
public abstract class BaseProtocolEncoder extends OneToOneEncoder {
@@ -27,6 +28,18 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
return Context.getIdentityManager().getDeviceById(deviceId).getUniqueId();
}
+ protected void initDevicePassword(Command command, String defaultPassword) {
+ if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
+ Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId());
+ if (device.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
+ String password = (String) device.getAttributes().get(Command.KEY_DEVICE_PASSWORD);
+ command.set(Command.KEY_DEVICE_PASSWORD, password);
+ } else {
+ command.set(Command.KEY_DEVICE_PASSWORD, defaultPassword);
+ }
+ }
+ }
+
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {