diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java index 42c1d5c122..716dd7386f 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java @@ -129,16 +129,11 @@ public WebSession( @NotNull WebAuthApplication application, @NotNull Map 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); } @@ -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, @@ -431,7 +426,7 @@ private boolean isDataSourceAccessible(DBPDataSourceContainer dataSource) { } @NotNull - private Set readAccessibleConnectionIds() { + protected Set readAccessibleConnectionIds() { try { return getSecurityController() .getAllAvailableObjectsPermissions(SMObjectType.datasource) @@ -493,7 +488,7 @@ private synchronized void refreshSessionAuth() { } } - private synchronized void refreshAccessibleConnectionIds() { + protected synchronized void refreshAccessibleConnectionIds() { this.accessibleConnectionIds = readAccessibleConnectionIds(); } diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalWorkspace.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalWorkspace.java index 02a3b4e53d..3e975239a6 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalWorkspace.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/server/WebGlobalWorkspace.java @@ -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; @@ -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; @@ -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 diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebDatasourceAccessCheckHandler.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebDatasourceAccessCheckHandler.java index 2e3ca7aea1..ddd680fb03 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebDatasourceAccessCheckHandler.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/model/WebDatasourceAccessCheckHandler.java @@ -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, diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index 2027832a9d..0bf84aae33 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -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, diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/graphql/GraphQLEndpoint.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/graphql/GraphQLEndpoint.java index b004e7e80d..15506f79dd 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/graphql/GraphQLEndpoint.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/graphql/GraphQLEndpoint.java @@ -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; @@ -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"; @@ -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(); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLQueryDataReceiver.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLQueryDataReceiver.java index 6a5800cb20..89bdc1e5f1 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLQueryDataReceiver.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLQueryDataReceiver.java @@ -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; @@ -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() { diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java index 2e55d43b34..9bf207fa4c 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLUtils.java @@ -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.*; @@ -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); } @@ -164,12 +166,11 @@ 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); } @@ -177,8 +178,8 @@ private static Object serializeContentValue(WebSession session, DBDContent value // 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); @@ -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();