use of org.traccar.model.Device in project traccar by tananaev.
the class BaseProtocolEncoder method initDevicePassword.
protected void initDevicePassword(Command command, String defaultPassword) {
if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
Device device = Context.getIdentityManager().getById(command.getDeviceId());
String password = device.getString(Command.KEY_DEVICE_PASSWORD);
if (password != null) {
command.set(Command.KEY_DEVICE_PASSWORD, password);
} else {
command.set(Command.KEY_DEVICE_PASSWORD, defaultPassword);
}
}
}
use of org.traccar.model.Device in project traccar by tananaev.
the class MediaFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpResponse = (HttpServletResponse) response;
try {
HttpSession session = ((HttpServletRequest) request).getSession(false);
Long userId = null;
if (session != null) {
userId = (Long) session.getAttribute(SessionResource.USER_ID_KEY);
if (userId != null) {
Context.getPermissionsManager().checkUserEnabled(userId);
Context.getStatisticsManager().registerRequest(userId);
}
}
if (userId == null) {
httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
String path = ((HttpServletRequest) request).getPathInfo();
String[] parts = path.split("/");
if (parts.length < 2 || parts.length == 2 && !path.endsWith("/")) {
Context.getPermissionsManager().checkAdmin(userId);
} else {
Device device = Context.getDeviceManager().getByUniqueId(parts[1]);
if (device != null) {
Context.getPermissionsManager().checkDevice(userId, device.getId());
} else {
httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
chain.doFilter(request, response);
} catch (SecurityException e) {
httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
httpResponse.getWriter().println(Log.exceptionStack(e));
} catch (SQLException e) {
httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
httpResponse.getWriter().println(Log.exceptionStack(e));
}
}
use of org.traccar.model.Device in project traccar by tananaev.
the class DeviceManager method updateCachedItem.
@Override
protected void updateCachedItem(Device device) {
Device cachedDevice = getById(device.getId());
cachedDevice.setName(device.getName());
cachedDevice.setGroupId(device.getGroupId());
cachedDevice.setCategory(device.getCategory());
cachedDevice.setContact(device.getContact());
cachedDevice.setModel(device.getModel());
cachedDevice.setDisabled(device.getDisabled());
cachedDevice.setAttributes(device.getAttributes());
if (!device.getUniqueId().equals(cachedDevice.getUniqueId())) {
devicesByUniqueId.remove(cachedDevice.getUniqueId());
cachedDevice.setUniqueId(device.getUniqueId());
putUniqueDeviceId(cachedDevice);
}
if (device.getPhone() != null && !device.getPhone().isEmpty() && !device.getPhone().equals(cachedDevice.getPhone())) {
String phone = cachedDevice.getPhone();
if (phone != null && !phone.isEmpty()) {
devicesByPhone.remove(phone);
}
cachedDevice.setPhone(device.getPhone());
putPhone(cachedDevice);
}
}
use of org.traccar.model.Device in project traccar by tananaev.
the class DeviceManager method updateLatestPosition.
public void updateLatestPosition(Position position) throws SQLException {
if (isLatestPosition(position)) {
getDataManager().updateLatestPosition(position);
Device device = getById(position.getDeviceId());
if (device != null) {
device.setPositionId(position.getId());
}
positions.put(position.getDeviceId(), position);
if (Context.getConnectionManager() != null) {
Context.getConnectionManager().updatePosition(position);
}
}
}
use of org.traccar.model.Device in project traccar by tananaev.
the class DeviceManager method removeCachedItem.
@Override
protected void removeCachedItem(long deviceId) {
Device cachedDevice = getById(deviceId);
if (cachedDevice != null) {
String deviceUniqueId = cachedDevice.getUniqueId();
String phone = cachedDevice.getPhone();
super.removeCachedItem(deviceId);
devicesByUniqueId.remove(deviceUniqueId);
if (phone != null && !phone.isEmpty()) {
devicesByPhone.remove(phone);
}
}
positions.remove(deviceId);
}
Aggregations