diff options
author | Christoph Krey <c@ckrey.de> | 2018-04-16 10:45:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-16 10:45:11 +0200 |
commit | 3a602dd133b533cc69d5986d64a00fb3ed670f75 (patch) | |
tree | 97ff753db310a49ae7e53240b1db07fb8475679e /src/org/traccar/api/resource | |
parent | 232de5f0daef98f31b28d177d991fdbfa191f195 (diff) | |
parent | 6d4b8df25c7e942b9ad594db9444fe15bcb16be9 (diff) | |
download | trackermap-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.tar.gz trackermap-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.tar.bz2 trackermap-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.zip |
Merge pull request #4 from traccar/master
upgrade to current master
Diffstat (limited to 'src/org/traccar/api/resource')
5 files changed, 57 insertions, 13 deletions
diff --git a/src/org/traccar/api/resource/AttributeResource.java b/src/org/traccar/api/resource/AttributeResource.java index 26a1f6931..8f0bac473 100644 --- a/src/org/traccar/api/resource/AttributeResource.java +++ b/src/org/traccar/api/resource/AttributeResource.java @@ -52,9 +52,11 @@ public class AttributeResource extends ExtendedObjectResource<Attribute> { if (result != null) { switch (entity.getType()) { case "number": - return Response.ok((Number) result).build(); + Number numberValue = (Number) result; + return Response.ok(numberValue).build(); case "boolean": - return Response.ok((Boolean) result).build(); + Boolean booleanValue = (Boolean) result; + return Response.ok(booleanValue).build(); default: return Response.ok(result.toString()).build(); } diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index 0ea532567..87927e45b 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -71,7 +71,7 @@ public class DeviceResource extends BaseObjectResource<Device> { result = deviceManager.getUserItems(userId); } } else { - result = new HashSet<Long>(); + result = new HashSet<>(); for (String uniqueId : uniqueIds) { Device device = deviceManager.getByUniqueId(uniqueId); Context.getPermissionsManager().checkDevice(getUserId(), device.getId()); @@ -88,7 +88,10 @@ public class DeviceResource extends BaseObjectResource<Device> { @Path("{id}/distance") @PUT public Response updateTotalDistance(DeviceTotalDistance entity) throws SQLException { - Context.getPermissionsManager().checkAdmin(getUserId()); + if (!Context.getPermissionsManager().getUserAdmin(getUserId())) { + Context.getPermissionsManager().checkManager(getUserId()); + Context.getPermissionsManager().checkPermission(Device.class, getUserId(), entity.getDeviceId()); + } Context.getDeviceManager().resetTotalDistance(entity); LogAction.resetTotalDistance(getUserId(), entity.getDeviceId()); return Response.noContent().build(); diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java index a7cf9edbd..e0ccf7020 100644 --- a/src/org/traccar/api/resource/EventResource.java +++ b/src/org/traccar/api/resource/EventResource.java @@ -13,6 +13,7 @@ import org.traccar.Context; import org.traccar.api.BaseResource; import org.traccar.model.Event; import org.traccar.model.Geofence; +import org.traccar.model.Maintenance; @Path("events") @Produces(MediaType.APPLICATION_JSON) @@ -28,6 +29,9 @@ public class EventResource extends BaseResource { if (event.getGeofenceId() != 0) { Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId()); } + if (event.getMaintenanceId() != 0) { + Context.getPermissionsManager().checkPermission(Maintenance.class, getUserId(), event.getMaintenanceId()); + } return event; } diff --git a/src/org/traccar/api/resource/MaintenanceResource.java b/src/org/traccar/api/resource/MaintenanceResource.java new file mode 100644 index 000000000..b3726b429 --- /dev/null +++ b/src/org/traccar/api/resource/MaintenanceResource.java @@ -0,0 +1,36 @@ +/* + * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.api.resource; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.traccar.api.ExtendedObjectResource; +import org.traccar.model.Maintenance; + +@Path("maintenances") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class MaintenanceResource extends ExtendedObjectResource<Maintenance> { + + public MaintenanceResource() { + super(Maintenance.class); + } + +} diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java index 3f7842626..fd331c766 100644 --- a/src/org/traccar/api/resource/SessionResource.java +++ b/src/org/traccar/api/resource/SessionResource.java @@ -17,6 +17,7 @@ package org.traccar.api.resource; import org.traccar.Context; import org.traccar.api.BaseResource; +import org.traccar.helper.DataConverter; import org.traccar.helper.LogAction; import org.traccar.model.User; @@ -34,7 +35,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import javax.xml.bind.DatatypeConverter; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -61,15 +61,14 @@ public class SessionResource extends BaseResource { Cookie[] cookies = request.getCookies(); String email = null, password = null; if (cookies != null) { - for (int i = 0; i < cookies.length; i++) { - if (cookies[i].getName().equals(USER_COOKIE_KEY)) { - byte[] emailBytes = DatatypeConverter.parseBase64Binary( - URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name())); + for (Cookie cookie : cookies) { + if (cookie.getName().equals(USER_COOKIE_KEY)) { + byte[] emailBytes = DataConverter.parseBase64( + URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name())); email = new String(emailBytes, StandardCharsets.UTF_8); - } - if (cookies[i].getName().equals(PASS_COOKIE_KEY)) { - byte[] passwordBytes = DatatypeConverter.parseBase64Binary( - URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name())); + } else if (cookie.getName().equals(PASS_COOKIE_KEY)) { + byte[] passwordBytes = DataConverter.parseBase64( + URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name())); password = new String(passwordBytes, StandardCharsets.UTF_8); } } |