Implements group fetching from Wallix.
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -43,5 +43,12 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.17.0</version> <!-- Use the latest stable version -->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -20,12 +20,12 @@ import org.apache.guacamole.environment.LocalEnvironment;
|
||||
|
||||
public class Wallix {
|
||||
|
||||
private final static String HEADER_AUTH_USER = "X-Auth-User";
|
||||
|
||||
private final static String HEADER_AUTH_KEY = "X-Auth-Key";
|
||||
|
||||
private static Wallix INSTANCE;
|
||||
|
||||
private static String HEADER_AUTH_USER = "X-Auth-User";
|
||||
|
||||
private static String HEADER_AUTH_KEY = "X-Auth-Key";
|
||||
|
||||
private String url;
|
||||
|
||||
private String user;
|
||||
@@ -110,4 +110,12 @@ public class Wallix {
|
||||
}
|
||||
}
|
||||
|
||||
public final class API {
|
||||
|
||||
public static final String ATTRIBUTE_GROUP_NAME = "group_name";
|
||||
|
||||
public static final String ATTRIBUTE_GROUP_USERS = "users";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package cm.soungui.guacamole.ext.wallix.sync;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.environment.LocalEnvironment;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import cm.soungui.guacamole.ext.wallix.sync.db.DB;
|
||||
import cm.soungui.guacamole.ext.wallix.sync.db.User;
|
||||
import cm.soungui.guacamole.ext.wallix.sync.db.UserGroup;
|
||||
|
||||
public class WallixConfigSynchronizer implements Runnable {
|
||||
@@ -36,11 +42,13 @@ public class WallixConfigSynchronizer implements Runnable {
|
||||
System.out.println("Synchronizing groups");
|
||||
System.out.println("Getting Wallix groups");
|
||||
printWallixVersion();
|
||||
getWallixGroups();
|
||||
List<UserGroup> wallixGroups = getWallixGroups();
|
||||
System.out.println("Wallix Groups");
|
||||
wallixGroups.forEach(group -> System.out.println(group.getName()));
|
||||
|
||||
DB db = DB.getInstance();
|
||||
List<UserGroup> groups = db.getUserGroups();
|
||||
for (UserGroup group : groups) {
|
||||
List<UserGroup> dbGroups = db.getUserGroups();
|
||||
for (UserGroup group : dbGroups) {
|
||||
System.out.println("ID : " + group.getId() + " - Name : " + group.getName());
|
||||
}
|
||||
}
|
||||
@@ -51,10 +59,30 @@ public class WallixConfigSynchronizer implements Runnable {
|
||||
System.out.println(output);
|
||||
}
|
||||
|
||||
private void getWallixGroups() throws Exception {
|
||||
private List<UserGroup> getWallixGroups() throws Exception {
|
||||
Wallix wallix = Wallix.getInstance();
|
||||
String output = wallix.get("/usergroups");
|
||||
System.out.println(output);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(output);
|
||||
List<UserGroup> list = new ArrayList<>();
|
||||
|
||||
jsonNode.elements().forEachRemaining((e) -> {
|
||||
ObjectNode node = (ObjectNode) e;
|
||||
|
||||
UserGroup group = new UserGroup();
|
||||
group.setName(node.findValue(Wallix.API.ATTRIBUTE_GROUP_NAME).asText());
|
||||
|
||||
node.findValues(Wallix.API.ATTRIBUTE_GROUP_USERS).forEach(userNode -> {
|
||||
User user = new User();
|
||||
user.setName(userNode.textValue());
|
||||
group.getMembers().add(user);
|
||||
});
|
||||
|
||||
list.add(group);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package cm.soungui.guacamole.ext.wallix.sync.db;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class UserGroup extends Entity {
|
||||
|
||||
private int groupId;
|
||||
|
||||
private List<Entity> members = new ArrayList<>();
|
||||
private Set<Entity> members = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public EntityType getType() {
|
||||
return EntityType.GROUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(EntityType type) {
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
@@ -22,7 +26,7 @@ public class UserGroup extends Entity {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public List<Entity> getMembers() {
|
||||
public Set<Entity> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user