GUAC-1132: Add support for getRemoteHost() of ConnectionRecord. Store remote host within AuthenticatedUser.

This commit is contained in:
Michael Jumper
2015-03-17 15:13:32 -07:00
parent d0c57a2378
commit cd52b25b94
4 changed files with 43 additions and 4 deletions

View File

@@ -37,6 +37,14 @@
<dependencies> <dependencies>
<!-- Java servlet API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- Guacamole Extension API --> <!-- Guacamole Extension API -->
<dependency> <dependency>
<groupId>org.glyptodon.guacamole</groupId> <groupId>org.glyptodon.guacamole</groupId>

View File

@@ -69,8 +69,7 @@ public class ModeledConnectionRecord implements ConnectionRecord {
@Override @Override
public String getRemoteHost() { public String getRemoteHost() {
// STUB return null;
return "STUB";
} }
@Override @Override

View File

@@ -176,8 +176,7 @@ public class ActiveConnectionRecord implements ConnectionRecord {
@Override @Override
public String getRemoteHost() { public String getRemoteHost() {
// STUB return user.getRemoteHost();
return "STUB";
} }
@Override @Override

View File

@@ -22,6 +22,7 @@
package org.glyptodon.guacamole.auth.jdbc.user; package org.glyptodon.guacamole.auth.jdbc.user;
import javax.servlet.http.HttpServletRequest;
import org.glyptodon.guacamole.net.auth.Credentials; import org.glyptodon.guacamole.net.auth.Credentials;
/** /**
@@ -41,6 +42,27 @@ public class AuthenticatedUser {
*/ */
private final Credentials credentials; private final Credentials credentials;
/**
* The host from which this user authenticated.
*/
private final String remoteHost;
/**
* Derives the remote host of the authenticating user from the given
* credentials object.
*
* @param credentials
* The credentials to derive the remote host from.
*
* @return
* The remote host from which the user with the given credentials is
* authenticating.
*/
private static String getRemoteHost(Credentials credentials) {
HttpServletRequest request = credentials.getRequest();
return request.getRemoteAddr();
}
/** /**
* Creates a new AuthenticatedUser associating the given user with their * Creates a new AuthenticatedUser associating the given user with their
* corresponding credentials. * corresponding credentials.
@@ -54,6 +76,7 @@ public class AuthenticatedUser {
public AuthenticatedUser(ModeledUser user, Credentials credentials) { public AuthenticatedUser(ModeledUser user, Credentials credentials) {
this.user = user; this.user = user;
this.credentials = credentials; this.credentials = credentials;
this.remoteHost = getRemoteHost(credentials);
} }
/** /**
@@ -76,4 +99,14 @@ public class AuthenticatedUser {
return credentials; return credentials;
} }
/**
* Returns the host from which this user authenticated.
*
* @return
* The host from which this user authenticated.
*/
public String getRemoteHost() {
return remoteHost;
}
} }