Skip to content
Snippets Groups Projects
Commit 9f22d28a authored by srosse's avatar srosse
Browse files

OO-1352: better control of access, add unit tests for the WebDAV access

parent 4d29ee8b
No related branches found
No related tags found
No related merge requests found
Showing with 94 additions and 7 deletions
......@@ -68,6 +68,11 @@ public class CustomStaticFolderManager implements InitializingBean, WebDAVProvid
public String getMountPoint() {
return MOUNT_POINT;
}
@Override
public boolean hasAccess(IdentityEnvironment identityEnv) {
return identityEnv != null && identityEnv.getRoles() != null && identityEnv.getRoles().isOLATAdmin();
}
@Override
public VFSContainer getContainer(IdentityEnvironment identityEnv) {
......
......@@ -38,6 +38,12 @@ public class CalendarWebDAVProvider implements WebDAVProvider {
private static final String MOUNT_POINT = "calendars";
@Override
public boolean hasAccess(IdentityEnvironment identityEnv) {
return identityEnv != null;
}
@Override
public VFSContainer getContainer(IdentityEnvironment identityEnv) {
VirtualContainer calendars = new VirtualContainer("calendars");
calendars.setLocalSecurityCallback(new ReadOnlyCallback());
......@@ -48,8 +54,8 @@ public class CalendarWebDAVProvider implements WebDAVProvider {
return calendars;
}
@Override
public String getMountPoint() {
return MOUNT_POINT;
}
}
}
\ No newline at end of file
......@@ -36,7 +36,8 @@ import org.olat.core.util.vfs.VFSContainer;
public class BriefcaseWebDAVProvider implements WebDAVProvider {
private static final String MOUNTPOINT = "home";
@Override
public String getMountPoint() {
return MOUNTPOINT;
}
......@@ -46,6 +47,11 @@ public class BriefcaseWebDAVProvider implements WebDAVProvider {
return new BriefcaseWebDAVMergeSource(identity);
}
@Override
public boolean hasAccess(IdentityEnvironment identityEnv) {
return identityEnv != null;
}
/**
* @see org.olat.core.commons.services.webdav.WebDAVProvider#getContainer(org.olat.core.id.Identity)
*/
......
......@@ -30,6 +30,8 @@ import org.olat.core.id.IdentityEnvironment;
import org.olat.core.util.vfs.VFSContainer;
public interface WebDAVProvider {
public boolean hasAccess(IdentityEnvironment identityEnv);
/**
* Get a name under which this provider would like to list its container as at the root level of the WebDAV mount point
......
......@@ -130,7 +130,9 @@ public class WebDAVManagerImpl implements WebDAVManager, InitializingBean {
MergeSource vfsRoot = new MergeSource(null, "webdav");
for (Map.Entry<String, WebDAVProvider> entry : webdavModule.getWebDAVProviders().entrySet()) {
WebDAVProvider provider = entry.getValue();
vfsRoot.addContainer(new WebDAVProviderNamedContainer(identityEnv, provider));
if(provider.hasAccess(identityEnv)) {
vfsRoot.addContainer(new WebDAVProviderNamedContainer(identityEnv, provider));
}
}
return vfsRoot;
}
......@@ -139,9 +141,7 @@ public class WebDAVManagerImpl implements WebDAVManager, InitializingBean {
//create the / folder
VirtualContainer rootContainer = new VirtualContainer("");
rootContainer.setLocalSecurityCallback(new ReadOnlyCallback());
VFSResourceRoot fdc = new VFSResourceRoot(usess.getIdentity(), rootContainer);
return fdc;
return new VFSResourceRoot(usess.getIdentity(), rootContainer);
}
/**
......
......@@ -40,6 +40,11 @@ public class CoursefolderWebDAVProvider implements WebDAVProvider {
public String getMountPoint() {
return MOUNTPOINT;
}
@Override
public boolean hasAccess(IdentityEnvironment identityEnv) {
return identityEnv != null;
}
@Override
public VFSContainer getContainer(IdentityEnvironment identityEnv) {
......
......@@ -46,6 +46,11 @@ public class GroupfoldersWebDAVProvider implements WebDAVProvider {
public void setCollaborationManager(CollaborationManager collaborationManager) {
this.collaborationManager = collaborationManager;
}
@Override
public boolean hasAccess(IdentityEnvironment identityEnv) {
return identityEnv != null;
}
@Override
public String getMountPoint() {
......
......@@ -79,9 +79,15 @@ public class SharedFolderWebDAVProvider implements WebDAVProvider {
/**
* @see org.olat.core.commons.services.webdav.WebDAVProvider#getMountPoint()
*/
@Override
public String getMountPoint() {
return "sharedfolders";
}
@Override
public boolean hasAccess(IdentityEnvironment identityEnv) {
return identityEnv != null;
}
/**
* @see org.olat.core.commons.services.webdav.WebDAVProvider#getContainer(org.olat.core.id.Identity)
......
......@@ -664,6 +664,58 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
conn.close();
}
@Test
public void customizingFolder()
throws IOException, URISyntaxException {
Identity admin = JunitTestHelper.createAndPersistIdentityAsAdmin("admin-webdav");
dbInstance.commitAndCloseSession();
WebDAVConnection conn = new WebDAVConnection();
conn.setCredentials(admin.getName(), "A6B7C8");
//Has access?
URI customizingUri = conn.getBaseURI().path("webdav").path("customizing").build();
String customizingXml = conn.propfind(customizingUri, 2);
Assert.assertTrue(customizingXml.contains("<D:href>/webdav/customizing/</D:href>"));
//PUT in the folder
URI textUri = conn.getBaseURI().path("webdav").path("customizing").path("infos.txt").build();
HttpPut put = conn.createPut(textUri);
InputStream dataStream = WebDAVCommandsTest.class.getResourceAsStream("text.txt");
InputStreamEntity entity = new InputStreamEntity(dataStream, -1);
put.setEntity(entity);
HttpResponse putResponse = conn.execute(put);
Assert.assertEquals(201, putResponse.getStatusLine().getStatusCode());
//GET
HttpGet get = conn.createGet(textUri);
HttpResponse getResponse = conn.execute(get);
Assert.assertEquals(200, getResponse.getStatusLine().getStatusCode());
String text = EntityUtils.toString(getResponse.getEntity());
Assert.assertEquals("Small text", text);
conn.close();
}
@Test
public void customizingFolder_permission()
throws IOException, URISyntaxException {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("user-webdav");
dbInstance.commitAndCloseSession();
WebDAVConnection conn = new WebDAVConnection();
conn.setCredentials(user.getName(), "A6B7C8");
URI customizingUri = conn.getBaseURI().path("webdav").path("customizing").build();
HttpPropFind propfind = new HttpPropFind(customizingUri);
propfind.addHeader("Depth", Integer.toString(2));
HttpResponse response = conn.execute(propfind);
Assert.assertEquals(404, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.close();
}
private VFSItem createFile(VFSContainer container, String filename) throws IOException {
VFSLeaf testLeaf = container.createChildLeaf(filename);
InputStream in = WebDAVCommandsTest.class.getResourceAsStream("text.txt");
......
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