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 8c4655ac4..9cb1f4137 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 @@ -22,6 +22,7 @@ package org.apache.guacamole.token; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.guacamole.net.auth.Credentials; +import javax.servlet.http.HttpServletRequest; /** * Utility class which provides access to standardized token names, as well as @@ -41,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 REMHOST_TOKEN = "GUAC_CLIENT_HOSTNAME"; + + /** + * The IP of the client token added via addStandardTokens(). + */ + public static final String REMIP_TOKEN = "GUAC_CLIENT_ADDRESS"; + /** * The name of the date token (server-local time) added via * addStandardTokens(). @@ -115,6 +126,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(REMHOST_TOKEN, request.getRemoteHost()); + filter.setToken(REMIP_TOKEN, request.getRemoteAddr()); + } + // Add any tokens which do not require credentials addStandardTokens(filter); 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 530b4dc74..9044b24ad 100644 --- a/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java +++ b/guacamole/src/main/java/org/apache/guacamole/rest/APIRequest.java @@ -41,6 +41,16 @@ public class APIRequest extends HttpServletRequestWrapper { */ private final Map parameters; + /** + * The hostname of the client that initiated the request. + */ + private final String remoteHost; + + /** + * The ip address of the client 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 @@ -58,6 +68,12 @@ public class APIRequest extends HttpServletRequestWrapper { super(request); + // Grab the remote host info + this.remoteHost = request.getRemoteHost(); + + // Grab the remote ip info + this.remoteAddr = request.getRemoteAddr(); + // Copy parameters from given MultivaluedMap this.parameters = new HashMap(parameters.size()); for (Map.Entry> entry : parameters.entrySet()) { @@ -101,4 +117,14 @@ public class APIRequest extends HttpServletRequestWrapper { } + @Override + public String getRemoteHost() { + return this.remoteHost; + } + + @Override + public String getRemoteAddr() { + return this.remoteAddr; + } + }