diff --git a/src/main/java/org/olat/repository/ui/author/AuthoringEditAccessAndBookingController.java b/src/main/java/org/olat/repository/ui/author/AuthoringEditAccessAndBookingController.java index f7fa5516c62b5d328588034668a6cb70134baf6b..84c54774f2dcea9fc1ff2b47ed9fae196cc8abf7 100644 --- a/src/main/java/org/olat/repository/ui/author/AuthoringEditAccessAndBookingController.java +++ b/src/main/java/org/olat/repository/ui/author/AuthoringEditAccessAndBookingController.java @@ -356,7 +356,7 @@ public class AuthoringEditAccessAndBookingController extends FormBasicController private void initFormOrganisations(FormItemContainer formLayout, UserSession usess) { Roles roles = usess.getRoles(); List<Organisation> organisations = organisationService.getOrganisations(getIdentity(), roles, - OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager); + OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager, OrganisationRoles.author); List<Organisation> organisationList = new ArrayList<>(organisations); List<Organisation> reOrganisations = repositoryService.getOrganisations(entry); diff --git a/src/test/java/org/olat/core/commons/services/webdav/WebDAVCommandsTest.java b/src/test/java/org/olat/core/commons/services/webdav/WebDAVCommandsTest.java index 89fac38bb1ae93d2e5afa6c98ab0bb9bf4116d6d..a0ba184f5e2e3d4384d65b4b84eed34aa2e402a3 100644 --- a/src/test/java/org/olat/core/commons/services/webdav/WebDAVCommandsTest.java +++ b/src/test/java/org/olat/core/commons/services/webdav/WebDAVCommandsTest.java @@ -153,6 +153,7 @@ public class WebDAVCommandsTest extends WebDAVTestCase { //head file URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build(); HttpResponse response = conn.head(publicUri); + Assert.assertEquals(200, response.getStatusLine().getStatusCode()); Header lengthHeader = response.getFirstHeader("Content-Length"); Assert.assertNotNull(lengthHeader); Assert.assertEquals("10", lengthHeader.getValue()); @@ -878,6 +879,49 @@ public class WebDAVCommandsTest extends WebDAVTestCase { conn.close(); } + /** + * Default are the following User-Agent forbidden: empty, - + * + * @throws IOException + * @throws URISyntaxException + */ + @Test + public void forbiddenUserAgent() + throws IOException, URISyntaxException { + Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("webdav-2-"); + + //create a file + String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public"; + VFSContainer vfsPublic = VFSManager.olatRootContainer(publicPath, null); + createFile(vfsPublic, "test_head.txt"); + + WebDAVConnection conn = new WebDAVConnection(); + URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build(); + + //head file with standard Apache User Agent -> Ok + conn.setCredentials(user.getName(), "A6B7C8"); + HttpResponse response = conn.head(publicUri); + Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + EntityUtils.consume(response.getEntity()); + conn.close(); + + // check with "-" as User-Agent -> Forbidden + WebDAVConnection hyphenConn = new WebDAVConnection("-"); + hyphenConn.setCredentials(user.getName(), "A6B7C8"); + HttpResponse hyphenResponse = hyphenConn.head(publicUri); + Assert.assertEquals(403, hyphenResponse.getStatusLine().getStatusCode()); + EntityUtils.consume(hyphenResponse.getEntity()); + hyphenConn.close(); + + // check with "" as User-Agent -> Forbidden + WebDAVConnection emptyConn = new WebDAVConnection("-"); + emptyConn.setCredentials(user.getName(), "A6B7C8"); + HttpResponse emptyResponse = emptyConn.head(publicUri); + Assert.assertEquals(403, emptyResponse.getStatusLine().getStatusCode()); + EntityUtils.consume(emptyResponse.getEntity()); + emptyConn.close(); + } + private VFSItem createFile(VFSContainer container, String filename) throws IOException { VFSLeaf testLeaf = container.createChildLeaf(filename); try(InputStream in = WebDAVCommandsTest.class.getResourceAsStream("text.txt"); diff --git a/src/test/java/org/olat/core/commons/services/webdav/WebDAVConnection.java b/src/test/java/org/olat/core/commons/services/webdav/WebDAVConnection.java index 446112863da63575a946b491e1ed801f5126aeb9..752d29bcba424547ea7351ec8f7f83f9a1a4ef9b 100644 --- a/src/test/java/org/olat/core/commons/services/webdav/WebDAVConnection.java +++ b/src/test/java/org/olat/core/commons/services/webdav/WebDAVConnection.java @@ -39,8 +39,6 @@ import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpOptions; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.BasicCredentialsProvider; @@ -76,22 +74,25 @@ public class WebDAVConnection implements Closeable { private final CloseableHttpClient httpclient; public WebDAVConnection() { - this(WebDAVTestCase.PROTOCOL, WebDAVTestCase.HOST, WebDAVTestCase.PORT); + this(WebDAVTestCase.PROTOCOL, WebDAVTestCase.HOST, WebDAVTestCase.PORT, null); } - public WebDAVConnection(String protocol, String host, int port) { + public WebDAVConnection(String userAgent) { + this(WebDAVTestCase.PROTOCOL, WebDAVTestCase.HOST, WebDAVTestCase.PORT, userAgent); + } + + public WebDAVConnection(String protocol, String host, int port, String userAgent) { this.protocol = protocol; this.host = host; this.port = port; - SSLConnectionSocketFactory sslFactory - = new SSLConnectionSocketFactory(SSLContexts.createDefault(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); - - httpclient = HttpClientBuilder.create() + HttpClientBuilder builder = HttpClientBuilder.create() .setDefaultCookieStore(cookieStore) - .setDefaultCredentialsProvider(provider) - .setSSLSocketFactory(sslFactory) - .build(); + .setDefaultCredentialsProvider(provider); + if(userAgent != null) { + builder.setUserAgent(userAgent); + } + httpclient = builder.build(); } public CookieStore getCookieStore() { @@ -112,9 +113,7 @@ public class WebDAVConnection implements Closeable { public HttpResponse head(URI uri) throws IOException, URISyntaxException { HttpHead propfind = new HttpHead(uri); - HttpResponse response = execute(propfind); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); - return response; + return execute(propfind); } public String propfind(URI uri, int depth) throws IOException, URISyntaxException {