mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUACAMOLE-47: Merge support for GUAC_CLIENT_HOSTNAME and GUAC_CLIENT_ADDRESS parameter tokens.
This commit is contained in:
@@ -22,6 +22,7 @@ package org.apache.guacamole.token;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import org.apache.guacamole.net.auth.Credentials;
|
import org.apache.guacamole.net.auth.Credentials;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class which provides access to standardized token names, as well as
|
* 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";
|
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
|
* The name of the date token (server-local time) added via
|
||||||
* addStandardTokens().
|
* addStandardTokens().
|
||||||
@@ -115,6 +126,13 @@ public class StandardTokens {
|
|||||||
if (password != null)
|
if (password != null)
|
||||||
filter.setToken(PASSWORD_TOKEN, password);
|
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
|
// Add any tokens which do not require credentials
|
||||||
addStandardTokens(filter);
|
addStandardTokens(filter);
|
||||||
|
|
||||||
|
@@ -41,6 +41,16 @@ public class APIRequest extends HttpServletRequestWrapper {
|
|||||||
*/
|
*/
|
||||||
private final Map<String, String[]> parameters;
|
private final Map<String, String[]> 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
|
* Wraps the given HttpServletRequest, using the given MultivaluedMap to
|
||||||
* provide all request parameters. All HttpServletRequest functions which
|
* provide all request parameters. All HttpServletRequest functions which
|
||||||
@@ -58,6 +68,12 @@ public class APIRequest extends HttpServletRequestWrapper {
|
|||||||
|
|
||||||
super(request);
|
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
|
// Copy parameters from given MultivaluedMap
|
||||||
this.parameters = new HashMap<String, String[]>(parameters.size());
|
this.parameters = new HashMap<String, String[]>(parameters.size());
|
||||||
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
|
for (Map.Entry<String, List<String>> 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user