You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/01/05 15:35:50 UTC

[4/6] guacamole-client git commit: GUACAMOLE-394: Add history endpoint at user level (analogous to Connection).

GUACAMOLE-394: Add history endpoint at user level (analogous to Connection).

Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/b8ce9c96
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/b8ce9c96
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/b8ce9c96

Branch: refs/heads/staging/0.9.14
Commit: b8ce9c96e712c7751eb7b2dc606c3f39c3945133
Parents: 2928472
Author: Michael Jumper <mj...@apache.org>
Authored: Mon Sep 11 18:39:32 2017 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Mon Dec 11 20:44:28 2017 -0800

----------------------------------------------------------------------
 .../guacamole/rest/user/UserResource.java       | 30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/b8ce9c96/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java b/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java
index 3f142ff..75a49db 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/user/UserResource.java
@@ -21,8 +21,11 @@ package org.apache.guacamole.rest.user;
 
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
+import java.util.ArrayList;
+import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -30,6 +33,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import org.apache.guacamole.GuacamoleException;
 import org.apache.guacamole.GuacamoleSecurityException;
+import org.apache.guacamole.net.auth.ActivityRecord;
 import org.apache.guacamole.net.auth.AuthenticationProvider;
 import org.apache.guacamole.net.auth.Credentials;
 import org.apache.guacamole.net.auth.User;
@@ -38,6 +42,7 @@ import org.apache.guacamole.net.auth.UserContext;
 import org.apache.guacamole.net.auth.credentials.GuacamoleCredentialsException;
 import org.apache.guacamole.rest.directory.DirectoryObjectResource;
 import org.apache.guacamole.rest.directory.DirectoryObjectTranslator;
+import org.apache.guacamole.rest.history.APIActivityRecord;
 import org.apache.guacamole.rest.permission.PermissionSetResource;
 
 /**
@@ -93,6 +98,31 @@ public class UserResource
         this.user = user;
     }
 
+    /**
+     * Retrieves the login (session) history of a single user.
+     *
+     * @return
+     *     A list of activity records, describing the start and end times of
+     *     this user's sessions.
+     *
+     * @throws GuacamoleException
+     *     If an error occurs while retrieving the user history.
+     */
+    @GET
+    @Path("history")
+    public List<APIActivityRecord> getUserHistory()
+            throws GuacamoleException {
+
+        // Retrieve the requested user's history
+        List<APIActivityRecord> apiRecords = new ArrayList<APIActivityRecord>();
+        for (ActivityRecord record : user.getHistory())
+            apiRecords.add(new APIActivityRecord(record));
+
+        // Return the converted history
+        return apiRecords;
+
+    }
+
     @Override
     public void updateObject(APIUser modifiedObject) throws GuacamoleException {