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 : <wallix-username-prefix>+<wallix-username-suffix>
Password : <wallix-user-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.
This commit is contained in:
2025-11-11 10:57:22 +01:00
parent 5edafc44bb
commit 603175febc
3 changed files with 33 additions and 4 deletions

View File

@@ -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

View File

@@ -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<TargetGroup> 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<String, String> 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();
}

View File

@@ -55,6 +55,7 @@ public class Connection {
public static interface Parameter {
String USERNAME = "username";
String HOSTNAME = "hostname";
String PASSWORD = "password";
}
@Override