Add connection parameter fetching from Wallix.
This commit is contained in:
@@ -85,4 +85,20 @@ public class Configuration {
|
|||||||
return "wallix-auth-key";
|
return "wallix-auth-key";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static StringGuacamoleProperty WALLIX_USERNAME_PREFIX = new StringGuacamoleProperty() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "wallix-username-prefix";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static StringGuacamoleProperty WALLIX_CONNECTION_HOST = new StringGuacamoleProperty() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "wallix-connection-host";
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
import cm.soungui.guacamole.ext.wallix.sync.db.Connection;
|
||||||
|
import cm.soungui.guacamole.ext.wallix.sync.db.TargetGroup;
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.User;
|
import cm.soungui.guacamole.ext.wallix.sync.db.User;
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.UserGroup;
|
import cm.soungui.guacamole.ext.wallix.sync.db.UserGroup;
|
||||||
|
|
||||||
@@ -42,11 +44,17 @@ public class Wallix {
|
|||||||
|
|
||||||
private String authKey;
|
private String authKey;
|
||||||
|
|
||||||
|
private String usernamePrefix;
|
||||||
|
|
||||||
|
private String connectionHost;
|
||||||
|
|
||||||
private Wallix() throws GuacamoleException {
|
private Wallix() throws GuacamoleException {
|
||||||
Environment environment = LocalEnvironment.getInstance();
|
Environment environment = LocalEnvironment.getInstance();
|
||||||
url = environment.getRequiredProperty(Configuration.WALLIX_URL);
|
url = environment.getRequiredProperty(Configuration.WALLIX_URL);
|
||||||
user = environment.getRequiredProperty(Configuration.WALLIX_USER);
|
user = environment.getRequiredProperty(Configuration.WALLIX_USER);
|
||||||
authKey = environment.getRequiredProperty(Configuration.WALLIX_AUTH_KEY);
|
authKey = environment.getRequiredProperty(Configuration.WALLIX_AUTH_KEY);
|
||||||
|
usernamePrefix = environment.getRequiredProperty(Configuration.WALLIX_USERNAME_PREFIX);
|
||||||
|
connectionHost = environment.getRequiredProperty(Configuration.WALLIX_CONNECTION_HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrustManager[] trustAllCerts = new X509ExtendedTrustManager[]{
|
TrustManager[] trustAllCerts = new X509ExtendedTrustManager[]{
|
||||||
@@ -136,9 +144,9 @@ public class Wallix {
|
|||||||
ObjectNode node = (ObjectNode) e;
|
ObjectNode node = (ObjectNode) e;
|
||||||
|
|
||||||
UserGroup group = new UserGroup();
|
UserGroup group = new UserGroup();
|
||||||
group.setName(node.findValue(Wallix.API.ATTRIBUTE_GROUP_NAME).asText());
|
group.setName(node.findValue(Wallix.API.ATTRIBUTE_USER_GROUP_NAME).asText());
|
||||||
|
|
||||||
List<JsonNode> membersList = node.findValues(Wallix.API.ATTRIBUTE_GROUP_USERS);
|
List<JsonNode> membersList = node.findValues(Wallix.API.ATTRIBUTE_USER_GROUP_USERS);
|
||||||
if (! membersList.isEmpty()) {
|
if (! membersList.isEmpty()) {
|
||||||
JsonNode usernames = membersList.get(0);
|
JsonNode usernames = membersList.get(0);
|
||||||
usernames.forEach(userNode -> {
|
usernames.forEach(userNode -> {
|
||||||
@@ -195,21 +203,32 @@ public class Wallix {
|
|||||||
JsonNode jsonNode = objectMapper.readTree(output);
|
JsonNode jsonNode = objectMapper.readTree(output);
|
||||||
Set<TargetGroup> list = new HashSet<>();
|
Set<TargetGroup> list = new HashSet<>();
|
||||||
|
|
||||||
|
String usernamePrefix = Wallix.getInstance().usernamePrefix;
|
||||||
|
String connectionHost = Wallix.getInstance().connectionHost;
|
||||||
|
|
||||||
jsonNode.elements().forEachRemaining((e) -> {
|
jsonNode.elements().forEachRemaining((e) -> {
|
||||||
ObjectNode node = (ObjectNode) e;
|
ObjectNode node = (ObjectNode) e;
|
||||||
|
|
||||||
TargetGroup group = new TargetGroup();
|
TargetGroup group = new TargetGroup();
|
||||||
group.setName(node.findValue(Wallix.API.ATTRIBUTE_GROUP_NAME).asText());
|
group.setName(node.findValue(Wallix.API.ATTRIBUTE_CONNECTION_GROUP_NAME).asText());
|
||||||
|
|
||||||
// List<JsonNode> membersList = node.findValues(Wallix.API.ATTRIBUTE_GROUP_USERS);
|
List<JsonNode> sessionsList = node.findValues(Wallix.API.ATTRIBUTE_CONNECTION_GROUP_SESSIONS);
|
||||||
// if (! membersList.isEmpty()) {
|
if (! sessionsList.isEmpty()) {
|
||||||
// JsonNode usernames = membersList.get(0);
|
JsonNode sessions = sessionsList.get(0);
|
||||||
// usernames.forEach(userNode -> {
|
sessions = sessions.findValue("accounts");
|
||||||
// User user = new User();
|
if (! sessions.isEmpty()) {
|
||||||
// user.setName(getNameWithoutDomain(userNode.textValue()));
|
sessions.forEach(accountNode -> {
|
||||||
// group.getMembers().add(user);
|
if (! accountNode.isEmpty()) {
|
||||||
// });
|
Connection connection = new Connection();
|
||||||
// }
|
connection.setGroup(group);
|
||||||
|
connection.setProtocol(Connection.Protocol.valueOf(accountNode.findValue("service").textValue()));
|
||||||
|
connection.getParameters().put(Connection.Parameter.USERNAME, getFormattedUsername(accountNode, group.getName(), usernamePrefix));
|
||||||
|
connection.getParameters().put(Connection.Parameter.HOSTNAME, connectionHost);
|
||||||
|
group.getConnections().add(connection);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
list.add(group);
|
list.add(group);
|
||||||
});
|
});
|
||||||
@@ -217,6 +236,21 @@ public class Wallix {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFormattedUsername(JsonNode accountNode, String targetGroupName, String usernamePrefix) {
|
||||||
|
if (accountNode == null || targetGroupName == null || targetGroupName.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Null object or empty string provided as argument");
|
||||||
|
}
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append(accountNode.findValue("account").asText());
|
||||||
|
buffer.append("@").append(accountNode.findValue("domain").asText());
|
||||||
|
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_USERNAME}");
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public final class API {
|
public final class API {
|
||||||
|
|
||||||
public static final String ATTRIBUTE_USER_DISABLED = "is_disabled";
|
public static final String ATTRIBUTE_USER_DISABLED = "is_disabled";
|
||||||
@@ -225,9 +259,13 @@ public class Wallix {
|
|||||||
|
|
||||||
public static final String ATTRIBUTE_USER_NAME = "user_name";
|
public static final String ATTRIBUTE_USER_NAME = "user_name";
|
||||||
|
|
||||||
public static final String ATTRIBUTE_GROUP_NAME = "group_name";
|
public static final String ATTRIBUTE_USER_GROUP_NAME = "group_name";
|
||||||
|
|
||||||
public static final String ATTRIBUTE_GROUP_USERS = "users";
|
public static final String ATTRIBUTE_USER_GROUP_USERS = "users";
|
||||||
|
|
||||||
|
public static final String ATTRIBUTE_CONNECTION_GROUP_NAME = "group_name";
|
||||||
|
|
||||||
|
public static final String ATTRIBUTE_CONNECTION_GROUP_SESSIONS = "session";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.apache.guacamole.GuacamoleException;
|
|||||||
import org.apache.guacamole.environment.LocalEnvironment;
|
import org.apache.guacamole.environment.LocalEnvironment;
|
||||||
|
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.DB;
|
import cm.soungui.guacamole.ext.wallix.sync.db.DB;
|
||||||
|
import cm.soungui.guacamole.ext.wallix.sync.db.TargetGroup;
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.User;
|
import cm.soungui.guacamole.ext.wallix.sync.db.User;
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.UserGroup;
|
import cm.soungui.guacamole.ext.wallix.sync.db.UserGroup;
|
||||||
|
|
||||||
@@ -118,21 +119,22 @@ public class WallixConfigSynchronizer implements Runnable {
|
|||||||
DB db = DB.getInstance();
|
DB db = DB.getInstance();
|
||||||
Set<TargetGroup> dbGroups = db.getTargetGroups();
|
Set<TargetGroup> dbGroups = db.getTargetGroups();
|
||||||
|
|
||||||
Set<TargetGroup> wallixGroups = Wallix.getInstance().getTargetGroups();
|
Set<TargetGroup> wallixTargetGroups = Wallix.getInstance().getTargetGroups();
|
||||||
|
|
||||||
for (TargetGroup group : wallixGroups) {
|
for (TargetGroup group : wallixTargetGroups) {
|
||||||
if (! dbGroups.contains(group)) {
|
if (! dbGroups.contains(group)) {
|
||||||
System.out.println("Adding target group " + group.getName());
|
System.out.println("Adding target group " + group.getName());
|
||||||
db.addTargetGroup(group);
|
db.addTargetGroup(group);
|
||||||
}
|
}
|
||||||
|
group.getConnections().forEach(connection -> System.out.println(connection.getParameters()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<TargetGroup> newDbGroups = db.getTargetGroups();
|
Set<TargetGroup> newDbGroups = db.getTargetGroups();
|
||||||
|
|
||||||
for (TargetGroup group : newDbGroups) {
|
for (TargetGroup group : newDbGroups) {
|
||||||
if (wallixGroups.contains(group)) {
|
if (wallixTargetGroups.contains(group)) {
|
||||||
for (TargetGroup wallixGroup : wallixGroups) {
|
for (TargetGroup wallixTargetGroup : wallixTargetGroups) {
|
||||||
if (group.equals(wallixGroup)) {
|
if (group.equals(wallixTargetGroup)) {
|
||||||
// db.updateGroupMembers(group, wallixGroup.getMembers());
|
// db.updateGroupMembers(group, wallixGroup.getMembers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package cm.soungui.guacamole.ext.wallix.sync.db;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Connection {
|
||||||
|
|
||||||
|
public enum Protocol { SSH, RDP, VNC };
|
||||||
|
|
||||||
|
private Protocol protocol;
|
||||||
|
|
||||||
|
private TargetGroup group;
|
||||||
|
|
||||||
|
private final HashMap<String, String> parameters = new HashMap<>();
|
||||||
|
|
||||||
|
public Protocol getProtocol() {
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProtocol(Protocol protocol) {
|
||||||
|
this.protocol = protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TargetGroup getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroup(TargetGroup group) {
|
||||||
|
this.group = group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, String> getParameters() {
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface Parameter {
|
||||||
|
String USERNAME = "username";
|
||||||
|
String HOSTNAME = "hostname";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,7 +14,6 @@ import org.apache.guacamole.environment.Environment;
|
|||||||
import org.apache.guacamole.environment.LocalEnvironment;
|
import org.apache.guacamole.environment.LocalEnvironment;
|
||||||
|
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.Configuration;
|
import cm.soungui.guacamole.ext.wallix.sync.Configuration;
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.TargetGroup;
|
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.Entity.EntityType;
|
import cm.soungui.guacamole.ext.wallix.sync.db.Entity.EntityType;
|
||||||
|
|
||||||
public class DB {
|
public class DB {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cm.soungui.guacamole.ext.wallix.sync;
|
package cm.soungui.guacamole.ext.wallix.sync.db;
|
||||||
|
|
||||||
import cm.soungui.guacamole.ext.wallix.sync.db.Entity;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TargetGroup {
|
public class TargetGroup {
|
||||||
|
|
||||||
@@ -8,6 +9,8 @@ public class TargetGroup {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
private final Set<Connection> connections = new HashSet<Connection>();
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -24,6 +27,10 @@ public class TargetGroup {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Connection> getConnections() {
|
||||||
|
return connections;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getName() == null ? super.hashCode() : getName().hashCode();
|
return getName() == null ? super.hashCode() : getName().hashCode();
|
||||||
Reference in New Issue
Block a user