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 {
* Return true if the lock has expired.
*/
public boolean hasExpired() {
return (System.currentTimeMillis() > expiresAt);
return (System.currentTimeMillis() > getExpiresAt());
}
/**
......
......@@ -29,7 +29,6 @@ import org.olat.core.util.vfs.NamedContainerImpl;
import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer;
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.filters.VFSItemFilter;
import org.olat.repository.RepositoryEntry;
......@@ -47,7 +46,6 @@ class CoursefolderWebDAVMergeSource extends MergeSource {
private final Identity identity;
private long loadTime;
public CoursefolderWebDAVMergeSource(Identity identity) {
super(null, null);
this.identity = identity;
......@@ -85,49 +83,34 @@ class CoursefolderWebDAVMergeSource extends MergeSource {
@Override
public List<VFSItem> getItems() {
if(!init) {
init();
}
checkInitialization();
return super.getItems();
}
@Override
public List<VFSItem> getItems(VFSItemFilter filter) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
}
checkInitialization();
return super.getItems(filter);
}
@Override
public VFSItem resolve(String path) {
if(init) {
return super.resolve(path);
}
path = VFSManager.sanitizePath(path);
if (path.equals("/")) {
return this;
}
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);
checkInitialization();
return super.resolve(path);
}
private void checkInitialization() {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
synchronized(this) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
}
}
}
return super.resolve(path);
}
@Override
protected void init() {
super.init();
RepositoryManager rm = RepositoryManager.getInstance();
List<RepositoryEntry> courseEntries = rm.queryByEditor(identity, CourseModule.getCourseTypeName());
List<VFSContainer> containers = new ArrayList<>();
......
......@@ -39,7 +39,6 @@ import org.olat.core.util.vfs.QuotaManager;
import org.olat.core.util.vfs.VFSConstants;
import org.olat.core.util.vfs.VFSContainer;
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.callbacks.FullAccessWithQuotaCallback;
import org.olat.core.util.vfs.callbacks.ReadOnlyCallback;
......@@ -91,60 +90,34 @@ class GroupfoldersWebDAVMergeSource extends MergeSource {
@Override
public List<VFSItem> getItems() {
if(!init) {
init();
}
checkInitialization();
return super.getItems();
}
@Override
public List<VFSItem> getItems(VFSItemFilter filter) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
}
checkInitialization();
return super.getItems(filter);
}
@Override
public VFSItem resolve(String path) {
if(init) {
return super.resolve(path);
}
path = VFSManager.sanitizePath(path);
if (path.equals("/")) {
return this;
}
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;
checkInitialization();
return super.resolve(path);
}
private void checkInitialization() {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
synchronized(this) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
}
}
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
protected void init() {
super.init();
// collect buddy groups
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
......
......@@ -27,7 +27,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.olat.core.commons.services.webdav.servlets.RequestUtil;
import org.olat.core.id.Identity;
import org.olat.core.id.Roles;
import org.olat.core.logging.OLog;
......@@ -35,7 +34,6 @@ import org.olat.core.logging.Tracing;
import org.olat.core.util.vfs.MergeSource;
import org.olat.core.util.vfs.VFSContainer;
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.fileresource.types.SharedFolderFileResource;
import org.olat.repository.RepositoryEntry;
......@@ -64,94 +62,34 @@ public class SharedFolderWebDAVMergeSource extends MergeSource {
@Override
public List<VFSItem> getItems() {
if(!init) {
init();
}
checkInitialization();
return super.getItems();
}
@Override
public List<VFSItem> getItems(VFSItemFilter filter) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
}
checkInitialization();
return super.getItems(filter);
}
@Override
public VFSItem resolve(String path) {
if(init) {
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);
}
}
}
}
checkInitialization();
return super.resolve(path);
}
private VFSContainer getSharedContainer(RepositoryEntry re, boolean readOnly) {
SharedFolderManager sfm = SharedFolderManager.getInstance();
VFSContainer shared = sfm.getNamedSharedFolder(re, true);
if(readOnly) {
shared.setLocalSecurityCallback(readOnlyCallback);
private void checkInitialization() {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
synchronized(this) {
if(!init || (System.currentTimeMillis() - loadTime) > 60000) {
init();
}
}
}
return shared;
}
@Override
protected void init() {
super.init();
SharedFolderManager sfm = SharedFolderManager.getInstance();
RepositoryManager repoManager = RepositoryManager.getInstance();
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