mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-47: Implement support for client hostname/IP token for connections.
This commit is contained in:
@@ -41,6 +41,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 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
|
* The name of the date token (server-local time) added via
|
||||||
* addStandardTokens().
|
* addStandardTokens().
|
||||||
@@ -115,6 +125,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(CLIENT_HOST_TOKEN, request.getRemoteHost());
|
||||||
|
filter.setToken(CLIENT_IP_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 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
|
* 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,29 @@ public class APIRequest extends HttpServletRequestWrapper {
|
|||||||
|
|
||||||
super(request);
|
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
|
// 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 +134,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