From 603175febca829b097f7b2016049eab2318985fa Mon Sep 17 00:00:00 2001 From: Abba Soungui YOUNOUSS Date: Tue, 11 Nov 2025 10:57:22 +0100 Subject: [PATCH] Allow to specify Wallix credentials in configuration file. This commit add 2 new parameters wallix-user-password and wallix-username-suffix, to allow formatting credentials before sending them to Wallix in order to automate authentication. Now when a connection is opened, the following crendentials will be used : Username : + Password : If wallix-username-suffix is not provided, the value ${GUAC_USERNAME} , which represent the username provided while login in to Guacamole will be used. If wallix-user-password is not set, password will be asked during connection otherwise, the provided password will be used for all connections. Guacamole tokens can be used as value, so if you set this parameter to ${GUAC_PASSWORD}, the password used to authenticate with Guacamole will be used to connect to Wallix and allow automatic authentication if both share the same authentication source. --- .../ext/wallix/sync/Configuration.java | 16 +++++++++++++++ .../guacamole/ext/wallix/sync/Wallix.java | 20 +++++++++++++++---- .../ext/wallix/sync/db/Connection.java | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Configuration.java b/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Configuration.java index 334db6d..2108cb2 100644 --- a/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Configuration.java +++ b/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Configuration.java @@ -94,6 +94,22 @@ public class Configuration { } }; + public static StringGuacamoleProperty WALLIX_USERNAME_SUFFIX = new StringGuacamoleProperty() { + + @Override + public String getName() { + return "wallix-username-suffix"; + } + }; + + public static StringGuacamoleProperty WALLIX_USER_PASSWORD = new StringGuacamoleProperty() { + + @Override + public String getName() { + return "wallix-user-password"; + } + }; + public static StringGuacamoleProperty WALLIX_CONNECTION_HOST = new StringGuacamoleProperty() { @Override diff --git a/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Wallix.java b/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Wallix.java index 250108b..5a06a5d 100644 --- a/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Wallix.java +++ b/src/main/java/cm/soungui/guacamole/ext/wallix/sync/Wallix.java @@ -38,7 +38,9 @@ public class Wallix { private final static String HEADER_AUTH_KEY = "X-Auth-Key"; - private final static String TOKEN_GUACAMOLE_USERNAME = "GUAC_USERNAME"; + private final static String TOKEN_GUACAMOLE_USERNAME = "{GUAC_USERNAME}"; + + private final static String TOKEN_GUACAMOLE_PASSWORD = "{GUAC_PASSWORD}"; private static Wallix INSTANCE; @@ -52,12 +54,18 @@ public class Wallix { private String connectionHost; + private String usernameSuffix; + + private String userPassword; + private Wallix() throws GuacamoleException { Environment environment = LocalEnvironment.getInstance(); url = environment.getRequiredProperty(Configuration.WALLIX_URL); user = environment.getRequiredProperty(Configuration.WALLIX_USER); authKey = environment.getRequiredProperty(Configuration.WALLIX_AUTH_KEY); usernamePrefix = environment.getRequiredProperty(Configuration.WALLIX_USERNAME_PREFIX); + usernameSuffix = environment.getProperty(Configuration.WALLIX_USERNAME_SUFFIX, TOKEN_GUACAMOLE_USERNAME); + userPassword = environment.getProperty(Configuration.WALLIX_USER_PASSWORD, TOKEN_GUACAMOLE_PASSWORD); connectionHost = environment.getRequiredProperty(Configuration.WALLIX_CONNECTION_HOST); } @@ -208,6 +216,7 @@ public class Wallix { Set list = new HashSet<>(); String usernamePrefix = Wallix.getInstance().usernamePrefix; + String usernameSuffix = Wallix.getInstance().usernameSuffix; String connectionHost = Wallix.getInstance().connectionHost; jsonNode.elements().forEachRemaining((e) -> { @@ -227,8 +236,11 @@ public class Wallix { connection.setGroup(group); connection.setProtocol(Connection.Protocol.valueOf(accountNode.findValue("service").textValue())); HashMap parameters = connection.getParameters(); - parameters.put(Connection.Parameter.USERNAME, getFormattedUsername(accountNode, group.getName(), usernamePrefix)); + parameters.put(Connection.Parameter.USERNAME, getFormattedUsername(accountNode, group.getName(), usernamePrefix + usernameSuffix)); parameters.put(Connection.Parameter.HOSTNAME, connectionHost); + if (userPassword != null) { + parameters.put(Connection.Parameter.PASSWORD, userPassword); + } StringBuffer connectionName = new StringBuffer(accountNode.findValue("account").asText()) .append("@").append(accountNode.findValue("device").asText()); connection.setName(connectionName.toString()); @@ -244,7 +256,7 @@ public class Wallix { return list; } - public static String getFormattedUsername(JsonNode accountNode, String targetGroupName, String usernamePrefix) { + public static String getFormattedUsername(JsonNode accountNode, String targetGroupName, String formattedUsername) { if (accountNode == null || targetGroupName == null || targetGroupName.isBlank()) { throw new IllegalArgumentException("Null object or empty string provided as argument"); } @@ -254,7 +266,7 @@ public class Wallix { buffer.append("@").append(accountNode.findValue("device").asText()); buffer.append(":").append(accountNode.findValue("service").asText()); buffer.append(":").append(targetGroupName); - buffer.append(":").append(usernamePrefix == null ? "" : usernamePrefix).append("${" + TOKEN_GUACAMOLE_USERNAME + "}"); + buffer.append(":").append(formattedUsername); return buffer.toString(); } diff --git a/src/main/java/cm/soungui/guacamole/ext/wallix/sync/db/Connection.java b/src/main/java/cm/soungui/guacamole/ext/wallix/sync/db/Connection.java index 7c092e5..3983c64 100644 --- a/src/main/java/cm/soungui/guacamole/ext/wallix/sync/db/Connection.java +++ b/src/main/java/cm/soungui/guacamole/ext/wallix/sync/db/Connection.java @@ -55,6 +55,7 @@ public class Connection { public static interface Parameter { String USERNAME = "username"; String HOSTNAME = "hostname"; + String PASSWORD = "password"; } @Override