-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'devel' into CB-4127-ssl-tab-show-certificates
- Loading branch information
Showing
45 changed files
with
403 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...r/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/model/WebFSServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* DBeaver - Universal Database Manager | ||
* Copyright (C) 2010-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.cloudbeaver.service.fs.model; | ||
|
||
import io.cloudbeaver.DBWebException; | ||
import io.cloudbeaver.model.session.WebSession; | ||
import io.cloudbeaver.server.CBApplication; | ||
import io.cloudbeaver.service.WebServiceServletBase; | ||
import io.cloudbeaver.service.fs.DBWServiceFS; | ||
import org.eclipse.jetty.server.Request; | ||
import org.jkiss.code.NotNull; | ||
import org.jkiss.dbeaver.DBException; | ||
import org.jkiss.dbeaver.model.data.json.JSONUtils; | ||
import org.jkiss.utils.CommonUtils; | ||
import org.jkiss.utils.IOUtils; | ||
|
||
import javax.servlet.MultipartConfigElement; | ||
import javax.servlet.annotation.MultipartConfig; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.Part; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
|
||
@MultipartConfig() | ||
public class WebFSServlet extends WebServiceServletBase { | ||
private static final String PARAM_PROJECT_ID = "projectId"; | ||
private final DBWServiceFS fs; | ||
|
||
public WebFSServlet(CBApplication application, DBWServiceFS fs) { | ||
super(application); | ||
this.fs = fs; | ||
} | ||
|
||
@Override | ||
protected void processServiceRequest(WebSession session, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException { | ||
if (!session.isAuthorizedInSecurityManager()) { | ||
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Anonymous access restricted."); | ||
return; | ||
} | ||
if (request.getMethod().equals("POST")) { | ||
doPost(session, request, response); | ||
} else { | ||
doGet(session, request, response); | ||
} | ||
|
||
} | ||
|
||
private void doGet(WebSession session, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException { | ||
String projectId = request.getParameter(PARAM_PROJECT_ID); | ||
Path path = getPath(session, projectId, request.getParameter("fileURI")); | ||
session.addInfoMessage("Download data ..."); | ||
response.setHeader("Content-Type", "application/octet-stream"); | ||
response.setHeader("Content-Disposition", "attachment; filename=\"" + path.getFileName() + "\""); | ||
response.setHeader("Content-Length", String.valueOf(Files.size(path))); | ||
|
||
try (InputStream is = Files.newInputStream(path)) { | ||
IOUtils.copyStream(is, response.getOutputStream()); | ||
} | ||
} | ||
|
||
private void doPost(WebSession session, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException { | ||
// we need to set this attribute to get parts | ||
request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement("")); | ||
Map<String, Object> variables = getVariables(request); | ||
String projectId = JSONUtils.getString(variables, PARAM_PROJECT_ID); | ||
String uri = JSONUtils.getString(variables, "toURI"); | ||
Path path = getPath(session, projectId, uri); | ||
try { | ||
for (Part part : request.getParts()) { | ||
String fileName = part.getSubmittedFileName(); | ||
if (CommonUtils.isEmpty(fileName)) { | ||
continue; | ||
} | ||
try (InputStream is = part.getInputStream()) { | ||
Files.copy(is, path.resolve(fileName)); | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw new DBWebException("File Upload Failed: Unable to Save File to the File System", e); | ||
} | ||
} | ||
|
||
@NotNull | ||
private Path getPath(WebSession session, String projectId, String uri) throws DBException { | ||
if (CommonUtils.isEmpty(projectId)) { | ||
throw new DBWebException("Project ID is not found"); | ||
} | ||
if (CommonUtils.isEmpty(uri)) { | ||
throw new DBWebException("URI is not found"); | ||
} | ||
return session.getFileSystemManager(projectId).getPathFromString(session.getProgressMonitor(), uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
server/bundles/io.cloudbeaver.service.security/db/cb_schema_update_13.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ALTER TABLE {table_prefix}CB_USER_SECRETS | ||
ADD COLUMN ENCODING_TYPE VARCHAR(32) NOT NULL DEFAULT 'PLAINTEXT'; | ||
ADD COLUMN ENCODING_TYPE VARCHAR(32) DEFAULT 'PLAINTEXT' NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.