if(relativeToUserPath.equals(String.valueOf(userLoggedID)) || owneredFolders.contains(relativeToUserPath) ){
if(file.isDirectory())
return new OverEncryptedFolderResource(host, this, file, userLoggedID, true);
else
return new OverEncryptedFileResource(host, this, file, userLoggedID, true, false);
}else return null; //--> Unauthorized access
}else{
LOGGER.debug("mapsOfPermissions doesn't contain user logged id.");
permitted = false;
}
}else{
//Shared folder case
if(file.getAbsolutePath().endsWith("Shared")){
//Shared folder root
return new OverEncryptedSharedFolder(this, userLoggedID);
}else{
//Shared subfolders
//Retrieve owner folder id
int friendID = retrieveOwnerIDFromSharedFilePath(file.getAbsolutePath());
LOGGER.debug("friend id catch from shared file path: " + friendID);
//First check: the friend shared folder is a user's friend folder
if(mapOfPermissions.containsKey(friendID)){
String realPathSharedFile = retrieveRealFilePath(file.getAbsolutePath());
LOGGER.debug("realPathSharedFile: " +realPathSharedFile);
File sharedFile = new File(realPathSharedFile);
String halfPath = realPathSharedFile.replace(ServerConfiguration.getWebDAVrootPath(), "");
if(realPathSharedFile.endsWith("/" + friendID)){
//rootFolder
//friends folder es: "/67"
return new OverEncryptedFriendsFolder(this, "/" + friendID, friendID, userLoggedID);
}else if(mapOfPermissions.get(friendID).contains(halfPath)){
//If user has permissions into afterShared folder
if(sharedFile.isDirectory()){
return new OverEncryptedFriendsFolder(this, halfPath, friendID, userLoggedID);
}else{
//TODO non dovrebbe mai essere un file qui
return new OverEncryptedFriendsFile(this, halfPath, false);
}
}else if(!sharedFile.isDirectory()){
//TODO Miss a check for allows only files into allowed paths and tokens in parent path
return new OverEncryptedFriendsFile(this, halfPath, true);
}
}else{
LOGGER.debug("mapsOfFriendAndFiles doesn't contain friend id.");
permitted = false;
}
}
}
}
}else{
permitted = true;
}
if(permitted){
if( file.isDirectory() ) {
return new OverEncryptedFolderResource(host, this, file, userLoggedID, true);
} else {
if(file.getName().equals(".tokens") && !file.exists()) {
return null;
} else {
return new OverEncryptedFileResource(host, this, file, userLoggedID, true, bypass);
}
}
} else {
return null;
}