guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mjum...@apache.org
Subject [01/13] incubator-guacamole-client git commit: GUACAMOLE-47: Implement support for client hostname/IP token for connections.
Date Sat, 28 Jan 2017 18:52:12 GMT
Repository: incubator-guacamole-client
Updated Branches:
  refs/heads/master d8f9d26bd -> 0d6500396


GUACAMOLE-47: Implement support for client hostname/IP token for connections.


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

Branch: refs/heads/master
Commit: 797bb86a4390504ab02afed8bf544b44fbad1af0
Parents: d45580f
Author: Nick Couchman <nick.couchman@yahoo.com>
Authored: Fri Jan 6 19:24:50 2017 -0500
Committer: Nick Couchman <nick.couchman@yahoo.com>
Committed: Fri Jan 6 19:24:50 2017 -0500

----------------------------------------------------------------------
 .../apache/guacamole/token/StandardTokens.java  | 17 ++++++++
 .../org/apache/guacamole/rest/APIRequest.java   | 43 ++++++++++++++++++++
 2 files changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/797bb86a/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java
----------------------------------------------------------------------
diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java b/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java
index 8c4655a..4bf4221 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/token/StandardTokens.java
@@ -42,6 +42,16 @@ public class StandardTokens {
     public static final String PASSWORD_TOKEN = "GUAC_PASSWORD";
 
     /**
+     * The name of the client token added via addStandardTokens().
+     */
+    public static final String CLIENT_HOST_TOKEN = "GUAC_CLIENT_HOST";
+
+    /**
+     * The IP of the client token added via addStandardTokens().
+     */
+    public static final String CLIENT_IP_TOKEN = "GUAC_CLIENT_IP";
+
+    /**
      * The name of the date token (server-local time) added via
      * addStandardTokens().
      */
@@ -115,6 +125,13 @@ public class StandardTokens {
         if (password != null)
             filter.setToken(PASSWORD_TOKEN, password);
 
+        // Add client hostname and ip tokens
+        HttpServletRequest request = credentials.getRequest();
+        if (request != null) {
+            filter.setToken(CLIENT_HOST_TOKEN, request.getRemoteHost());
+            filter.setToken(CLIENT_IP_TOKEN, request.getRemoteAddr());
+        }
+
         // Add any tokens which do not require credentials
         addStandardTokens(filter);
 

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/797bb86a/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java b/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java
index 530b4dc..6a49c3e 100644
--- a/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java
+++ b/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java
@@ -42,6 +42,16 @@ public class APIRequest extends HttpServletRequestWrapper {
     private final Map<String, String[]> parameters;
 
     /**
+     * The remote hostname that initiated the request.
+     */
+    private final String remoteHost;
+
+    /**
+     * The remote ip address that initiated the request.
+     */
+    private final String remoteAddr;
+
+    /**
      * Wraps the given HttpServletRequest, using the given MultivaluedMap to
      * provide all request parameters. All HttpServletRequest functions which
      * do not deal with parameter names and values are delegated to the wrapped
@@ -58,6 +68,29 @@ public class APIRequest extends HttpServletRequestWrapper {
 
         super(request);
 
+        // Try a few methods to get client info.
+        String clientHostname = "";
+        String clientAddress = "";
+        if(request.getHeader("X-Guacamole-Client-Hostname") != "") {
+            this.remoteHost = request.getHeader("X-Guacamole-Client-Hostname");
+        } else if(request.getHeader("X-Forwarded-For") != "") {
+            this.remoteHost = request.getHeader("X-Forwarded-For");
+        } else if(request.getRemoteHost() != "") {
+            this.remoteHost = request.getRemoteHost();
+        } else {
+            this.remoteHost = "";
+        }
+
+        if(request.getHeader("X-Guacamole-Client-IP") != "") {
+            this.remoteAddr = request.getHeader("X-Guacamole-Client-IP");
+        } else if(request.getHeader("X-Forwarded-For") != "") {
+            this.remoteAddr = request.getHeader("X-Forwarded-For");
+        } else if(request.getRemoteAddr() != "") {
+            this.remoteAddr = request.getRemoteAddr();
+        } else {
+            this.remoteAddr = "";
+        }
+
         // Copy parameters from given MultivaluedMap 
         this.parameters = new HashMap<String, String[]>(parameters.size());
         for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
@@ -101,4 +134,14 @@ public class APIRequest extends HttpServletRequestWrapper {
 
     }
 
+    @Override
+    public String getRemoteHost() {
+        return this.remoteHost;
+    }
+
+    @Override
+    public String getRemoteAddr() {
+        return this.remoteAddr;
+    }
+
 }


Mime
View raw message