Move Wallix specific methods to Wallix class.
This commit is contained in:
@@ -8,6 +8,8 @@ import java.net.http.HttpResponse;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
@@ -18,6 +20,13 @@ import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.environment.Environment;
|
||||
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.User;
|
||||
import cm.soungui.guacamole.ext.wallix.sync.db.UserGroup;
|
||||
|
||||
public class Wallix {
|
||||
|
||||
private final static String HEADER_AUTH_USER = "X-Auth-User";
|
||||
@@ -110,6 +119,36 @@ public class Wallix {
|
||||
}
|
||||
}
|
||||
|
||||
public String getVersion() throws Exception {
|
||||
String output = get("/version");
|
||||
return output;
|
||||
}
|
||||
|
||||
public Set<UserGroup> getGroups() throws Exception {
|
||||
String output = get("/usergroups");
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(output);
|
||||
Set<UserGroup> list = new HashSet<>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public final class API {
|
||||
|
||||
public static final String ATTRIBUTE_GROUP_NAME = "group_name";
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package cm.soungui.guacamole.ext.wallix.sync;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
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 {
|
||||
@@ -43,7 +37,7 @@ public class WallixConfigSynchronizer implements Runnable {
|
||||
private void synchronizeGroups() throws Exception {
|
||||
System.out.println("Synchronizing groups");
|
||||
System.out.println("Getting Wallix groups");
|
||||
Set<UserGroup> wallixGroups = getWallixGroups();
|
||||
Set<UserGroup> wallixGroups = Wallix.getInstance().getGroups();
|
||||
|
||||
DB db = DB.getInstance();
|
||||
Set<UserGroup> dbGroups = db.getUserGroups();
|
||||
@@ -74,34 +68,7 @@ public class WallixConfigSynchronizer implements Runnable {
|
||||
|
||||
private void printWallixVersion() throws Exception {
|
||||
Wallix wallix = Wallix.getInstance();
|
||||
String output = wallix.get("/version");
|
||||
System.out.println(output);
|
||||
}
|
||||
|
||||
private Set<UserGroup> getWallixGroups() throws Exception {
|
||||
Wallix wallix = Wallix.getInstance();
|
||||
String output = wallix.get("/usergroups");
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNode = objectMapper.readTree(output);
|
||||
Set<UserGroup> list = new HashSet<>();
|
||||
|
||||
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;
|
||||
System.out.println(wallix.getVersion());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user