String acl;
String json = null;
String jsout;
boolean hasTokenHBELToCreate = false;
TokensResource tokenFile = new TokensResource(path);
TokenStruct token = tokenFile.getTokens(folderName);
String aesKeyBEL = ClientTokensManager.getAESKeyFromToken(path, token, aclBEL, "BEL", false, inpd);
LOGGER.debug("users: " + users);
LOGGER.debug("userId: " + userId);
LOGGER.debug("aclSEL: " + aclSEL);
LOGGER.debug("aclBEL: " + aclBEL);
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "debug");
if(EditManager.setEditPermission(path, users, userId, aclSEL, aclBEL)) {
returnValues = ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_RETURN_EDITPERM, "newSEL", "addUser", "delUser");
newSEL = returnValues[0];
addUser = returnValues[1];
delUser = returnValues[2];
}
if(!"nochange".equals(newSEL)) {
if(EditManager.getTokenInfo(path, userId)) {
returnValues = ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_TOKEN_INFO, "idToken", "hasMoreTokens");
idToken = returnValues[0];
hasTokenHBELToCreate = Boolean.valueOf(returnValues[1]);
}
LOGGER.debug("idToken: " + idToken);
LOGGER.debug("hasTokenHBELToCreate: " + hasTokenHBELToCreate);
LOGGER.debug("addUser: " + addUser);
LOGGER.debug("delUser: " + delUser);
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "debug2");
acl = aclBEL;
while(hasTokenHBELToCreate) {
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "hasTokenHBELtoCreate!");
String tokenHBEL = "";
if(EditManager.createJsonHBEL(path, userId)) {
tokenHBEL = ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_JSON_HBEL, "tokenHBEL")[0];
}
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "tokenHBEL: " + tokenHBEL);
//HBEL Tokens creation
FileSystemUtils.writePrivateFile("json.txt", tokenHBEL);
String command[] = {
ClientConfiguration.getEXECUTABLES_PATH() + "/wpes1_linux",
"h",
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/" + aesKeyBEL,
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/json.txt",
acl,
idToken,
passphrase
};
RunnerExecutables.execute(command);
String jsonout = FileSystemUtils.readPrivateFile("jsonout.txt");
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "Ora inserisce i token HBEL nel DB in tokentableencrypt. Controlla jsonout.txt per vedere cosa contiene");
//Put new tokens HBEL in server DB
if(EditManager.putToken(path, userId, jsonout)) {
hasTokenHBELToCreate = Boolean.valueOf(ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_TOKEN_INFO, "hasMoreTokens")[0]);
}
LOGGER.debug("hasTokenHBELToCreate: " + hasTokenHBELToCreate);
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "debug3");
FileSystemUtils.deletePrivateFile("jsonout.txt");
}
//End HBEL tokens creation
inpd.setMessage("HBEL tokens generated");
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "HBEL tokens generated");
FileSystemUtils.deletePrivateFile();
//Update View Informations for added and deleted users
if(!addUser.isEmpty()) {
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "addUser process start");
if(EditManager.getView(path, userId, userId + "-" + addUser, true)) {
json = ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_GET_VIEW, "json")[0];
}
FileSystemUtils.writePrivateFile("json.txt", json);
LOGGER.debug("json: " + json);
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "debug");
String command[] = {
ClientConfiguration.getEXECUTABLES_PATH() + "/wpes1_linux",
"addID",
folderIdDB,
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/json.txt",
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/jsonout.txt",
passphrase,
userId
};
RunnerExecutables.execute(command);
jsout = FileSystemUtils.readPrivateFile("jsonout.txt");
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "leggi jsonout per vedere cosa inserirà in ViewInformations");
if(EditManager.setView(userId, path, jsout)) {
ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_SUCCESSFUL);
}
FileSystemUtils.deletePrivateFile();
}
if(!delUser.isEmpty()) {
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "delUser process start");
if(EditManager.getView(path, userId, delUser, true)) {
json = ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_GET_VIEW, "json")[0];
}
FileSystemUtils.writePrivateFile("json.txt", json);
LOGGER.debug("json: " + json);
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "debug");
String command[] = {
ClientConfiguration.getEXECUTABLES_PATH() + "/wpes1_linux",
"remID",
folderIdDB,
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/json.txt",
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/jsonout.txt",
passphrase,
};
RunnerExecutables.execute(command);
jsout = FileSystemUtils.readFile("jsonout.txt");
if(ClientConfiguration.debug)
JOptionPane.showMessageDialog(null, "leggi jsonout per vedere cosa inserirà in ViewInformations");
if(EditManager.setView(userId, path, jsout)) {
ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_SUCCESSFUL);
}
FileSystemUtils.deletePrivateFile();
}
//If has SEL level decrypt and re-encrypt at SEL Level
if(EditManager.selRequest(path, folderName, folderIdDB, userId, users, aclSEL, Boolean.toString(token.hasSEL))) {
ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_SUCCESSFUL);
}
//Retrieve ViewInformations to encrypt acl to put into server db
String viewInfos = "";
if(EditManager.getView(path, userId, userId, true)) {
viewInfos = ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_GET_VIEW, "json")[0];
}
FileSystemUtils.writePrivateFile("viewInfos.txt", viewInfos);
//run wpes1
String command[] = {
ClientConfiguration.getEXECUTABLES_PATH() + "/wpes1_linux",
"eACLsel",
folderIdDB,
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/viewInfos.txt",
passphrase,
"0-" + newSEL,
ClientConfiguration.getLOCAL_PRIVATE_RESOURCES_PATH() + "/aclSEL.txt"
};
RunnerExecutables.execute(command);
String newCryptedAclSEL = FileSystemUtils.readPrivateFile("aclSEL.txt");
//SAVE IN .tokens
//After a permission editing also delta-SEL resources has SEL encrypt level
tokenFile.editCryptedAcl(token.folderIdDB, newCryptedAclSEL);
LOGGER.debug("New acl SEL saved in .tokens file");
//SAVE IN SERVER DB
if(EditManager.saveNewSEL(userId, path,folderIdDB,newCryptedAclSEL)){
ResponseManager.retrieveCommunication(path, ServerPrimitives.OE_SUCCESSFUL);