mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-47: Store remote address and hostname within Credentials.
This commit is contained in:
@@ -51,6 +51,19 @@ public class Credentials implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The address of the client end of the connection which provided these
|
||||||
|
* credentials, if known.
|
||||||
|
*/
|
||||||
|
private String remoteAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hostname or, if the hostname cannot be determined, the address of
|
||||||
|
* the client end of the connection which provided these credentials, if
|
||||||
|
* known.
|
||||||
|
*/
|
||||||
|
private String remoteHostname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The HttpServletRequest carrying additional credentials, if any.
|
* The HttpServletRequest carrying additional credentials, if any.
|
||||||
*/
|
*/
|
||||||
@@ -133,4 +146,56 @@ public class Credentials implements Serializable {
|
|||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the address of the client end of the connection which provided
|
||||||
|
* these credentials, if known.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The address of the client end of the connection which provided these
|
||||||
|
* credentials, or null if the address is not known.
|
||||||
|
*/
|
||||||
|
public String getRemoteAddress() {
|
||||||
|
return remoteAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the address of the client end of the connection which provided
|
||||||
|
* these credentials.
|
||||||
|
*
|
||||||
|
* @param remoteAddress
|
||||||
|
* The address of the client end of the connection which provided these
|
||||||
|
* credentials, or null if the address is not known.
|
||||||
|
*/
|
||||||
|
public void setRemoteAddress(String remoteAddress) {
|
||||||
|
this.remoteAddress = remoteAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hostname of the client end of the connection which provided
|
||||||
|
* these credentials, if known. If the hostname of the client cannot be
|
||||||
|
* determined, but the address is known, the address may be returned
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The hostname or address of the client end of the connection which
|
||||||
|
* provided these credentials, or null if the hostname is not known.
|
||||||
|
*/
|
||||||
|
public String getRemoteHostname() {
|
||||||
|
return remoteHostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the hostname of the client end of the connection which provided
|
||||||
|
* these credentials, if known. If the hostname of the client cannot be
|
||||||
|
* determined, but the address is known, the address may be specified
|
||||||
|
* instead.
|
||||||
|
*
|
||||||
|
* @param remoteHostname
|
||||||
|
* The hostname or address of the client end of the connection which
|
||||||
|
* provided these credentials, or null if the hostname is not known.
|
||||||
|
*/
|
||||||
|
public void setRemoteHostname(String remoteHostname) {
|
||||||
|
this.remoteHostname = remoteHostname;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,6 @@ package org.apache.guacamole.token;
|
|||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import org.apache.guacamole.net.auth.Credentials;
|
import org.apache.guacamole.net.auth.Credentials;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,12 +125,15 @@ 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
|
// Add client hostname token
|
||||||
HttpServletRequest request = credentials.getRequest();
|
String hostname = credentials.getRemoteHostname();
|
||||||
if (request != null) {
|
if (hostname != null)
|
||||||
filter.setToken(CLIENT_HOSTNAME_TOKEN, request.getRemoteHost());
|
filter.setToken(CLIENT_HOSTNAME_TOKEN, hostname);
|
||||||
filter.setToken(CLIENT_ADDRESS_TOKEN, request.getRemoteAddr());
|
|
||||||
}
|
// Add client address token
|
||||||
|
String address = credentials.getRemoteAddress();
|
||||||
|
if (address != null)
|
||||||
|
filter.setToken(CLIENT_ADDRESS_TOKEN, address);
|
||||||
|
|
||||||
// Add any tokens which do not require credentials
|
// Add any tokens which do not require credentials
|
||||||
addStandardTokens(filter);
|
addStandardTokens(filter);
|
||||||
|
@@ -125,6 +125,8 @@ public class TokenRESTService {
|
|||||||
credentials.setPassword(password);
|
credentials.setPassword(password);
|
||||||
credentials.setRequest(request);
|
credentials.setRequest(request);
|
||||||
credentials.setSession(request.getSession(true));
|
credentials.setSession(request.getSession(true));
|
||||||
|
credentials.setRemoteAddress(request.getRemoteAddr());
|
||||||
|
credentials.setRemoteHostname(request.getRemoteHost());
|
||||||
|
|
||||||
return credentials;
|
return credentials;
|
||||||
|
|
||||||
|
@@ -130,6 +130,8 @@ public class UserResource
|
|||||||
credentials.setPassword(userPasswordUpdate.getOldPassword());
|
credentials.setPassword(userPasswordUpdate.getOldPassword());
|
||||||
credentials.setRequest(request);
|
credentials.setRequest(request);
|
||||||
credentials.setSession(request.getSession(true));
|
credentials.setSession(request.getSession(true));
|
||||||
|
credentials.setRemoteAddress(request.getRemoteAddr());
|
||||||
|
credentials.setRemoteHostname(request.getRemoteHost());
|
||||||
|
|
||||||
// Verify that the old password was correct
|
// Verify that the old password was correct
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user