Skip to content

Commit

Permalink
dbeaver/dbeaver-vscode#16 fix SQL processor, server port cli arg (#2933)
Browse files Browse the repository at this point in the history
Co-authored-by: mr-anton-t <[email protected]>
  • Loading branch information
alexander-skoblikov and mr-anton-t authored Sep 30, 2024
1 parent 3118eac commit 735024b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,11 @@ public WebSession(
@NotNull WebAuthApplication application,
@NotNull Map<String, DBWSessionHandler> sessionHandlers
) throws DBException {
super(requestInfo.getId(), application);
this.lastAccessTime = this.createTime;
setLocale(CommonUtils.toString(requestInfo.getLocale(), this.locale));
this.sessionHandlers = sessionHandlers;
//force authorization of anonymous session to avoid access error,
//because before authorization could be called by any request,
//but now 'updateInfo' is called only in special requests,
//and the order of requests is not guaranteed.
//look at CB-4747
refreshSessionAuth();
this(requestInfo.getId(),
CommonUtils.toString(requestInfo.getLocale()),
application,
sessionHandlers
);
updateSessionParameters(requestInfo);
}

Expand All @@ -151,7 +146,7 @@ protected WebSession(
super(id, application);
this.lastAccessTime = this.createTime;
this.sessionHandlers = sessionHandlers;
setLocale(locale);
setLocale(CommonUtils.toString(locale, this.locale));
//force authorization of anonymous session to avoid access error,
//because before authorization could be called by any request,
//but now 'updateInfo' is called only in special requests,
Expand Down Expand Up @@ -431,7 +426,7 @@ private boolean isDataSourceAccessible(DBPDataSourceContainer dataSource) {
}

@NotNull
private Set<String> readAccessibleConnectionIds() {
protected Set<String> readAccessibleConnectionIds() {
try {
return getSecurityController()
.getAllAvailableObjectsPermissions(SMObjectType.datasource)
Expand Down Expand Up @@ -493,7 +488,7 @@ private synchronized void refreshSessionAuth() {
}
}

private synchronized void refreshAccessibleConnectionIds() {
protected synchronized void refreshAccessibleConnectionIds() {
this.accessibleConnectionIds = readAccessibleConnectionIds();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.cloudbeaver.server;

import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.utils.WebAppUtils;
import org.eclipse.core.runtime.Platform;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
Expand All @@ -28,8 +28,6 @@
import org.jkiss.dbeaver.model.impl.app.BaseWorkspaceImpl;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
Expand All @@ -48,17 +46,7 @@ public class WebGlobalWorkspace extends BaseWorkspaceImpl {
private WebGlobalProject globalProject;

public WebGlobalWorkspace(DBPPlatform platform) {
super(platform, Path.of(getWorkspaceURI()));
}

@NotNull
private static URI getWorkspaceURI() {
String workspacePath = Platform.getInstanceLocation().getURL().toString();
try {
return new URI(workspacePath);
} catch (URISyntaxException e) {
throw new IllegalStateException("Workspace path is invalid: " + workspacePath, e);
}
super(platform, ((WebApplication) platform.getApplication()).getWorkspaceDirectory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.utils.ConfigurationUtils;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.dbeaver.model.connection.DBPDriver;

//TODO move to a separate CBApplication plugin
public class WebDatasourceAccessCheckHandler extends BaseDatasourceAccessCheckHandler {
@Override
protected boolean isDriverDisabled(DBPDriver driver) {
if (!WebAppUtils.getWebApplication().isMultiuser()) {
return false;
}
CBAppConfig config = CBApplication.getInstance().getAppConfiguration();
return !ConfigurationUtils.isDriverEnabled(
driver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ protected void startServer() {

Location instanceLoc = Platform.getInstanceLocation();
try {
if (!instanceLoc.isSet()) {
if (!instanceLoc.isSet()) { // always false?
URL wsLocationURL = new URL(
"file", //$NON-NLS-1$
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.HttpConstants;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.DBWServiceBindingGraphQL;
Expand Down Expand Up @@ -63,6 +61,8 @@ public class GraphQLEndpoint extends HttpServlet {

private static final Log log = Log.getLog(GraphQLEndpoint.class);

private static final boolean DEBUG = true;

private static final String HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
private static final String HEADER_ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
private static final String HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
Expand Down Expand Up @@ -255,6 +255,8 @@ private void executeQuery(HttpServletRequest request, HttpServletResponse respon
// }
if (apiCall != null) {
log.debug("API > " + apiCall);
} else if (DEBUG) {
log.debug("API > " + query);
}
}
ExecutionInput executionInput = contextBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.cloudbeaver.service.sql;

import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
Expand Down Expand Up @@ -58,7 +58,9 @@ class WebSQLQueryDataReceiver implements DBDDataReceiver {
this.contextInfo = contextInfo;
this.dataContainer = dataContainer;
this.dataFormat = dataFormat;
rowLimit = CBApplication.getInstance().getAppConfiguration().getResourceQuota(WebSQLConstants.QUOTA_PROP_ROW_LIMIT);
rowLimit = WebAppUtils.getWebApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_ROW_LIMIT);
}

public WebSQLQueryResultSet getResultSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
package io.cloudbeaver.service.sql;

import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.CBModelConstants;
import io.cloudbeaver.utils.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.*;
Expand Down Expand Up @@ -151,9 +151,11 @@ private static Object serializeContentValue(WebSession session, DBDContent value
if (ContentUtils.isTextContent(value)) {
String stringValue = ContentUtils.getContentStringValue(session.getProgressMonitor(), value);
int textPreviewMaxLength = CommonUtils.toInt(
CBApplication.getInstance().getAppConfiguration().getResourceQuota(
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH,
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH));
WebAppUtils.getWebApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH),
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH
);
if (stringValue != null && stringValue.length() > textPreviewMaxLength) {
stringValue = stringValue.substring(0, textPreviewMaxLength);
}
Expand All @@ -164,21 +166,20 @@ private static Object serializeContentValue(WebSession session, DBDContent value
if (binaryValue != null) {
byte[] previewValue = binaryValue;
// gets parameters from the configuration file
CBAppConfig config = CBApplication.getInstance().getAppConfiguration();
WebAppConfiguration config = WebAppUtils.getWebApplication().getAppConfiguration();
// the max length of the text preview
int textPreviewMaxLength = CommonUtils.toInt(
config.getResourceQuota(
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH,
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH));
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH), WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH);
if (previewValue.length > textPreviewMaxLength) {
previewValue = Arrays.copyOf(previewValue, textPreviewMaxLength);
}
map.put(WebSQLConstants.ATTR_TEXT, GeneralUtils.convertToString(previewValue, 0, previewValue.length));
// the max length of the binary preview
int binaryPreviewMaxLength = CommonUtils.toInt(
config.getResourceQuota(
WebSQLConstants.QUOTA_PROP_BINARY_PREVIEW_MAX_LENGTH,
WebSQLConstants.BINARY_PREVIEW_MAX_LENGTH));
WebSQLConstants.QUOTA_PROP_BINARY_PREVIEW_MAX_LENGTH),
WebSQLConstants.BINARY_PREVIEW_MAX_LENGTH);
byte[] inlineValue = binaryValue;
if (inlineValue.length > binaryPreviewMaxLength) {
inlineValue = Arrays.copyOf(inlineValue, textPreviewMaxLength);
Expand Down Expand Up @@ -214,9 +215,11 @@ private static Object serializeGeometryValue(DBGeometry value) {
*/
public static Object serializeStringValue(Object value) {
int textPreviewMaxLength = CommonUtils.toInt(
CBApplication.getInstance().getAppConfiguration().getResourceQuota(
WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH,
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH));
WebAppUtils.getWebApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH),
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH
);
String stringValue = value.toString();
if (stringValue.length() < textPreviewMaxLength) {
return value.toString();
Expand Down

0 comments on commit 735024b

Please sign in to comment.