// TODO ??
}
// GET DECRYPTED ACL BEL & SEL
TokensResource tokenFile = new TokensResource(path);
TokenStruct token = tokenFile.getTokens(folderName);
String folderIdDB = token.getFolderIdDB();
String[] acls = tokenFile.getDecryptedACL(folderName,
OperationType.EDIT);
String aclBEL = acls[0];
String aclSEL = acls[1];
String acl;
String json = null;
String jsout;
String aesKeyBEL = tokenFile
.getAESKey(folderName, aclBEL, "BEL", false);
Response resp = client.sendAndWait(ClientPrimitives.OE_EDITPERM, path,
users, userId, aclSEL, aclBEL);
String newSEL = resp.getValue("newSel");
String addUser = resp.getValue("addUser");
String delUser = resp.getValue("delUser");
if (!"nochange".equals(newSEL)) {
Response tokenInfo = client.sendAndWait(
ClientPrimitives.OE_GET_TOKEN_INFO, path, userId);
String idToken = tokenInfo.getValue("idToken");
boolean hasMoreTokens = Boolean.valueOf(tokenInfo
.getValue("hasMoreTokens"));
acl = aclBEL;
while (hasMoreTokens) {
String tokenHBEL = client.sendAndWait(
ClientPrimitives.OE_CREATE_JSON_HBEL, path, userId)
.getValue("tokenHBEL");
// HBEL Tokens creation
FileSystemUtils.writePrivateFile("json.txt", tokenHBEL);
Executable exec = new Executable("wpes1_linux");
exec.add("h");
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/"
+ aesKeyBEL);
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/json.txt");
exec.add(acl);
exec.add(idToken);
exec.add(passphrase);
exec.run();
String jsonout = FileSystemUtils.readPrivateFile("jsonout.txt");
// Put new tokens HBEL in server DB
hasMoreTokens = Boolean.valueOf(client.sendAndWait(
ClientPrimitives.OE_PUT_TOKEN_HBEL, path, userId,
jsonout).getValue("hasMoreTokens"));
FileSystemUtils.deletePrivateFile("jsonout.txt");
}
// End HBEL tokens creation
FileSystemUtils.deletePrivateFiles();
// Update View Informations for added and deleted users
if (!addUser.isEmpty()) {
json = client.sendAndWait(ClientPrimitives.OE_VIEW_INFO, path,
userId, (userId + "-" + addUser), String.valueOf(true))
.getValue("json");
FileSystemUtils.writePrivateFile("json.txt", json);
Executable exec = new Executable("wpes1_linux");
exec.add("addID");
exec.add(folderIdDB);
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/json.txt");
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/jsonout.txt");
exec.add(passphrase);
exec.add(userId);
exec.run();
jsout = FileSystemUtils.readPrivateFile("jsonout.txt");
client.sendAndWait(ClientPrimitives.OE_SET_VIEW, path, jsout);
FileSystemUtils.deletePrivateFiles();
}
if (!delUser.isEmpty()) {
json = client.sendAndWait(ClientPrimitives.OE_VIEW_INFO, path,
userId, delUser, String.valueOf(true)).getValue("json");
FileSystemUtils.writePrivateFile("json.txt", json);
Executable exec = new Executable("wpes1_linux");
exec.add("remID");
exec.add(folderIdDB);
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/json.txt");
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/jsonout.txt");
exec.add(passphrase);
exec.run();
jsout = FileSystemUtils.readFile("jsonout.txt");
client.sendAndWait(ClientPrimitives.OE_SET_VIEW, path, jsout);
FileSystemUtils.deletePrivateFiles();
}
// If has SEL level decrypt and re-encrypt at SEL Level
client.sendAndWait(ClientPrimitives.OE_SEL_REQ, path, folderName,
folderIdDB, userId, users, aclSEL,
Boolean.toString(token.hasSEL()));
// Retrieve ViewInformations to encrypt acl to put into server db
String viewInfos = client.sendAndWait(
ClientPrimitives.OE_VIEW_INFO, path, userId, userId,
String.valueOf(true)).getValue("json");
FileSystemUtils.writePrivateFile("viewInfos.txt", viewInfos);
Executable exec = new Executable("wpes1_linux");
exec.add("eACLsel");
exec.add(folderIdDB);
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH
+ "/viewInfos.txt");
exec.add(passphrase);
exec.add("0-" + newSEL);
exec.add(Configuration.LOCAL_PRIVATE_RESOURCES_PATH + "/aclSEL.txt");
exec.run();
String newEncryptedAclSEL = FileSystemUtils
.readPrivateFile("aclSEL.txt");
// SAVE IN .tokens
// After a permission editing also delta-SEL resources has SEL
// encrypt level
tokenFile
.setEncryptedAcl(token.getFolderIdDB(), newEncryptedAclSEL);
// SAVE IN SERVER DB
client.sendAndWait(ClientPrimitives.OE_SAVE_NEW_SEL, path,
folderIdDB, newEncryptedAclSEL);
FileSystemUtils.deletePrivateFiles();