Utils.retrieveUserID(file.getPath());
} catch (NumberFormatException e) {
//Lock management
if(!file.getPath().contains("/Shared")){
if(file.getName().contains(".lock")){
return new PlainSimpleResource(lockResource(file, user, false));
}
}else if(file.getPath().contains("/Shared")){
File newFile = new File(retrieveRealFilePath(file.getAbsolutePath()));
if(file.getName().contains(".lock")){
return new PlainSimpleResource(lockResource(newFile, user, true));
}
}
}
//Unlock management
if (file.getName().contains(".unlock")) {
if (request.getMethod().equals(Method.OPTIONS)) {
if(!file.getPath().contains("/Shared")){
return new PlainSimpleResource(unlockResource(file, false));
}else if(file.getPath().contains("/Shared")){
File newFile = new File(retrieveRealFilePath(file.getAbsolutePath()));
return new PlainSimpleResource(unlockResource(newFile, true));
}else return null;
}else{
return null;
}
}
//Bypass only for OVER ENCRYPT REQUEST / RESPONSE CLIENT
LOGGER.debug("FILE '" + file.getPath() +"'EXISTS? " + file.exists());
if(!file.getPath().contains("/Shared") && file.exists()){
if(".request".equals(file.getName())){
LOGGER.debug(".request intercepted");
return new PlainSimpleResource(RequestManager.manageRequest(file, request, false));
}
if(".response".equals(file.getName())){
return new PlainSimpleResource(file);
}
}else if(file.getPath().contains("/Shared")){
File newFile = new File(retrieveRealFilePath(file.getAbsolutePath()));
if(newFile.exists()){
if(".request".equals(file.getName())){
LOGGER.debug(".request intercepted");
return new PlainSimpleResource(RequestManager.manageRequest(newFile, request, true));
}
if(".response".equals(file.getName())){
return new PlainSimpleResource(newFile);
}
}
}
if (".response".equals(file.getName()) && !file.exists() && request.getMethod().equals(Method.DELETE)) {
return null;
}
//TODO CHANGE USER-AGENT NAME IN CLIENT
if(headers.containsKey("user-agent")){
if(headers.get("user-agent").contains("Jakarta Commons-HttpClient")){
LOGGER.debug("user-agent - Jakarta Commons-Http client recognise!");
if(file.getPath().contains("/Shared")){
return resolveFileIfPermitted(host, file, false, false);
}else{
return resolveFileIfPermitted(host, file, true, true);
}
}
}
//Path control
//In this way, it happens only when the user is IN shared folder with some resources
if(file.getPath().contains("/Shared") && file.getPath().indexOf("/Shared/") == -1){
// 1. Special case: "Shared" folder
return resolveFileIfPermitted(host, file, false, false);
}else if(file.getPath().contains("/Shared") && doubleCheckOnShared(file.getPath())){
// 2. Case into shared folders (also 'username' folder, or their subtrees)
LOGGER.debug("INTO Shared folder with any files");
if(previousRequest == request.hashCode()){
LOGGER.debug("same request before");
if(permissionsUpdated){
LOGGER.debug("permissionsUpdated");
return resolveFileIfPermitted(host, file, false, false);
} else {
LOGGER.debug("permissions don't updated");
return null;
}
} else {
permissionsUpdated = false;
previousRequest = request.hashCode();
LOGGER.debug("previousRequest: " + previousRequest);
if(user != null && sharedUpdated.containsKey(user.getId()) && sharedUpdated.get(user.getId())){
LOGGER.debug("sharedUpdated containsKey(userId) and permissions are not deprecated");
LOGGER.debug("PERMISSION ALREADY UPDATE AND NOT DEPRECATED. LIST FILES");
permissionsUpdated = true;
return resolveFileIfPermitted(host, file, false, false);
}else{
//If the user that made request never update permissions or its permissions are out of date
LOGGER.debug("send update permissions request");
if(user == null)
LOGGER.error("Which way has it followed? It's called a webdav request without authorization inside (GET, PUT,...? ");
return new PlainSimpleResource(ServerUpdatePermissionsManager.sendUpdatePermissionsResponseForSharedFiles(file, user));
}
}
} else {
// 3. Not in shared folders, owner folders
LOGGER.debug("Not in /shared/ - user owned file");