Hi Nick & Mike,

So, some progress, and I'm also a bit confused by what I had to do to get
this to work. This is my custom connect() method, and the various calls to
get configuration information:

@Override
public GuacamoleTunnel connect(GuacamoleClientInformation info, Map<String,
String> tokens) throws GuacamoleException {

    tokens = new HashMap<>(tokens);
    GuacamoleTunnel tunnel = super.connect(info, tokens);
    UUID tunnelUUID = tunnel.getUUID();
    UserContext privilegedUserContext = userContext.getPrivileged();
    Directory<ActiveConnection> activeConnectionDirectory =
privilegedUserContext.getActiveConnectionDirectory();
    ActiveConnection activeConnection =
activeConnectionDirectory.get(tunnelUUID.toString());
    String connectionIdentifier =
activeConnection.getConnectionIdentifier();
    Directory<Connection> connectionDirectory =
privilegedUserContext.getConnectionDirectory();
    Connection connection = connectionDirectory.get(connectionIdentifier);
    GuacamoleConfiguration config = connection.getConfiguration();

    logger.info("********** [CustomUserContext] tunnel: {}", tunnel);
    logger.info("********** [CustomUserContext] tunnelUUID: {}",
tunnelUUID);
    logger.info("********** [CustomUserContext] privilegedUserContext: {}",
privilegedUserContext);
    logger.info("********** [CustomUserContext] activeConnectionDirectory:
{}", activeConnectionDirectory);
    logger.info("********** [CustomUserContext] activeConnection: {}",
activeConnection);
    logger.info("********** [CustomUserContext] connectionIdentifier: {}",
connectionIdentifier);
    logger.info("********** [CustomUserContext] connectionDirectory: {}",
connectionDirectory);
    logger.info("********** [CustomUserContext] connection: {}",
connection);
    logger.info("********** [CustomUserContext] config: {}", config);

    logger.info("********** [CustomUserContext]   config.getProtocol: {}",
config.getProtocol());
    logger.info("********** [CustomUserContext]   config.getParameterNames:
{}", config.getParameterNames());
    logger.info("********** [CustomUserContext]
config.getParameter(\"hostname\"): {}", config.getParameter("hostname"));

    return tunnel;
}

The logging output of all of that is:

********** [CustomUserContext] tunnel:
org.apache.guacamole.auth.jdbc.tunnel.ActiveConnectionRecord$2@60d7a730
********** [CustomUserContext] tunnelUUID:
7380abce-a220-36f5-a67b-b3272d2854ec
********** [CustomUserContext] privilegedUserContext:
org.apache.guacamole.auth.jdbc.user.ModeledUserContext@4ff5d3ff
********** [CustomUserContext] activeConnectionDirectory:
org.apache.guacamole.auth.jdbc.activeconnection.ActiveConnectionDirectory@1148447a
********** [CustomUserContext] activeConnection:
org.apache.guacamole.auth.jdbc.activeconnection.TrackedActiveConnection@754e2efa
********** [CustomUserContext] connectionIdentifier: 1
********** [CustomUserContext] connectionDirectory:
org.apache.guacamole.auth.jdbc.connection.ConnectionDirectory$$EnhancerByGuice$$2150384@287df944
********** [CustomUserContext] connection:
org.apache.guacamole.auth.jdbc.connection.ModeledConnection@49f6bd9f
********** [CustomUserContext] config:
org.apache.guacamole.auth.jdbc.connection.ModeledGuacamoleConfiguration@1a4e5b4f
********** [CustomUserContext]   config.getProtocol: rdp
********** [CustomUserContext]   config.getParameterNames: []
********** [CustomUserContext]   config.getParameter("hostname"): null

At this point I thought I was stuck—maybe the jdbc extension wasn't going
to expose what I needed. As one last ditch attempt, I tried this:

logger.info("********** [CustomUserContext]   config.getProtocol: {}",
config.getProtocol());
logger.info("********** [CustomUserContext]   config.getParameterNames:
{}", config.getParameterNames());
logger.info("********** [CustomUserContext]   config.getParameters: {}",
config.getParameters());
logger.info("********** [CustomUserContext]
config.getParameter(\"hostname\"): {}", config.getParameter("hostname"));

and now the output looks like this:

********** [CustomUserContext]   config.getProtocol: rdp
********** [CustomUserContext]   config.getParameterNames: []
********** [CustomUserContext]   config.getParameters:
{hostname=10.0.0.130, password=[snip], security=nla, ignore-cert=true,
port=3389, server-layout=en-gb-qwerty, enable-audio-input=true,
username=[snip]}
********** [CustomUserContext]   config.getParameter("hostname"): 10.0.0.130

so it seems I _can_ get the hostname, but only by calling getParameters()
before getParameter(). Looking at the source code for
ModeledGuacamoleConfiguration it seems like this is how it's supposed to
work, but I just wanted to check before relying on it.

Many thanks both for all your help and nudges in the right direction—I
think we finally have what we need :).

David

On Sun, 11 Aug 2024 at 19:56, David Lomas <d...@pale-eds.co.uk> wrote:

> Thanks Nick—that is correct. We hadn’t had any joy with the
> getConfiguration() method previously, but I haven’t tried it yet with the
> privileged user context. However, I suspect you know more about how that
> balancing connection group works and maybe we still won’t get what we need.
>
> It seems like the tunnel or socket ought to be able to tell us what they
> are connected too but they don’t have any methods for that
> either it seems.
>
> On Sun, 11 Aug 2024 at 19:27, Nick Couchman <vn...@apache.org> wrote:
>
>> On Fri, Aug 9, 2024 at 4:58 PM Michael Jumper <mjum...@apache.org> wrote:
>>
>>> You can pull connection configuration information, including the value
>>> of the "hostname" parameter, by obtaining a privileged UserContext,
>>> retrieving the relevant Connection object, and invoking
>>> getConfiguration() on that object:
>>>
>>>
>>> https://guacamole.apache.org/doc/guacamole-ext/org/apache/guacamole/net/auth/Connection.html#getConfiguration()
>>>
>>>
>> Ah, but the issue is a bit more complex than this. As I understand what
>> David is trying to do, he has a Connection Group fo type "Balancing", and,
>> within that Connection Group, several tens/dozens/hundreds of connections.
>> Either just before or just after a connection is used, or perhaps both,
>> he'd like to run a script or API or some set of tasks against the
>> connection that gets used. Since the connect() method that gets call is the
>> one for the Connection Group (which then goes and determines the actual
>> connection to use and connects the user), the challenge has been how to get
>> access to the connection information *of the connection that ends up being
>> chosen/used*, so that the code can be run against that specific connection
>> and not the connection group. Specifically, David would like to retrieve
>> the hostname of the connection item that is selected.
>>
>> -Nick
>>
>

Reply via email to