Skip to content
Snippets Groups Projects
Commit 19b37335 authored by srosse's avatar srosse
Browse files

OO-1069: fix expiration date for VFS lock, hardened the init method of the different merged folders

parent 78938b04
No related branches found
No related tags found
No related merge requests found
...@@ -162,7 +162,7 @@ public class LockInfo { ...@@ -162,7 +162,7 @@ public class LockInfo {
* Return true if the lock has expired. * Return true if the lock has expired.
*/ */
public boolean hasExpired() { public boolean hasExpired() {
return (System.currentTimeMillis() > expiresAt); return (System.currentTimeMillis() > getExpiresAt());
} }
/** /**
......
...@@ -29,7 +29,6 @@ import org.olat.core.util.vfs.NamedContainerImpl; ...@@ -29,7 +29,6 @@ import org.olat.core.util.vfs.NamedContainerImpl;
import org.olat.core.util.vfs.VFSConstants; import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.VFSStatus; import org.olat.core.util.vfs.VFSStatus;
import org.olat.core.util.vfs.filters.VFSItemFilter; import org.olat.core.util.vfs.filters.VFSItemFilter;
import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntry;
...@@ -47,7 +46,6 @@ class CoursefolderWebDAVMergeSource extends MergeSource { ...@@ -47,7 +46,6 @@ class CoursefolderWebDAVMergeSource extends MergeSource {
private final Identity identity; private final Identity identity;
private long loadTime; private long loadTime;
public CoursefolderWebDAVMergeSource(Identity identity) { public CoursefolderWebDAVMergeSource(Identity identity) {
super(null, null); super(null, null);
this.identity = identity; this.identity = identity;
...@@ -85,49 +83,34 @@ class CoursefolderWebDAVMergeSource extends MergeSource { ...@@ -85,49 +83,34 @@ class CoursefolderWebDAVMergeSource extends MergeSource {
@Override @Override
public List<VFSItem> getItems() { public List<VFSItem> getItems() {
if(!init) { checkInitialization();
init();
}
return super.getItems(); return super.getItems();
} }
@Override @Override
public List<VFSItem> getItems(VFSItemFilter filter) { public List<VFSItem> getItems(VFSItemFilter filter) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) { checkInitialization();
init();
}
return super.getItems(filter); return super.getItems(filter);
} }
@Override @Override
public VFSItem resolve(String path) { public VFSItem resolve(String path) {
if(init) { checkInitialization();
return super.resolve(path); return super.resolve(path);
} }
path = VFSManager.sanitizePath(path); private void checkInitialization() {
if (path.equals("/")) { if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
return this; synchronized(this) {
} if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
String childName = VFSManager.extractChild(path); }
RepositoryManager rm = RepositoryManager.getInstance();
List<RepositoryEntry> entries = rm.queryByEditor(identity, CourseModule.getCourseTypeName());
for(RepositoryEntry entry:entries) {
String courseTitle = RequestUtil.normalizeFilename(entry.getDisplayname());
if(childName.equals(courseTitle)) {
NamedContainerImpl cfContainer = new CoursefolderWebDAVNamedContainer(childName, entry.getOlatResource());
String nextPath = path.substring(childName.length() + 1);
return cfContainer.resolve(nextPath);
} }
} }
return super.resolve(path);
} }
@Override @Override
protected void init() { protected void init() {
super.init();
RepositoryManager rm = RepositoryManager.getInstance(); RepositoryManager rm = RepositoryManager.getInstance();
List<RepositoryEntry> courseEntries = rm.queryByEditor(identity, CourseModule.getCourseTypeName()); List<RepositoryEntry> courseEntries = rm.queryByEditor(identity, CourseModule.getCourseTypeName());
List<VFSContainer> containers = new ArrayList<>(); List<VFSContainer> containers = new ArrayList<>();
......
...@@ -39,7 +39,6 @@ import org.olat.core.util.vfs.QuotaManager; ...@@ -39,7 +39,6 @@ import org.olat.core.util.vfs.QuotaManager;
import org.olat.core.util.vfs.VFSConstants; import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.VFSStatus; import org.olat.core.util.vfs.VFSStatus;
import org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback; import org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback;
import org.olat.core.util.vfs.callbacks.ReadOnlyCallback; import org.olat.core.util.vfs.callbacks.ReadOnlyCallback;
...@@ -91,60 +90,34 @@ class GroupfoldersWebDAVMergeSource extends MergeSource { ...@@ -91,60 +90,34 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
@Override @Override
public List<VFSItem> getItems() { public List<VFSItem> getItems() {
if(!init) { checkInitialization();
init();
}
return super.getItems(); return super.getItems();
} }
@Override @Override
public List<VFSItem> getItems(VFSItemFilter filter) { public List<VFSItem> getItems(VFSItemFilter filter) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) { checkInitialization();
init();
}
return super.getItems(filter); return super.getItems(filter);
} }
@Override @Override
public VFSItem resolve(String path) { public VFSItem resolve(String path) {
if(init) { checkInitialization();
return super.resolve(path); return super.resolve(path);
} }
path = VFSManager.sanitizePath(path); private void checkInitialization() {
if (path.equals("/")) { if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
return this; synchronized(this) {
} if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
String childName = VFSManager.extractChild(path); }
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, true);
params.addTools(CollaborationTools.TOOL_FOLDER);
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
Set<String> addedGroupNames = new HashSet<String>();
for(BusinessGroup group:groups) {
String name = nameIdentifier(group, addedGroupNames);
if(name == null) {
continue;
} }
name = RequestUtil.normalizeFilename(name);
if(childName.equals(name)) {
String nextPath = path.substring(childName.length() + 1);
VFSContainer grpContainer = getGroupContainer(name, group, false);
VFSItem item = grpContainer.resolve(nextPath);
return item;
}
} }
return super.resolve(path);
} }
@Override @Override
protected void init() { protected void init() {
super.init();
// collect buddy groups // collect buddy groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class); BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
......
...@@ -27,7 +27,6 @@ import java.util.HashSet; ...@@ -27,7 +27,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.olat.core.commons.services.webdav.servlets.RequestUtil;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.Roles; import org.olat.core.id.Roles;
import org.olat.core.logging.OLog; import org.olat.core.logging.OLog;
...@@ -35,7 +34,6 @@ import org.olat.core.logging.Tracing; ...@@ -35,7 +34,6 @@ import org.olat.core.logging.Tracing;
import org.olat.core.util.vfs.MergeSource; import org.olat.core.util.vfs.MergeSource;
import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSItem;
import org.olat.core.util.vfs.VFSManager;
import org.olat.core.util.vfs.filters.VFSItemFilter; import org.olat.core.util.vfs.filters.VFSItemFilter;
import org.olat.fileresource.types.SharedFolderFileResource; import org.olat.fileresource.types.SharedFolderFileResource;
import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntry;
...@@ -64,94 +62,34 @@ public class SharedFolderWebDAVMergeSource extends MergeSource { ...@@ -64,94 +62,34 @@ public class SharedFolderWebDAVMergeSource extends MergeSource {
@Override @Override
public List<VFSItem> getItems() { public List<VFSItem> getItems() {
if(!init) { checkInitialization();
init();
}
return super.getItems(); return super.getItems();
} }
@Override @Override
public List<VFSItem> getItems(VFSItemFilter filter) { public List<VFSItem> getItems(VFSItemFilter filter) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) { checkInitialization();
init();
}
return super.getItems(filter); return super.getItems(filter);
} }
@Override @Override
public VFSItem resolve(String path) { public VFSItem resolve(String path) {
if(init) { checkInitialization();
return super.resolve(path);
}
path = VFSManager.sanitizePath(path);
if (path.equals("/")) {
return this;
}
String childName = VFSManager.extractChild(path);
RepositoryManager repoManager = RepositoryManager.getInstance();
//lookup in my shared folders
List<RepositoryEntry> ownerEntries = repoManager.queryByOwner(identity, SharedFolderFileResource.TYPE_NAME);
for (RepositoryEntry re : ownerEntries) {
String name = RequestUtil.normalizeFilename(re.getDisplayname());
if(childName.equals(name)) {
VFSContainer shared = getSharedContainer(re, false);
String nextPath = path.substring(childName.length() + 1);
return shared.resolve(nextPath);
}
}
if (publiclyReadableFolders != null && publiclyReadableFolders.size() > 0) {
String firstItem = publiclyReadableFolders.get(0);
// If the first value in the list is '*', list all resource folders.
if (firstItem != null && firstItem.equals("*")) {
// fake role that represents normally logged in user
Roles registeredUserRole = new Roles(false, false, false, false, false, false, false);
List<String> types = Collections.singletonList(SharedFolderFileResource.TYPE_NAME);
List<RepositoryEntry> allEntries = repoManager.queryByTypeLimitAccess(identity, types, registeredUserRole);
for (RepositoryEntry re : allEntries) {
String name = RequestUtil.normalizeFilename(re.getDisplayname());
if(childName.equals(name)) {
VFSContainer shared = getSharedContainer(re, true);
String nextPath = path.substring(childName.length() + 1);
return shared.resolve(nextPath);
}
}
} else {
// only list the specified folders
List<Long> publiclyReadableFoldersKeys = getSharedKeys();
List<RepositoryEntry> entries = repoManager.lookupRepositoryEntries(publiclyReadableFoldersKeys);
for (RepositoryEntry re:entries) {
String name = RequestUtil.normalizeFilename(re.getDisplayname());
if (childName.equals(name) &&
(re.getAccess() >= RepositoryEntry.ACC_USERS || (re.getAccess() == RepositoryEntry.ACC_OWNERS && re.isMembersOnly()))) {
VFSContainer shared = getSharedContainer(re, true);
String nextPath = path.substring(childName.length() + 1);
return shared.resolve(nextPath);
}
}
}
}
return super.resolve(path); return super.resolve(path);
} }
private VFSContainer getSharedContainer(RepositoryEntry re, boolean readOnly) { private void checkInitialization() {
SharedFolderManager sfm = SharedFolderManager.getInstance(); if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
VFSContainer shared = sfm.getNamedSharedFolder(re, true); synchronized(this) {
if(readOnly) { if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
shared.setLocalSecurityCallback(readOnlyCallback); init();
}
}
} }
return shared;
} }
@Override @Override
protected void init() { protected void init() {
super.init();
SharedFolderManager sfm = SharedFolderManager.getInstance(); SharedFolderManager sfm = SharedFolderManager.getInstance();
RepositoryManager repoManager = RepositoryManager.getInstance(); RepositoryManager repoManager = RepositoryManager.getInstance();
List<VFSContainer> containers = new ArrayList<>(); List<VFSContainer> containers = new ArrayList<>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment