aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-22 08:35:59 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-22 08:35:59 -0700
commit1271b2e7a772c8458b567d7f424d5a38365b5d75 (patch)
treeb23fdd8dd45dbf7ff0102a950958145bc00df373 /src/main/java/org/traccar
parentcc9eca495f93b8ffaee0fe5b10b62f1f3dfbf945 (diff)
downloadtrackermap-server-1271b2e7a772c8458b567d7f424d5a38365b5d75.tar.gz
trackermap-server-1271b2e7a772c8458b567d7f424d5a38365b5d75.tar.bz2
trackermap-server-1271b2e7a772c8458b567d7f424d5a38365b5d75.zip
Login as another user
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/api/resource/SessionResource.java15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/api/resource/SessionResource.java b/src/main/java/org/traccar/api/resource/SessionResource.java
index 91052fc6b..8eabdc63c 100644
--- a/src/main/java/org/traccar/api/resource/SessionResource.java
+++ b/src/main/java/org/traccar/api/resource/SessionResource.java
@@ -22,6 +22,9 @@ import org.traccar.helper.ServletHelper;
import org.traccar.helper.LogAction;
import org.traccar.model.User;
import org.traccar.storage.StorageException;
+import org.traccar.storage.query.Columns;
+import org.traccar.storage.query.Condition;
+import org.traccar.storage.query.Request;
import javax.annotation.security.PermitAll;
import javax.inject.Inject;
@@ -33,6 +36,7 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
@@ -107,6 +111,17 @@ public class SessionResource extends BaseResource {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
}
+ @Path("{id}")
+ @GET
+ public User get(@PathParam("id") long userId) throws StorageException {
+ permissionsService.checkAdmin(getUserId());
+ User user = storage.getObject(User.class, new Request(
+ new Columns.All(), new Condition.Equals("id", "id", userId)));
+ request.getSession().setAttribute(USER_ID_KEY, user.getId());
+ LogAction.login(user.getId(), ServletHelper.retrieveRemoteAddress(request));
+ return user;
+ }
+
@PermitAll
@POST
public User add(