Skip to content

Commit

Permalink
CB-4123 upload file fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yagudin10 committed Oct 25, 2023
1 parent 7de4a45 commit 2bfd871
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package io.cloudbeaver.service.fs.model;

import io.cloudbeaver.DBWConstants;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
Expand All @@ -27,6 +28,7 @@
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.navigator.fs.DBNPathBase;
import org.jkiss.dbeaver.model.rm.RMConstants;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.IOUtils;

Expand All @@ -52,11 +54,17 @@ public WebFSServlet(CBApplication application, DBWServiceFS fs) {
@Override
protected void processServiceRequest(WebSession session, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException {
if (request.getMethod().equals("POST")) {
if (!session.hasPermission(RMConstants.PERMISSION_PROJECT_RESOURCE_EDIT)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user needs more permissions to upload files to virtual file systems");
return;
}
// Hack for getting request params
request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement(""));
String nodePath = JSONUtils.getString(getVariables(request), NODE_PATH);
Path path = getPath(session, nodePath);
// set the final location of parent folder
request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement(path.toString()));
try {
MultipartConfigElement MULTI_PART_CONFIG = new MultipartConfigElement(path.toString());
request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, MULTI_PART_CONFIG);
for (Part part : request.getParts()) {
String fileName = part.getSubmittedFileName();
if (CommonUtils.isEmpty(fileName)) {
Expand All @@ -70,6 +78,10 @@ protected void processServiceRequest(WebSession session, HttpServletRequest requ
throw new DBWebException("Servlet exception ", e);
}
} else {
if (!session.hasPermission(RMConstants.PERMISSION_PROJECT_RESOURCE_VIEW)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user needs more permissions to load files from virtual file systems");
return;
}
Path path = getPath(session, request.getParameter(NODE_PATH));
session.addInfoMessage("Download data ...");
response.setHeader("Content-Type", "application/octet-stream");
Expand Down

0 comments on commit 2bfd871

Please sign in to comment.