Dbeaver/dbeaver vscode#22 split core plugins (#3102)

* dbeaver/dbeaver-vscode#22 wip

* dbeaver/dbeaver-vscode#22 wip

* dbeaver/dbeaver-vscode#22 wip

* dbeaver/dbeaver-vscode#22 gql model fix

* dbeaver/dbeaver-vscode#22 missed class fix

* dbeaver/dbeaver-vscode#22 ce fixes

* dbeaver/dbeaver-vscode#22 fixes

* dbeaver/dbeaver-vscode#22 review fixes

---------

Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com>
Co-authored-by: Alexey <wrouds@gmail.com>
This commit is contained in:
Alexander Skoblikov
2024-12-04 08:20:06 +01:00
committed by GitHub
co-authored by mr-anton-t Alexey
parent 7f1c9ceec0
commit 0b5af36628
119 changed files with 904 additions and 701 deletions
@@ -22,7 +22,7 @@ import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.service.sql.WebDataFormat;
import io.cloudbeaver.utils.CBModelConstants;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebCommonUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
@@ -465,7 +465,8 @@ public class WebConnectionInfo {
if (isCanEdit()) {
return true;
}
BaseWebAppConfiguration appConfig = (BaseWebAppConfiguration) WebAppUtils.getWebApplication().getAppConfiguration();
BaseWebAppConfiguration appConfig = (BaseWebAppConfiguration) ServletAppUtils.getServletApplication()
.getAppConfiguration();
return appConfig.isShowReadOnlyConnectionInfo();
}
@@ -32,8 +32,8 @@ import java.nio.file.Path;
/**
* Abstract class that contains methods for loading configuration with gson.
*/
public abstract class BaseServerConfigurationController<T extends WebServerConfiguration>
implements WebServerConfigurationController<T> {
public abstract class BaseServerConfigurationController<T extends ServletServerConfiguration>
implements ServletServerConfigurationController<T> {
private static final Log log = Log.getLog(BaseServerConfigurationController.class);
@NotNull
private final Path homeDirectory;
@@ -45,16 +45,16 @@ import java.util.List;
import java.util.Map;
/**
* Web application
* Servlet application
*/
public abstract class BaseWebApplication extends BaseApplicationImpl implements WebApplication {
public abstract class BaseServletApplication extends BaseApplicationImpl implements ServletApplication {
public static final String DEFAULT_CONFIG_FILE_PATH = "/etc/cloudbeaver.conf";
public static final String CUSTOM_CONFIG_FOLDER = "custom";
public static final String CLI_PARAM_WEB_CONFIG = "-web-config";
public static final String LOGBACK_FILE_NAME = "logback.xml";
private static final Log log = Log.getLog(BaseWebApplication.class);
private static final Log log = Log.getLog(BaseServletApplication.class);
private String instanceId;
@@ -252,7 +252,7 @@ public abstract class BaseWebApplication extends BaseApplicationImpl implements
return null;
}
public abstract WebServerConfigurationController getServerConfigurationController();
public abstract ServletServerConfigurationController getServerConfigurationController();
@Override
public boolean isEnvironmentVariablesAccessible() {
@@ -25,7 +25,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
public abstract class BaseWebAppConfiguration implements WebAppConfiguration {
public abstract class BaseWebAppConfiguration implements ServletAppConfiguration {
public static final String DEFAULT_APP_ANONYMOUS_TEAM_NAME = "user";
protected final Map<String, Object> plugins;
@@ -0,0 +1,55 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.model.app;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import java.util.Map;
/**
* Application configuration
*/
public interface ServletAppConfiguration {
String getAnonymousUserTeam();
boolean isAnonymousAccessEnabled();
@Nullable
<T> T getResourceQuota(String quotaId);
String getDefaultUserTeam();
<T> T getPluginOption(@NotNull String pluginId, @NotNull String option);
Map<String, Object> getPluginConfig(@NotNull String pluginId, boolean create);
boolean isResourceManagerEnabled();
boolean isFeaturesEnabled(String[] requiredFeatures);
boolean isFeatureEnabled(String id);
@NotNull
default String[] getEnabledFeatures() {
return new String[0];
}
default boolean isSupportsCustomConnections() {
return true;
}
}
@@ -35,16 +35,16 @@ import java.util.Map;
/**
* Base interface for web application
*/
public interface WebApplication extends DBPApplication {
public interface ServletApplication extends DBPApplication {
boolean isConfigurationMode();
default boolean isInitializationMode() {
return false;
}
default boolean isInitializationMode() {
return false;
}
WebAppConfiguration getAppConfiguration();
ServletAppConfiguration getAppConfiguration();
WebServerConfiguration getServerConfiguration();
ServletServerConfiguration getServerConfiguration();
Path getDataDirectory(boolean create);
@@ -20,10 +20,8 @@ package io.cloudbeaver.model.app;
import io.cloudbeaver.auth.CBAuthConstants;
import org.jkiss.dbeaver.DBException;
import java.util.List;
public interface WebAuthApplication extends WebApplication {
WebAuthConfiguration getAuthConfiguration();
public interface ServletAuthApplication extends ServletApplication {
ServletAuthConfiguration getAuthConfiguration();
String getAuthServiceURL();
@@ -25,7 +25,7 @@ import java.util.Set;
/**
* Application authentication configuration
*/
public interface WebAuthConfiguration {
public interface ServletAuthConfiguration {
String getDefaultAuthProvider();
@@ -25,7 +25,7 @@ import java.util.Map;
* Web server configuration.
* Contains only server configuration properties.
*/
public interface WebServerConfiguration {
public interface ServletServerConfiguration {
boolean isDevelMode();
default String getRootURI() {
@@ -39,5 +39,4 @@ public interface WebServerConfiguration {
default Map<String, Object> getProductSettings() {
return Map.of();
}
}
@@ -27,7 +27,7 @@ import java.util.Map;
* Server configuration controller.
* Works with app server configuration (loads, updates)
*/
public interface WebServerConfigurationController<T extends WebServerConfiguration> {
public interface ServletServerConfigurationController<T extends ServletServerConfiguration> {
/**
* Loads server configuration.
@@ -17,39 +17,38 @@
package io.cloudbeaver.model.app;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.navigator.DBNBrowseSettings;
import org.jkiss.dbeaver.registry.DataSourceNavigatorSettings;
import java.util.Map;
/**
* Application configuration
*/
public interface WebAppConfiguration {
String getAnonymousUserTeam();
public interface WebAppConfiguration extends ServletAppConfiguration {
DataSourceNavigatorSettings.Preset PRESET_WEB = new DataSourceNavigatorSettings.Preset("web",
"Web",
"Default view");
boolean isAnonymousAccessEnabled();
DBNBrowseSettings getDefaultNavigatorSettings();
@Nullable
<T> T getResourceQuota(String quotaId);
boolean isPublicCredentialsSaveEnabled();
String getDefaultUserTeam();
boolean isAdminCredentialsSaveEnabled();
<T> T getPluginOption(@NotNull String pluginId, @NotNull String option);
Map<String, Object> getPluginConfig(@NotNull String pluginId, boolean create);
boolean isResourceManagerEnabled();
boolean isFeaturesEnabled(String[] requiredFeatures);
boolean isFeatureEnabled(String id);
@NotNull
default String[] getEnabledFeatures() {
default String[] getDisabledBetaFeatures() {
return new String[0];
}
default boolean isSupportsCustomConnections() {
return true;
default String[] getEnabledAuthProviders() {
return new String[0];
}
@NotNull
String[] getEnabledDrivers();
@NotNull
String[] getDisabledDrivers();
Map<String, Object> getResourceQuotas();
}
@@ -19,7 +19,8 @@ package io.cloudbeaver.model.config;
import com.google.gson.annotations.Expose;
import io.cloudbeaver.auth.provider.local.LocalAuthProviderConstants;
import io.cloudbeaver.model.app.BaseWebAppConfiguration;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
import org.jkiss.code.NotNull;
@@ -36,9 +37,8 @@ import java.util.*;
/**
* Application configuration
*/
public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfiguration {
public class CBAppConfig extends BaseWebAppConfiguration implements ServletAuthConfiguration, WebAppConfiguration {
private static final Log log = Log.getLog(CBAppConfig.class);
public static final DataSourceNavigatorSettings.Preset PRESET_WEB = new DataSourceNavigatorSettings.Preset("web", "Web", "Default view");
public static final DataSourceNavigatorSettings DEFAULT_VIEW_SETTINGS = PRESET_WEB.getSettings();
private final Set<SMAuthProviderCustomConfiguration> authConfigurations;
@@ -47,8 +47,6 @@ public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfi
private final Map<String, SMAuthProviderCustomConfiguration> authConfiguration;
private boolean supportsCustomConnections;
private boolean supportsConnectionBrowser;
private boolean supportsUserWorkspaces;
private boolean enableReverseProxyAuth;
private boolean forwardProxy;
private boolean publicCredentialsSaveEnabled;
@@ -80,8 +78,6 @@ public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfi
this.anonymousUserRole = DEFAULT_APP_ANONYMOUS_TEAM_NAME;
this.anonymousUserTeam = DEFAULT_APP_ANONYMOUS_TEAM_NAME;
this.supportsCustomConnections = true;
this.supportsConnectionBrowser = false;
this.supportsUserWorkspaces = false;
this.publicCredentialsSaveEnabled = true;
this.adminCredentialsSaveEnabled = true;
this.redirectOnFederatedAuth = false;
@@ -106,8 +102,6 @@ public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfi
this.anonymousUserRole = src.anonymousUserRole;
this.anonymousUserTeam = src.anonymousUserTeam;
this.supportsCustomConnections = src.supportsCustomConnections;
this.supportsConnectionBrowser = src.supportsConnectionBrowser;
this.supportsUserWorkspaces = src.supportsUserWorkspaces;
this.publicCredentialsSaveEnabled = src.publicCredentialsSaveEnabled;
this.adminCredentialsSaveEnabled = src.adminCredentialsSaveEnabled;
this.redirectOnFederatedAuth = src.redirectOnFederatedAuth;
@@ -148,14 +142,6 @@ public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfi
this.supportsCustomConnections = supportsCustomConnections;
}
public boolean isSupportsConnectionBrowser() {
return supportsConnectionBrowser;
}
public boolean isSupportsUserWorkspaces() {
return supportsUserWorkspaces;
}
public boolean isPublicCredentialsSaveEnabled() {
return publicCredentialsSaveEnabled;
}
@@ -176,6 +162,7 @@ public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfi
return redirectOnFederatedAuth;
}
@NotNull
public String[] getEnabledDrivers() {
return enabledDrivers;
}
@@ -184,6 +171,7 @@ public class CBAppConfig extends BaseWebAppConfiguration implements WebAuthConfi
this.enabledDrivers = enabledDrivers;
}
@NotNull
public String[] getDisabledDrivers() {
return disabledDrivers;
}
@@ -1,51 +0,0 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.model.rm;
import io.cloudbeaver.model.app.WebApplication;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.rm.RMController;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class RMControllerInvocationHandler implements InvocationHandler {
private final WebApplication webApplication;
private final RMController rmController;
public RMControllerInvocationHandler(RMController rmController, WebApplication webApplication) {
this.webApplication = webApplication;
this.rmController = rmController;
}
private void checkIsRmEnabled() throws DBException {
if (!webApplication.getAppConfiguration().isResourceManagerEnabled()) {
throw new DBException("Resource Manager disabled");
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
checkIsRmEnabled();
return method.invoke(rmController, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
}
@@ -18,11 +18,11 @@ package io.cloudbeaver.model.rm.local;
import io.cloudbeaver.BaseWebProjectImpl;
import io.cloudbeaver.DBWConstants;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.rm.lock.RMFileLockController;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.service.sql.WebSQLConstants;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.file.UniversalFileVisitor;
import org.eclipse.core.runtime.IPath;
import org.jkiss.code.NotNull;
@@ -84,7 +84,7 @@ public class LocalResourceController extends BaseLocalResourceController {
Path sharedProjectsPath,
Supplier<SMController> smControllerSupplier
) throws DBException {
super(workspace, new RMFileLockController(WebAppUtils.getWebApplication()));
super(workspace, new RMFileLockController(ServletAppUtils.getServletApplication()));
this.credentialsProvider = credentialsProvider;
this.rootPath = rootPath;
this.userProjectsPath = userProjectsPath;
@@ -145,7 +145,7 @@ public class LocalResourceController extends BaseLocalResourceController {
}
// Checking if private projects are enabled in the configuration and if the user has permission to them
var webApp = WebAppUtils.getWebApplication();
var webApp = ServletAppUtils.getServletApplication();
var userHasPrivateProjectPermission = userHasAccessToPrivateProject(webApp, activeUserCreds);
if (webApp.getAppConfiguration().isSupportsCustomConnections() && userHasPrivateProjectPermission) {
var userProjectPermission = getProjectPermissions(null, RMProjectType.USER);
@@ -154,7 +154,7 @@ public class LocalResourceController extends BaseLocalResourceController {
projects.add(0, userProject);
}
}
if (WebAppUtils.getWebApplication().isMultiNode()) {
if (ServletAppUtils.getServletApplication().isMultiNode()) {
for (RMProject rmProject : projects) {
handleProjectOpened(rmProject.getId());
}
@@ -200,7 +200,7 @@ public class LocalResourceController extends BaseLocalResourceController {
}
return getRmProjectPermissions(projectId, activeUserCreds);
case USER:
var webApp = WebAppUtils.getWebApplication();
var webApp = ServletAppUtils.getServletApplication();
if (userHasAccessToPrivateProject(webApp, activeUserCreds)) {
return Set.of(RMProjectPermission.RESOURCE_EDIT, RMProjectPermission.DATA_SOURCES_EDIT);
}
@@ -209,7 +209,7 @@ public class LocalResourceController extends BaseLocalResourceController {
}
}
private boolean userHasAccessToPrivateProject(WebApplication webApp, @Nullable SMCredentials activeUserCreds) {
private boolean userHasAccessToPrivateProject(ServletApplication webApp, @Nullable SMCredentials activeUserCreds) {
return !webApp.isMultiNode() ||
(activeUserCreds != null && activeUserCreds.hasPermission(DBWConstants.PERMISSION_PRIVATE_PROJECT_ACCESS));
}
@@ -277,7 +277,7 @@ public class LocalResourceController extends BaseLocalResourceController {
try {
log.debug("Creating project '" + project.getId() + "'");
Files.createDirectories(projectPath);
if (WebAppUtils.getWebApplication().isMultiNode()) {
if (ServletAppUtils.getServletApplication().isMultiNode()) {
createResourceTypeFolders(projectPath);
}
fireRmProjectAddEvent(project);
@@ -581,7 +581,7 @@ public class LocalResourceController extends BaseLocalResourceController {
) throws DBException {
try (var ignoredLock = lockController.lockProject(projectId, "setResourceContents")) {
validateResourcePath(resourcePath);
Number fileSizeLimit = WebAppUtils.getWebApplication()
Number fileSizeLimit = ServletAppUtils.getServletApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_RM_FILE_SIZE_LIMIT);
if (fileSizeLimit != null && data.length > fileSizeLimit.longValue()) {
@@ -775,7 +775,7 @@ public class LocalResourceController extends BaseLocalResourceController {
fileHandler.projectOpened(projectId);
} catch (Exception e) {
if (credentialsProvider.getActiveUserCredentials() != null) {
WebAppUtils.getWebApplication().getEventController().addEvent(
ServletAppUtils.getServletApplication().getEventController().addEvent(
new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
credentialsProvider.getActiveUserCredentials().getSmSessionId(),
@@ -794,7 +794,7 @@ public class LocalResourceController extends BaseLocalResourceController {
fileHandler.beforeFileRead(projectId, file);
} catch (Exception e) {
if (credentialsProvider.getActiveUserCredentials() != null) {
WebAppUtils.getWebApplication().getEventController().addEvent(
ServletAppUtils.getServletApplication().getEventController().addEvent(
new WSSessionLogUpdatedEvent(
WSEventType.SESSION_LOG_UPDATED,
credentialsProvider.getActiveUserCredentials().getSmSessionId(),
@@ -17,7 +17,7 @@
package io.cloudbeaver.model.rm.lock;
import com.google.gson.Gson;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
@@ -50,12 +50,12 @@ public class RMFileLockController {
private final int maxLockTime;
public RMFileLockController(WebApplication application) throws DBException {
public RMFileLockController(ServletApplication application) throws DBException {
this(application, DEFAULT_MAX_LOCK_TIME);
}
// for tests
public RMFileLockController(WebApplication application, int maxLockTime) throws DBException {
public RMFileLockController(ServletApplication application, int maxLockTime) throws DBException {
this.lockFolderPath = application.getWorkspaceDirectory()
.resolve(DBPWorkspace.METADATA_FOLDER)
.resolve(LOCK_META_FOLDER);
@@ -17,8 +17,8 @@
package io.cloudbeaver.model.session;
import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.websocket.CBWebSessionEventHandler;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
@@ -51,14 +51,14 @@ public abstract class BaseWebSession extends AbstractSessionPersistent {
@NotNull
protected final WebUserContext userContext;
@NotNull
protected final WebApplication application;
protected final ServletApplication application;
protected volatile long lastAccessTime;
private final List<CBWebSessionEventHandler> sessionEventHandlers = new CopyOnWriteArrayList<>();
private WebSessionEventsFilter eventsFilter = new WebSessionEventsFilter();
private final WebSessionWorkspace workspace;
public BaseWebSession(@NotNull String id, @NotNull WebApplication application) throws DBException {
public BaseWebSession(@NotNull String id, @NotNull ServletApplication application) throws DBException {
this.id = id;
this.application = application;
this.createTime = System.currentTimeMillis();
@@ -153,7 +153,7 @@ public abstract class BaseWebSession extends AbstractSessionPersistent {
}
@NotNull
public WebApplication getApplication() {
public ServletApplication getApplication() {
return application;
}
@@ -238,7 +238,7 @@ public abstract class BaseWebSession extends AbstractSessionPersistent {
@Property
public long getRemainingTime() {
if (application instanceof WebAuthApplication authApplication) {
if (application instanceof ServletAuthApplication authApplication) {
return authApplication.getMaxSessionIdleTime() + lastAccessTime - System.currentTimeMillis();
}
return Integer.MAX_VALUE;
@@ -17,7 +17,7 @@
package io.cloudbeaver.model.session;
import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
@@ -29,7 +29,7 @@ import org.jkiss.dbeaver.model.auth.SMSessionPrincipal;
public class WebHeadlessSession extends BaseWebSession {
public WebHeadlessSession(
@NotNull String id,
@NotNull WebAuthApplication application
@NotNull ServletAuthApplication application
) throws DBException {
super(id, application);
}
@@ -24,8 +24,8 @@ import io.cloudbeaver.*;
import io.cloudbeaver.model.WebAsyncTaskInfo;
import io.cloudbeaver.model.WebConnectionInfo;
import io.cloudbeaver.model.WebServerMessage;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.model.user.WebUser;
import io.cloudbeaver.service.DBWSessionHandler;
import io.cloudbeaver.service.sql.WebSQLConstants;
@@ -114,7 +114,7 @@ public class WebSession extends BaseWebSession
public WebSession(
@NotNull WebHttpRequestInfo requestInfo,
@NotNull WebAuthApplication application,
@NotNull ServletAuthApplication application,
@NotNull Map<String, DBWSessionHandler> sessionHandlers
) throws DBException {
this(requestInfo.getId(),
@@ -128,7 +128,7 @@ public class WebSession extends BaseWebSession
protected WebSession(
@NotNull String id,
@Nullable String locale,
@NotNull WebApplication application,
@NotNull ServletApplication application,
@NotNull Map<String, DBWSessionHandler> sessionHandlers
) throws DBException {
super(id, application);
@@ -20,11 +20,11 @@ package io.cloudbeaver.model.session;
import io.cloudbeaver.DBWUserIdentity;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.auth.SMAuthProviderExternal;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.model.user.WebUser;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
@@ -82,7 +82,7 @@ public class WebSessionAuthProcessor {
@SuppressWarnings("unchecked")
private List<WebAuthInfo> finishWebSessionAuthorization(SMAuthInfo authInfo) throws DBException {
boolean configMode = WebAppUtils.getWebApplication().isConfigurationMode();
boolean configMode = ServletAppUtils.getServletApplication().isConfigurationMode();
boolean alreadyLoggedIn = webSession.getUser() != null;
boolean resetUserStateOnError = !alreadyLoggedIn;
@@ -127,7 +127,7 @@ public class WebSessionAuthProcessor {
DBWUserIdentity userIdentity = null;
var providerConfigId = authConfiguration.getAuthProviderConfigurationId();
var providerConfig = WebAppUtils.getWebAuthApplication()
var providerConfig = ServletAppUtils.getAuthApplication()
.getAuthConfiguration()
.getAuthProviderConfiguration(providerConfigId);
if (authProviderExternal != null) {
@@ -194,7 +194,8 @@ public class WebSessionAuthProcessor {
}
private boolean isProviderEnabled(@NotNull String providerId) {
WebAuthConfiguration appConfiguration = (WebAuthConfiguration) WebAppUtils.getWebApplication().getAppConfiguration();
ServletAuthConfiguration appConfiguration = (ServletAuthConfiguration) ServletAppUtils.getServletApplication()
.getAppConfiguration();
return appConfiguration.isAuthProviderEnabled(providerId);
}
}
@@ -17,7 +17,7 @@
package io.cloudbeaver.model.session;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.user.WebUser;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
@@ -50,7 +50,7 @@ import java.util.stream.Collectors;
public class WebUserContext implements SMCredentialsProvider {
private static final Log log = Log.getLog(WebUserContext.class);
private final WebApplication application;
private final ServletApplication application;
private final DBPWorkspace workspace;
private WebUser user;
@@ -67,7 +67,7 @@ public class WebUserContext implements SMCredentialsProvider {
private Set<String> accessibleProjectIds = new HashSet<>();
private final WebSessionPreferenceStore preferenceStore;
public WebUserContext(WebApplication application, DBPWorkspace workspace) throws DBException {
public WebUserContext(ServletApplication application, DBPWorkspace workspace) throws DBException {
this.application = application;
this.workspace = workspace;
this.securityController = application.createSecurityController(this);
@@ -19,7 +19,7 @@ package io.cloudbeaver.registry;
import io.cloudbeaver.auth.CBAuthConstants;
import io.cloudbeaver.auth.SMAuthProviderFederated;
import io.cloudbeaver.auth.SMSignOutLinkProvider;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.auth.SMAuthProvider;
@@ -80,7 +80,7 @@ public class WebAuthProviderConfiguration {
}
private String buildRedirectUrl(String baseUrl) {
return baseUrl + "?" + CBAuthConstants.CB_REDIRECT_URL_REQUEST_PARAM + "=" + WebAppUtils.getFullServerUrl();
return baseUrl + "?" + CBAuthConstants.CB_REDIRECT_URL_REQUEST_PARAM + "=" + ServletAppUtils.getFullServerUrl();
}
@Property
@@ -18,7 +18,7 @@
package io.cloudbeaver.registry;
import io.cloudbeaver.DBWFeatureSet;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPImage;
@@ -66,7 +66,7 @@ public class WebFeatureDescriptor extends AbstractContextDescriptor implements D
@Override
public boolean isEnabled() {
return WebAppUtils.getWebApplication().getAppConfiguration().isFeatureEnabled(this.id);
return ServletAppUtils.getServletApplication().getAppConfiguration().isFeatureEnabled(this.id);
}
}
@@ -18,7 +18,6 @@
package io.cloudbeaver.registry;
import io.cloudbeaver.DBWFeatureSet;
import io.cloudbeaver.utils.WebAppUtils;
import org.eclipse.core.runtime.IConfigurationElement;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPImage;
@@ -20,6 +20,8 @@ package io.cloudbeaver.server;
* Various constants
*/
public class CBConstants {
public static final int STATIC_CACHE_SECONDS = 60 * 60 * 24 * 3;
public static final String RUNTIME_DATA_DIR_NAME = ".data";
public static final String RUNTIME_APP_CONFIG_FILE_NAME = ".cloudbeaver.runtime.conf";
public static final String RUNTIME_PRODUCT_CONFIG_FILE_NAME = ".product.runtime.conf";
@@ -17,8 +17,7 @@
package io.cloudbeaver.server;
import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.model.app.ServletApplication;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
@@ -39,18 +38,18 @@ import java.util.Map;
/**
* Web global workspace.
*/
public class WebGlobalWorkspace extends BaseWorkspaceImpl {
public class ServerGlobalWorkspace extends BaseWorkspaceImpl {
private static final Log log = Log.getLog(WebGlobalWorkspace.class);
private static final Log log = Log.getLog(ServerGlobalWorkspace.class);
protected final Map<String, WebProjectImpl> projects = new LinkedHashMap<>();
private WebGlobalProject globalProject;
private final WebApplication application;
private final ServletApplication application;
public WebGlobalWorkspace(
public ServerGlobalWorkspace(
@NotNull DBPPlatform platform,
@NotNull WebApplication application
@NotNull ServletApplication application
) {
super(platform, application.getWorkspaceDirectory());
this.application = application;
@@ -61,7 +60,7 @@ public class WebGlobalWorkspace extends BaseWorkspaceImpl {
initializeWorkspaceSession();
// Load global project
String defaultProjectName = WebAppUtils.getWebApplication().getDefaultProjectName();
String defaultProjectName = application.getDefaultProjectName();
if (CommonUtils.isNotEmpty(defaultProjectName)) {
Path globalProjectPath = getAbsolutePath().resolve(defaultProjectName);
if (!Files.exists(globalProjectPath)) {
@@ -16,7 +16,7 @@
*/
package io.cloudbeaver.server;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.impl.preferences.AbstractPreferenceStore;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
@@ -185,7 +185,7 @@ public class WebServerPreferenceStore extends AbstractPreferenceStore {
}
private Map<String, Object> productConf() {
var app = WebAppUtils.getWebApplication();
var app = ServletAppUtils.getServletApplication();
return app.getServerConfiguration().getProductSettings();
}
}
@@ -16,14 +16,14 @@
*/
package io.cloudbeaver.service;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import org.jkiss.dbeaver.DBException;
/**
* Servlet service
*/
public interface DBWServiceBindingServlet<APPLICATION extends WebApplication> extends DBWServiceBinding {
default boolean isApplicable(WebApplication application) {
public interface DBWServiceBindingServlet<APPLICATION extends ServletApplication> extends DBWServiceBinding {
default boolean isApplicable(ServletApplication application) {
return true;
}
@@ -16,9 +16,9 @@
*/
package io.cloudbeaver.service;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebServerConfiguration;
import io.cloudbeaver.model.app.ServletAppConfiguration;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.ServletServerConfiguration;
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
@@ -30,16 +30,16 @@ import org.jkiss.dbeaver.DBException;
public interface DBWServiceServerConfigurator extends DBWServiceBinding {
void configureServer(
@NotNull WebApplication application,
@NotNull ServletApplication application,
@Nullable WebSession session,
@NotNull WebServerConfiguration serverConfiguration,
@NotNull WebAppConfiguration appConfig
@NotNull ServletServerConfiguration serverConfiguration,
@NotNull ServletAppConfiguration appConfig
) throws DBException;
default void migrateConfigurationIfNeeded(@NotNull WebApplication application) throws DBException {
default void migrateConfigurationIfNeeded(@NotNull ServletApplication application) throws DBException {
}
void reloadConfiguration(@NotNull WebAppConfiguration appConfig) throws DBException;
void reloadConfiguration(@NotNull ServletAppConfiguration appConfig) throws DBException;
}
@@ -19,8 +19,8 @@ package io.cloudbeaver.utils;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.model.session.WebSession;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
@@ -41,8 +41,8 @@ import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class WebAppUtils {
private static final Log log = Log.getLog(WebAppUtils.class);
public class ServletAppUtils {
private static final Log log = Log.getLog(ServletAppUtils.class);
public static String getRelativePath(String path, String curDir) {
return getRelativePath(path, Path.of(curDir));
@@ -55,19 +55,19 @@ public class WebAppUtils {
return curDir.resolve(path).toAbsolutePath().toString();
}
public static WebApplication getWebApplication() {
return (WebApplication) DBWorkbench.getPlatform().getApplication();
public static ServletApplication getServletApplication() {
return (ServletApplication) DBWorkbench.getPlatform().getApplication();
}
public static WebAuthApplication getWebAuthApplication() throws DBException {
WebApplication application = getWebApplication();
if (!WebAuthApplication.class.isAssignableFrom(application.getClass())) {
public static ServletAuthApplication getAuthApplication() throws DBException {
ServletApplication application = getServletApplication();
if (!ServletAuthApplication.class.isAssignableFrom(application.getClass())) {
throw new DBException("The current application doesn't contain authorization configuration");
}
return (WebAuthApplication) application;
return (ServletAuthApplication) application;
}
public static SMAuthenticationManager getAuthManager(WebApplication application) throws DBException {
public static SMAuthenticationManager getAuthManager(ServletApplication application) throws DBException {
var smController = application.createSecurityController(new NoAuthCredentialsProvider());
if (!SMAuthenticationManager.class.isAssignableFrom(smController.getClass())) {
throw new DBException("The current application cannot be used for authorization");
@@ -169,11 +169,11 @@ public class WebAppUtils {
@NotNull
public static StringBuilder getAuthApiPrefix(String serviceId) throws DBException {
return getAuthApiPrefix(getWebAuthApplication(), serviceId);
return getAuthApiPrefix(getAuthApplication(), serviceId);
}
@NotNull
public static StringBuilder getAuthApiPrefix(WebAuthApplication webAuthApplication, String serviceId) {
public static StringBuilder getAuthApiPrefix(ServletAuthApplication webAuthApplication, String serviceId) {
String authUrl = removeSideSlashes(webAuthApplication.getAuthServiceURL());
StringBuilder apiPrefix = new StringBuilder(authUrl);
apiPrefix.append("/").append(serviceId).append("/");
@@ -190,7 +190,7 @@ public class WebAppUtils {
sessionCookie.setMaxAge((int) (maxSessionIdleTime / 1000));
}
String path = getWebApplication().getServerConfiguration().getRootURI();
String path = getServletApplication().getServerConfiguration().getRootURI();
if (sameSite != null) {
if (!request.isSecure()) {
@@ -223,7 +223,7 @@ public class WebAppUtils {
}
public static String getGlobalProjectId() {
String globalConfigurationName = getWebApplication().getDefaultProjectName();
String globalConfigurationName = getServletApplication().getDefaultProjectName();
return RMProjectType.GLOBAL.getPrefix() + "_" + globalConfigurationName;
}
@@ -273,9 +273,9 @@ public class WebAppUtils {
@NotNull
public static String getFullServerUrl() {
WebApplication application = WebAppUtils.getWebApplication();
ServletApplication application = ServletAppUtils.getServletApplication();
return Stream.of(application.getServerURL(), application.getRootURI())
.map(WebAppUtils::removeSideSlashes)
.map(ServletAppUtils::removeSideSlashes)
.filter(CommonUtils::isNotEmpty)
.collect(Collectors.joining("/"));
}
@@ -80,7 +80,7 @@ public class WebEventUtils {
if (event == null) {
return;
}
WebAppUtils.getWebApplication().getEventController().addEvent(event);
ServletAppUtils.getServletApplication().getEventController().addEvent(event);
}
public static void addNavigatorNodeUpdatedEvent(
@@ -122,7 +122,7 @@ public class WebEventUtils {
if (event == null) {
return;
}
WebAppUtils.getWebApplication().getEventController().addEvent(event);
ServletAppUtils.getServletApplication().getEventController().addEvent(event);
}
public static void addRmResourceUpdatedEvent(
@@ -179,7 +179,7 @@ public class WebEventUtils {
if (event == null) {
return;
}
WebAppUtils.getWebApplication().getEventController().addEvent(event);
ServletAppUtils.getServletApplication().getEventController().addEvent(event);
}
}
@@ -8,5 +8,5 @@ Bundle-Release-Date: 20241223
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Require-Bundle: io.cloudbeaver.server
Require-Bundle: io.cloudbeaver.server.ce
Automatic-Module-Name: io.cloudbeaver.product.ce
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Vendor: DBeaver Corp
Bundle-Name: Cloudbeaver CE Server
Bundle-SymbolicName: io.cloudbeaver.server.ce;singleton:=true
Bundle-Version: 24.3.1.qualifier
Bundle-Release-Date: 20241104
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Activator: io.cloudbeaver.server.CBPlatformActivator
Bundle-ClassPath: .
Require-Bundle: io.cloudbeaver.server;visibility:=reexport
Export-Package: io.cloudbeaver,
io.cloudbeaver.model,
io.cloudbeaver.model.config,
io.cloudbeaver.server,
io.cloudbeaver.service,
io.cloudbeaver.service.session
Import-Package: org.slf4j
Automatic-Module-Name: io.cloudbeaver.server.ce
@@ -0,0 +1,6 @@
source..=src/
output..=target/classes/
bin.includes=.,\
META-INF/,\
schema/,\
plugin.xml
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<plugin>
<extension point="org.jkiss.dbeaver.dataSourceHandler">
<handler id="db.access.check" class="io.cloudbeaver.model.WebDatasourceAccessCheckHandler"/>
</extension>
<extension point="io.cloudbeaver.service">
<service id="core_ce" label="Core service" description="Core services" class="io.cloudbeaver.service.core.CECoreModelExtender"/>
</extension>
<extension point="org.jkiss.dbeaver.ws.event.handler">
<eventHandler class="io.cloudbeaver.server.events.WSUserEventHandler">
<topic id="cb_user"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSSubjectPermissionUpdatedEventHandler">
<topic id="cb_subject_permissions"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSUserSecretEventHandlerImpl">
<topic id="cb_user_secret"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSObjectPermissionUpdatedEventHandler">
<topic id="cb_object_permissions"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSRmResourceUpdatedEventHandlerImpl">
<topic id="cb_scripts"/>
</eventHandler>
</extension>
</plugin>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.cloudbeaver</groupId>
<artifactId>bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>io.cloudbeaver.server.ce</artifactId>
<version>24.3.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
@@ -0,0 +1,16 @@
extend type ServerConfig {
serverURL: String!
rootURI: String!
hostName: String! @deprecated # use container id instead
containerId: String!
defaultAuthRole: String
defaultUserTeam: String # [23.2.2]
sessionExpireTime: Int!
localHostAddress: String
redirectOnFederatedAuth: Boolean!
enabledAuthProviders: [ID!]!
passwordPolicyConfiguration: PasswordPolicyConfig! @since(version: "23.3.3")
}
@@ -0,0 +1,89 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.model;
import io.cloudbeaver.model.config.PasswordPolicyConfiguration;
import io.cloudbeaver.server.CBApplication;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.utils.CommonUtils;
public class CBWebServerConfig extends WebServerConfig {
private final CBApplication<?> cbApp;
public CBWebServerConfig(@NotNull CBApplication<?> cbApp) {
super(cbApp);
this.cbApp = cbApp;
}
@Property
public String getServerURL() {
return CommonUtils.notEmpty(cbApp.getServerConfiguration().getServerURL());
}
@Property
public String getRootURI() {
return CommonUtils.notEmpty(cbApp.getServerConfiguration().getRootURI());
}
@Deprecated
@Property
public String getHostName() {
return getContainerId();
}
@Property
public String getContainerId() {
return CommonUtils.notEmpty(cbApp.getContainerId());
}
@Property
public boolean isRedirectOnFederatedAuth() {
return cbApp.getAppConfiguration().isRedirectOnFederatedAuth();
}
@Property
public String getLocalHostAddress() {
return cbApp.getLocalHostAddress();
}
@Property
public long getSessionExpireTime() {
return cbApp.getServerConfiguration().getMaxSessionIdleTime();
}
@Property
public String[] getEnabledAuthProviders() {
return cbApp.getAppConfiguration().getEnabledAuthProviders();
}
@Property
public String getDefaultAuthRole() {
return cbApp.getDefaultAuthRole();
}
@Property
public String getDefaultUserTeam() {
return cbApp.getAppConfiguration().getDefaultUserTeam();
}
@Property
public PasswordPolicyConfiguration getPasswordPolicyConfiguration() {
return cbApp.getSecurityManagerConfiguration().getPasswordPolicyConfiguration();
}
}
@@ -20,14 +20,13 @@ package io.cloudbeaver.model;
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.utils.ConfigurationUtils;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
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()) {
if (!ServletAppUtils.getServletApplication().isMultiuser()) {
return false;
}
CBAppConfig config = CBApplication.getInstance().getAppConfiguration();
@@ -18,9 +18,11 @@ package io.cloudbeaver.server;
import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.model.app.BaseWebApplication;
import io.cloudbeaver.model.app.WebAuthApplication;
import io.cloudbeaver.model.app.WebAuthConfiguration;
import io.cloudbeaver.model.CBWebServerConfig;
import io.cloudbeaver.model.WebServerConfig;
import io.cloudbeaver.model.app.BaseServletApplication;
import io.cloudbeaver.model.app.ServletAuthApplication;
import io.cloudbeaver.model.app.ServletAuthConfiguration;
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.config.CBServerConfig;
import io.cloudbeaver.model.config.SMControllerConfiguration;
@@ -29,7 +31,7 @@ import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.jetty.CBJettyServer;
import io.cloudbeaver.service.DBWServiceInitializer;
import io.cloudbeaver.service.DBWServiceServerConfigurator;
import io.cloudbeaver.service.session.WebSessionManager;
import io.cloudbeaver.service.session.CBSessionManager;
import io.cloudbeaver.utils.WebDataSourceUtils;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.service.datalocation.Location;
@@ -74,7 +76,7 @@ import java.util.concurrent.ConcurrentHashMap;
* This class controls all aspects of the application's execution
*/
public abstract class CBApplication<T extends CBServerConfig> extends
BaseWebApplication implements WebAuthApplication, GQLApplicationAdapter {
BaseServletApplication implements ServletAuthApplication, WebApplication {
private static final Log log = Log.getLog(CBApplication.class);
@@ -105,7 +107,7 @@ public abstract class CBApplication<T extends CBServerConfig> extends
protected final WSEventController eventController = new WSEventController();
private WebSessionManager sessionManager;
private CBSessionManager sessionManager;
private final Map<String, String> initActions = new ConcurrentHashMap<>();
@@ -175,7 +177,7 @@ public abstract class CBApplication<T extends CBServerConfig> extends
}
@Override
public WebAuthConfiguration getAuthConfiguration() {
public ServletAuthConfiguration getAuthConfiguration() {
return getAppConfiguration();
}
@@ -660,15 +662,15 @@ public abstract class CBApplication<T extends CBServerConfig> extends
return null;
}
public WebSessionManager getSessionManager() {
public CBSessionManager getSessionManager() {
if (sessionManager == null) {
sessionManager = createSessionManager();
}
return sessionManager;
}
protected WebSessionManager createSessionManager() {
return new WebSessionManager(this);
protected CBSessionManager createSessionManager() {
return new CBSessionManager(this);
}
@NotNull
@@ -709,7 +711,7 @@ public abstract class CBApplication<T extends CBServerConfig> extends
@Override
public Class<? extends DBPPlatformUI> getPlatformUIClass() {
return CBPlatformUI.class;
return ServletPlatformUI.class;
}
public void saveProductConfiguration(
@@ -765,4 +767,9 @@ public abstract class CBApplication<T extends CBServerConfig> extends
public Map<String, String> getInitActions() {
return Map.copyOf(initActions);
}
@Override
public WebServerConfig getWebServerConfig() {
return new CBWebServerConfig(this);
}
}
@@ -17,6 +17,8 @@
package io.cloudbeaver.server;
import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.model.CBWebServerConfig;
import io.cloudbeaver.model.WebServerConfig;
import io.cloudbeaver.model.config.CBServerConfig;
import io.cloudbeaver.model.rm.local.LocalResourceController;
import io.cloudbeaver.service.security.CBEmbeddedSecurityController;
@@ -114,5 +116,4 @@ public class CBApplicationCE extends CBApplication<CBServerConfig> {
embeddedSecurityController.finishConfiguration(adminName, adminPassword, authInfoList);
}
}
}
@@ -21,7 +21,7 @@ import io.cloudbeaver.auth.NoAuthCredentialsProvider;
import io.cloudbeaver.server.jobs.SessionStateJob;
import io.cloudbeaver.server.jobs.WebDataSourceMonitorJob;
import io.cloudbeaver.server.jobs.WebSessionMonitorJob;
import io.cloudbeaver.service.session.WebSessionManager;
import io.cloudbeaver.service.session.CBSessionManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jkiss.code.NotNull;
@@ -47,17 +47,15 @@ import java.util.stream.Collectors;
/**
* CBPlatform
*/
public class CBPlatform extends BaseGQLPlatform {
public class CBPlatform extends BaseWebPlatform {
// The plug-in ID
public static final String PLUGIN_ID = "io.cloudbeaver.server"; //$NON-NLS-1$
private static final Log log = Log.getLog(CBPlatform.class);
public static final String TEMP_FILE_FOLDER = "temp-sql-upload-files";
public static final String TEMP_FILE_IMPORT_FOLDER = "temp-import-files";
@Nullable
private static GQLApplicationAdapter application = null;
private static CBApplication<?> application = null;
private WebServerPreferenceStore preferenceStore;
protected final List<DBPDriver> applicableDrivers = new ArrayList<>();
@@ -69,7 +67,7 @@ public class CBPlatform extends BaseGQLPlatform {
protected CBPlatform() {
}
public static void setApplication(@NotNull GQLApplicationAdapter application) {
public static void setApplication(@NotNull CBApplication<?> application) {
CBPlatform.application = application;
}
@@ -86,15 +84,13 @@ public class CBPlatform extends BaseGQLPlatform {
}
protected void scheduleServerJobs() {
if (getSessionManager() instanceof WebSessionManager webSessionManager) {
new WebSessionMonitorJob(this, webSessionManager)
.scheduleMonitor();
new WebSessionMonitorJob(this, application.getSessionManager())
.scheduleMonitor();
new SessionStateJob(this, webSessionManager)
.scheduleMonitor();
}
new SessionStateJob(this, application.getSessionManager())
.scheduleMonitor();
new WebDataSourceMonitorJob(this, getSessionManager())
new WebDataSourceMonitorJob(this, application.getSessionManager())
.scheduleMonitor();
new AbstractJob("Delete temp folder") {
@@ -124,7 +120,7 @@ public class CBPlatform extends BaseGQLPlatform {
@NotNull
@Override
public GQLApplicationAdapter getApplication() {
public CBApplication<?> getApplication() {
return application;
}
@@ -144,10 +140,6 @@ public class CBPlatform extends BaseGQLPlatform {
return false;
}
public AppWebSessionManager getSessionManager() {
return application.getSessionManager();
}
public void refreshApplicableDrivers() {
this.applicableDrivers.clear();
@@ -18,12 +18,12 @@ package io.cloudbeaver.server;
import com.google.gson.*;
import io.cloudbeaver.model.app.BaseServerConfigurationController;
import io.cloudbeaver.model.app.BaseWebApplication;
import io.cloudbeaver.model.app.BaseServletApplication;
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.config.CBServerConfig;
import io.cloudbeaver.model.config.PasswordPolicyConfiguration;
import io.cloudbeaver.model.config.SMControllerConfiguration;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
@@ -76,7 +76,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
return Stream.of(serverConfiguration.getServerURL(),
serverConfiguration.getRootURI(),
serverConfiguration.getServicesURI())
.map(WebAppUtils::removeSideSlashes)
.map(ServletAppUtils::removeSideSlashes)
.filter(CommonUtils::isNotEmpty)
.collect(Collectors.joining("/"));
}
@@ -139,7 +139,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
Gson gson = getGson();
Map<String, Object> currentConfigurationAsMap = gson.fromJson(gson.toJson(getServerConfiguration()),
JSONUtils.MAP_TYPE_TOKEN);
serverConfig = WebAppUtils.mergeConfigurations(currentConfigurationAsMap, serverConfig);
serverConfig = ServletAppUtils.mergeConfigurations(currentConfigurationAsMap, serverConfig);
gson.fromJson(
gson.toJson(serverConfig),
getServerConfiguration().getClass()
@@ -174,9 +174,9 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
config.setServerURL("http://" + hostName + ":" + config.getServerPort());
}
config.setContentRoot(WebAppUtils.getRelativePath(config.getContentRoot(), homeDirectory));
config.setContentRoot(ServletAppUtils.getRelativePath(config.getContentRoot(), homeDirectory));
config.setRootURI(readRootUri(config.getRootURI()));
config.setDriversLocation(WebAppUtils.getRelativePath(config.getDriversLocation(), homeDirectory));
config.setDriversLocation(ServletAppUtils.getRelativePath(config.getDriversLocation(), homeDirectory));
String staticContentsFile = config.getStaticContent();
if (!CommonUtils.isEmpty(staticContentsFile)) {
@@ -231,7 +231,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
if (!serverConfig.containsKey(CBConstants.PARAM_PRODUCT_SETTINGS)
&& serverConfig.get(CBConstants.PARAM_PRODUCT_CONFIGURATION) instanceof String
) {
String productConfigPath = WebAppUtils.getRelativePath(
String productConfigPath = ServletAppUtils.getRelativePath(
JSONUtils.getString(
serverConfig,
CBConstants.PARAM_PRODUCT_CONFIGURATION,
@@ -248,7 +248,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
try (Reader reader = new InputStreamReader(new FileInputStream(productConfigFile),
StandardCharsets.UTF_8)) {
serverConfiguration.getProductSettings()
.putAll(WebAppUtils.flattenMap(JSONUtils.parseMap(gson, reader)));
.putAll(ServletAppUtils.flattenMap(JSONUtils.parseMap(gson, reader)));
} catch (Exception e) {
throw new DBException("Error reading product configuration", e);
}
@@ -265,7 +265,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
var runtimeProductSettings = JSONUtils.parseMap(gson, reader);
var productSettings = serverConfiguration.getProductSettings();
runtimeProductSettings.putAll(productSettings);
Map<String, Object> flattenConfig = WebAppUtils.flattenMap(runtimeProductSettings);
Map<String, Object> flattenConfig = ServletAppUtils.flattenMap(runtimeProductSettings);
productSettings.clear();
productSettings.putAll(flattenConfig);
} catch (Exception e) {
@@ -276,7 +276,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
}
protected Map<String, Object> readConnectionsPermissionsConfiguration(Path parentPath) {
String permissionsConfigPath = WebAppUtils.getRelativePath(CBConstants.DEFAULT_DATASOURCE_PERMISSIONS_CONFIGURATION,
String permissionsConfigPath = ServletAppUtils.getRelativePath(CBConstants.DEFAULT_DATASOURCE_PERMISSIONS_CONFIGURATION,
parentPath);
File permissionsConfigFile = new File(permissionsConfigPath);
if (permissionsConfigFile.exists()) {
@@ -301,7 +301,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
if (originalConfigurationProperties.isEmpty()) {
originalConfigurationProperties.putAll(configProps);
} else {
var mergedOriginalConfigs = WebAppUtils.mergeConfigurations(
var mergedOriginalConfigs = ServletAppUtils.mergeConfigurations(
originalConfigurationProperties,
configProps
);
@@ -394,7 +394,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
) {
Map<String, Object> rootConfig = new LinkedHashMap<>();
{
var originServerConfig = BaseWebApplication.getServerConfigProps(this.originalConfigurationProperties); // get server properties from original configuration file
var originServerConfig = BaseServletApplication.getServerConfigProps(this.originalConfigurationProperties); // get server properties from original configuration file
var serverConfigProperties = collectServerConfigProperties(serverConfig, originServerConfig);
rootConfig.put("server", serverConfigProperties);
}
@@ -560,7 +560,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
return super.get(name);
}
};
BaseWebApplication.patchConfigurationWithProperties(configProps, varResolver);
BaseServletApplication.patchConfigurationWithProperties(configProps, varResolver);
}
// gets info about patterns from original configuration file and saves it to runtime config
@@ -583,7 +583,7 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
}
newConfig.put(key, subValue);
} else {
Object newConfigValue = WebAppUtils.getExtractedValue(oldConfig.get(key), defaultValue);
Object newConfigValue = ServletAppUtils.getExtractedValue(oldConfig.get(key), defaultValue);
newConfig.put(key, newConfigValue);
}
}
@@ -613,9 +613,9 @@ public abstract class CBServerConfigurationController<T extends CBServerConfig>
public void saveProductConfiguration(Map<String, Object> productConfiguration) throws DBException {
Map<String, Object> productSettings = getServerConfiguration().getProductSettings();
Map<String, Object> mergedConfig = WebAppUtils.mergeConfigurations(productSettings, productConfiguration);
Map<String, Object> mergedConfig = ServletAppUtils.mergeConfigurations(productSettings, productConfiguration);
productSettings.clear();
productSettings.putAll(WebAppUtils.flattenMap(mergedConfig));
productSettings.putAll(ServletAppUtils.flattenMap(mergedConfig));
}
public T getServerConfiguration() {
@@ -22,7 +22,7 @@ import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
@@ -66,7 +66,7 @@ public class WSObjectPermissionUpdatedEventHandler extends WSDefaultEventHandler
return;
}
log.debug(event.getTopicId() + " event handled");
Collection<BaseWebSession> allSessions = CBPlatform.getInstance().getSessionManager().getAllActiveSessions();
Collection<BaseWebSession> allSessions = CBApplication.getInstance().getSessionManager().getAllActiveSessions();
for (var activeUserSession : allSessions) {
if (!isAcceptableInSession(activeUserSession, event)) {
log.debug("Cannot handle %s event '%s' in session %s".formatted(
@@ -103,7 +103,7 @@ public class WSObjectPermissionUpdatedEventHandler extends WSDefaultEventHandler
List<String> dataSources = List.of(dataSourceId);
WebSessionGlobalProjectImpl project = webSession.getGlobalProject();
if (project == null) {
log.error("Project " + WebAppUtils.getGlobalProjectId() +
log.error("Project " + ServletAppUtils.getGlobalProjectId() +
" is not found in session " + activeUserSession.getSessionId());
return;
}
@@ -16,8 +16,8 @@
*/
package io.cloudbeaver.server.events;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.service.session.WebSessionManager;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.websocket.WSEventHandler;
import org.jkiss.dbeaver.model.websocket.event.WSAbstractEvent;
@@ -32,11 +32,7 @@ public class WSUserEventHandler<EVENT extends WSAbstractEvent> implements WSEven
if (eventType == null) {
return;
}
var appSessionManager = CBPlatform.getInstance().getSessionManager();
if (!(appSessionManager instanceof WebSessionManager)) {
return;
}
var sessionManager = (WebSessionManager) appSessionManager;
var sessionManager = CBApplication.getInstance().getSessionManager();
switch (eventType) {
case CLOSE_USER_SESSIONS:
if (event instanceof WSUserCloseSessionsEvent closeSessionsEvent) {
@@ -19,11 +19,12 @@ package io.cloudbeaver.server.jetty;
import io.cloudbeaver.model.config.CBServerConfig;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.GQLApplicationAdapter;
import io.cloudbeaver.server.CBConstants;
import io.cloudbeaver.server.WebApplication;
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
import io.cloudbeaver.server.servlets.CBImageServlet;
import io.cloudbeaver.server.servlets.CBStaticServlet;
import io.cloudbeaver.server.servlets.CBStatusServlet;
import io.cloudbeaver.server.servlets.WebStatusServlet;
import io.cloudbeaver.server.websockets.CBJettyWebSocketManager;
import io.cloudbeaver.service.DBWServiceBindingServlet;
import io.cloudbeaver.service.DBWServiceBindingWebSocket;
@@ -104,7 +105,8 @@ public class CBJettyServer {
"static", new CBStaticServlet(Path.of(serverConfiguration.getContentRoot()))
);
staticServletHolder.setInitParameter("dirAllowed", "false");
staticServletHolder.setInitParameter("cacheControl", "public, max-age=" + CBStaticServlet.STATIC_CACHE_SECONDS);
staticServletHolder.setInitParameter("cacheControl",
"public, max-age=" + CBConstants.STATIC_CACHE_SECONDS);
servletContextHandler.addServlet(staticServletHolder, "/");
if (Files.isSymbolicLink(contentRootPath)) {
@@ -114,7 +116,7 @@ public class CBJettyServer {
ServletHolder imagesServletHolder = new ServletHolder("images", new CBImageServlet());
servletContextHandler.addServlet(imagesServletHolder, serverConfiguration.getServicesURI() + "images/*");
servletContextHandler.addServlet(new ServletHolder("status", new CBStatusServlet()), "/status");
servletContextHandler.addServlet(new ServletHolder("status", new WebStatusServlet()), "/status");
servletContextHandler.addServlet(new ServletHolder("graphql", new GraphQLEndpoint()), serverConfiguration.getServicesURI() + "gql/*");
servletContextHandler.addEventListener(new CBServerContextListener(application));
@@ -135,7 +137,7 @@ public class CBJettyServer {
}
CBJettyWebSocketContext webSocketContext = new CBJettyWebSocketContext(server, servletContextHandler);
for (DBWServiceBindingWebSocket wsb : WebServiceRegistry.getInstance()
for (DBWServiceBindingWebSocket<CBApplication> wsb : WebServiceRegistry.getInstance()
.getWebServices(DBWServiceBindingWebSocket.class)
) {
if (wsb.isApplicable(this.application)) {
@@ -158,7 +160,7 @@ public class CBJettyServer {
);
servletContextHandler.insertHandler(webSocketHandler);
initSessionManager(
JettyUtils.initSessionManager(
this.application.getMaxSessionIdleTime(),
this.application,
server,
@@ -216,35 +218,6 @@ public class CBJettyServer {
return sslConfiguration.isAbsolute() ? sslConfiguration : application.getHomeDirectory().resolve(sslConfiguration);
}
public static void initSessionManager(
long maxIdleTime,
@NotNull GQLApplicationAdapter application,
@NotNull Server server,
@NotNull ServletContextHandler servletContextHandler
) {
// Init sessions persistence
CBSessionHandler sessionHandler = new CBSessionHandler(application);
sessionHandler.setRefreshCookieAge(CBSessionHandler.ONE_MINUTE);
int intMaxIdleSeconds;
if (maxIdleTime > Integer.MAX_VALUE) {
log.warn("Max session idle time value is greater than Integer.MAX_VALUE. Integer.MAX_VALUE will be used instead");
maxIdleTime = Integer.MAX_VALUE;
}
intMaxIdleSeconds = (int) (maxIdleTime / 1000);
log.debug("Max http session idle time: " + intMaxIdleSeconds + "s");
sessionHandler.setMaxInactiveInterval(intMaxIdleSeconds);
sessionHandler.setMaxCookieAge(intMaxIdleSeconds);
DefaultSessionCache sessionCache = new DefaultSessionCache(sessionHandler);
sessionCache.setSessionDataStore(new NullSessionDataStore());
sessionHandler.setSessionCache(sessionCache);
servletContextHandler.setSessionHandler(sessionHandler);
DefaultSessionIdManager idMgr = new DefaultSessionIdManager(server);
idMgr.setWorkerName(null);
server.addBean(idMgr, true);
}
public synchronized void refreshJettyConfig() {
if (server == null) {
return;
@@ -16,7 +16,7 @@
*/
package io.cloudbeaver.server.jobs;
import io.cloudbeaver.service.session.WebSessionManager;
import io.cloudbeaver.service.session.CBSessionManager;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.app.DBPPlatform;
@@ -27,9 +27,9 @@ import java.time.Duration;
public class SessionStateJob extends PeriodicJob {
private static final Log log = Log.getLog(SessionStateJob.class);
private final WebSessionManager sessionManager;
private final CBSessionManager sessionManager;
public SessionStateJob(@NotNull DBPPlatform platform, WebSessionManager sessionManager) {
public SessionStateJob(@NotNull DBPPlatform platform, CBSessionManager sessionManager) {
super("Session state sender", platform, Duration.ofSeconds(30));
this.sessionManager = sessionManager;
}
@@ -16,7 +16,7 @@
*/
package io.cloudbeaver.server.jobs;
import io.cloudbeaver.service.session.WebSessionManager;
import io.cloudbeaver.service.session.CBSessionManager;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.app.DBPPlatform;
@@ -30,9 +30,9 @@ import java.time.Duration;
*/
public class WebSessionMonitorJob extends PeriodicJob {
private static final Log log = Log.getLog(WebSessionMonitorJob.class);
private final WebSessionManager sessionManager;
private final CBSessionManager sessionManager;
public WebSessionMonitorJob(@NotNull DBPPlatform platform, @NotNull WebSessionManager sessionManager) {
public WebSessionMonitorJob(@NotNull DBPPlatform platform, @NotNull CBSessionManager sessionManager) {
super("Web session monitor", platform, Duration.ofSeconds(10));
this.sessionManager = sessionManager;
}
@@ -60,7 +60,6 @@ public class CBStaticServlet extends DefaultServlet {
private static final String AUTO_LOGIN_ACTION = "auto-login";
private static final String AUTO_LOGIN_AUTH_ID = "auth-id";
private static final String ACTION = "action";
public static final int STATIC_CACHE_SECONDS = 60 * 60 * 24 * 3;
private static final Log log = Log.getLog(CBStaticServlet.class);
@@ -84,7 +83,7 @@ public class CBStaticServlet extends DefaultServlet {
}
String uri = request.getPathInfo();
try {
WebSession webSession = CBPlatform.getInstance().getSessionManager().getWebSession(
WebSession webSession = CBApplication.getInstance().getSessionManager().getWebSession(
request, response, false);
performAutoLoginIfNeeded(request, webSession);
WebActionParameters webActionParameters = WebActionParameters.fromSession(webSession, false);
@@ -0,0 +1,35 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.core;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.WebServiceBindingBase;
/**
* extends the base gql model, to avoid unnecessary fields in other applications
*/
public class CECoreModelExtender extends WebServiceBindingBase<DBWVoidService> {
public CECoreModelExtender() {
super(DBWVoidService.class, new DBWVoidService(), "schema/service.core.graphqls");
}
@Override
public void bindWiring(DBWBindingContext model) throws DBWebException {
}
}
@@ -0,0 +1,22 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.core;
import io.cloudbeaver.service.DBWService;
public class DBWVoidService implements DBWService {
}
@@ -21,9 +21,9 @@ import io.cloudbeaver.auth.SMTokenCredentialProvider;
import io.cloudbeaver.model.session.*;
import io.cloudbeaver.registry.WebHandlerRegistry;
import io.cloudbeaver.registry.WebSessionHandlerDescriptor;
import io.cloudbeaver.server.AppWebSessionManager;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBConstants;
import io.cloudbeaver.server.WebAppSessionManager;
import io.cloudbeaver.server.events.WSWebUtils;
import io.cloudbeaver.service.DBWSessionHandler;
import jakarta.servlet.http.HttpServletRequest;
@@ -48,14 +48,14 @@ import java.util.stream.Collectors;
/**
* Web session manager
*/
public class WebSessionManager implements AppWebSessionManager {
public class CBSessionManager implements WebAppSessionManager {
private static final Log log = Log.getLog(WebSessionManager.class);
private static final Log log = Log.getLog(CBSessionManager.class);
private final CBApplication application;
private final Map<String, BaseWebSession> sessionMap = new HashMap<>();
public WebSessionManager(CBApplication application) {
public CBSessionManager(CBApplication application) {
this.application = application;
}
@@ -7,7 +7,6 @@ Bundle-Version: 24.3.1.qualifier
Bundle-Release-Date: 20241223
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Activator: io.cloudbeaver.server.CBPlatformActivator
Bundle-ClassPath: .
Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
org.apache.commons.jexl,
@@ -23,6 +22,7 @@ Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
io.cloudbeaver.service.security;visibility:=reexport
Export-Package: io.cloudbeaver,
io.cloudbeaver.model,
io.cloudbeaver.model.app,
io.cloudbeaver.model.user,
io.cloudbeaver.registry,
io.cloudbeaver.server.events,
@@ -32,10 +32,9 @@ Export-Package: io.cloudbeaver,
io.cloudbeaver.server.graphql,
io.cloudbeaver.server.jobs,
io.cloudbeaver.server.servlets,
io.cloudbeaver.server.websockets,
io.cloudbeaver.server.websockets,
io.cloudbeaver.service,
io.cloudbeaver.service.navigator,
io.cloudbeaver.service.session,
io.cloudbeaver.service.sql
Import-Package: org.slf4j
Automatic-Module-Name: io.cloudbeaver.server
@@ -29,9 +29,6 @@
</service>
</extension>
<extension point="org.jkiss.dbeaver.dataSourceHandler">
<handler id="db.access.check" class="io.cloudbeaver.model.WebDatasourceAccessCheckHandler"/>
</extension>
<extension point="io.cloudbeaver.valueSerializer">
<serializer type="geometry" class="io.cloudbeaver.server.data.WebGeometryValueSerializer"/>
</extension>
@@ -46,21 +43,9 @@
<eventHandler class="io.cloudbeaver.server.events.WSFolderUpdatedEventHandlerImpl">
<topic id="cb_datasource_folder"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSRmResourceUpdatedEventHandlerImpl">
<topic id="cb_scripts"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSObjectPermissionUpdatedEventHandler">
<topic id="cb_object_permissions"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSSubjectPermissionUpdatedEventHandler">
<topic id="cb_subject_permissions"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSProjectUpdatedEventHandler">
<topic id="cb_projects"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSUserSecretEventHandlerImpl">
<topic id="cb_user_secret"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSLogEventHandler">
<topic id="cb_session_log"/>
</eventHandler>
@@ -70,9 +55,6 @@
<eventHandler class="io.cloudbeaver.server.events.WSDeleteTempFileHandler">
<topic id="cb_delete_temp_folder"/>
</eventHandler>
<eventHandler class="io.cloudbeaver.server.events.WSUserEventHandler">
<topic id="cb_user"/>
</eventHandler>
</extension>
<extension point="org.jkiss.dbeaver.settings">
@@ -126,17 +126,8 @@ type ServerConfig {
version: String!
workspaceId: ID!
serverURL: String!
rootURI: String!
hostName: String! @deprecated # use container id instead
containerId: String!
defaultAuthRole: String
defaultUserTeam: String # [23.2.2]
anonymousAccessEnabled: Boolean!
supportsCustomConnections: Boolean!
supportsConnectionBrowser: Boolean!
supportsWorkspaces: Boolean!
resourceManagerEnabled: Boolean!
publicCredentialsSaveEnabled: Boolean!
@@ -146,19 +137,14 @@ type ServerConfig {
licenseValid: Boolean!
licenseStatus: String @since(version: "24.1.5")
sessionExpireTime: Int!
localHostAddress: String
configurationMode: Boolean!
# initializationMode: Boolean! @since(version: "24.1.5")
developmentMode: Boolean!
redirectOnFederatedAuth: Boolean!
distributed: Boolean!
enabledFeatures: [ID!]!
disabledBetaFeatures: [ID!] @since(version: "24.0.5")
serverFeatures: [ID!] @since(version: "24.3.0")
enabledAuthProviders: [ID!]!
supportedLanguages: [ ServerLanguage! ]!
services: [ WebServiceConfig ]
productConfiguration: Object!
@@ -166,7 +152,6 @@ type ServerConfig {
defaultNavigatorSettings: NavigatorSettings!
disabledDrivers: [ID!]!
resourceQuotas: Object!
passwordPolicyConfiguration: PasswordPolicyConfig! @since(version: "23.3.3")
}
type ProductSettingsGroup @since(version: "24.0.1") {
@@ -23,18 +23,20 @@ import com.google.gson.Strictness;
import io.cloudbeaver.model.WebConnectionConfig;
import io.cloudbeaver.model.WebNetworkHandlerConfigInput;
import io.cloudbeaver.model.WebPropertyInfo;
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebActionParameters;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.registry.WebAuthProviderRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.WebApplication;
import io.cloudbeaver.service.navigator.WebPropertyFilter;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebCommonUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
@@ -135,11 +137,11 @@ public class WebServiceUtils extends WebCommonUtils {
}
((DataSourceDescriptor)newDataSource).setTemplate(config.isTemplate());
// Set default navigator settings
DataSourceNavigatorSettings navSettings = new DataSourceNavigatorSettings(
CBApplication.getInstance().getAppConfiguration().getDefaultNavigatorSettings());
//navSettings.setShowSystemObjects(false);
((DataSourceDescriptor)newDataSource).setNavigatorSettings(navSettings);
ServletApplication app = ServletAppUtils.getServletApplication();
if (app instanceof WebApplication webApplication) {
((DataSourceDescriptor) newDataSource).setNavigatorSettings(
webApplication.getAppConfiguration().getDefaultNavigatorSettings());
}
saveAuthProperties(
newDataSource,
@@ -311,12 +313,6 @@ public class WebServiceUtils extends WebCommonUtils {
gson.toJsonTree(settingsMap), DataSourceNavigatorSettings.class);
}
public static void checkServerConfigured() throws DBWebException {
if (CBApplication.getInstance().isConfigurationMode()) {
throw new DBWebException("Server is in configuration mode");
}
}
public static void fireActionParametersOpenEditor(WebSession webSession, DBPDataSourceContainer dataSource, boolean addEditorName) {
Map<String, Object> actionParameters = new HashMap<>();
actionParameters.put("action", "open-sql-editor");
@@ -341,13 +337,20 @@ public class WebServiceUtils extends WebCommonUtils {
}
public static boolean isGlobalProject(DBPProject project) {
return project.getId().equals(RMProjectType.GLOBAL.getPrefix() + "_" + CBApplication.getInstance().getDefaultProjectName());
return project.getId()
.equals(RMProjectType.GLOBAL.getPrefix() + "_" + ServletAppUtils.getServletApplication()
.getDefaultProjectName());
}
public static List<WebAuthProviderDescriptor> getEnabledAuthProviders() {
List<WebAuthProviderDescriptor> result = new ArrayList<>();
CBAppConfig appConfig = CBApplication.getInstance().getAppConfiguration();
String[] authProviders = appConfig.getEnabledAuthProviders();
String[] authProviders = null;
try {
authProviders = ServletAppUtils.getAuthApplication().getAuthConfiguration().getEnabledAuthProviders();
} catch (DBException e) {
log.error(e.getMessage(), e);
return List.of();
}
for (String apId : authProviders) {
WebAuthProviderDescriptor authProvider = WebAuthProviderRegistry.getInstance().getAuthProvider(apId);
if (authProvider != null) {
@@ -362,7 +365,7 @@ public class WebServiceUtils extends WebCommonUtils {
*/
@NotNull
public static Set<String> getApplicableDriversIds() {
return CBPlatform.getInstance().getApplicableDrivers().stream()
return WebAppUtils.getWebPlatform().getApplicableDrivers().stream()
.map(DBPDriver::getId)
.collect(Collectors.toSet());
}
@@ -18,10 +18,10 @@ package io.cloudbeaver.model;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.config.CBAppConfig;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.utils.ConfigurationUtils;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.WebAppUtils;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
@@ -265,7 +265,7 @@ public class WebDatabaseDriverInfo {
@Property
public boolean isEnabled() {
CBAppConfig config = CBApplication.getInstance().getAppConfiguration();
WebAppConfiguration config = WebAppUtils.getWebApplication().getAppConfiguration();
return ConfigurationUtils.isDriverEnabled(
driver,
config.getEnabledDrivers(),
@@ -16,7 +16,7 @@
*/
package io.cloudbeaver.model;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.utils.ServletAppUtils;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
import org.jkiss.dbeaver.model.meta.Property;
@@ -68,7 +68,7 @@ public class WebProductInfo {
@Property
public String getLicenseInfo() {
return CBApplication.getInstance().getInfoDetails(new VoidProgressMonitor());
return ServletAppUtils.getServletApplication().getInfoDetails(new VoidProgressMonitor());
}
@Property
@@ -16,18 +16,14 @@
*/
package io.cloudbeaver.model;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.config.PasswordPolicyConfiguration;
import io.cloudbeaver.registry.WebServerFeatureRegistry;
import io.cloudbeaver.registry.WebServiceDescriptor;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebApplication;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.navigator.DBNBrowseSettings;
import org.jkiss.dbeaver.registry.DataSourceNavigatorSettings;
import org.jkiss.dbeaver.registry.language.PlatformLanguageDescriptor;
import org.jkiss.dbeaver.registry.language.PlatformLanguageRegistry;
import org.jkiss.dbeaver.runtime.DBWorkbench;
@@ -51,10 +47,7 @@ public class WebServerConfig {
@Property
public String getName() {
if (application instanceof CBApplication<?> cbApp) {
return CommonUtils.notEmpty(cbApp.getServerConfiguration().getServerName());
}
return "";
return CommonUtils.notEmpty(application.getServerConfiguration().getServerName());
}
@Property
@@ -67,33 +60,6 @@ public class WebServerConfig {
return DBWorkbench.getPlatform().getWorkspace().getWorkspaceId();
}
@Property
public String getServerURL() {
if (application instanceof CBApplication<?> cbApp) {
return CommonUtils.notEmpty(cbApp.getServerConfiguration().getServerURL());
}
return "";
}
@Property
public String getRootURI() {
return CommonUtils.notEmpty(application.getServerConfiguration().getRootURI());
}
@Deprecated
@Property
public String getHostName() {
return getContainerId();
}
@Property
public String getContainerId() {
if (application instanceof CBApplication<?> cbApp) {
return CommonUtils.notEmpty(cbApp.getContainerId());
}
return "";
}
@Property
public boolean isAnonymousAccessEnabled() {
return application.getAppConfiguration().isAnonymousAccessEnabled();
@@ -104,36 +70,14 @@ public class WebServerConfig {
return application.getAppConfiguration().isSupportsCustomConnections();
}
@Property
public boolean isSupportsConnectionBrowser() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().isSupportsConnectionBrowser();
}
return false;
}
@Property
public boolean isSupportsWorkspaces() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().isSupportsUserWorkspaces();
}
return false;
}
@Property
public boolean isPublicCredentialsSaveEnabled() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().isPublicCredentialsSaveEnabled();
}
return false;
return application.getAppConfiguration().isPublicCredentialsSaveEnabled();
}
@Property
public boolean isAdminCredentialsSaveEnabled() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().isAdminCredentialsSaveEnabled();
}
return false;
return application.getAppConfiguration().isAdminCredentialsSaveEnabled();
}
@Property
@@ -143,18 +87,12 @@ public class WebServerConfig {
@Property
public boolean isLicenseValid() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.isLicenseValid();
}
return false;
return application.isLicenseValid();
}
@Property
public String getLicenseStatus() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getLicenseStatus();
}
return "";
return application.getLicenseStatus();
}
@Property
@@ -167,35 +105,11 @@ public class WebServerConfig {
return application.getServerConfiguration().isDevelMode();
}
@Property
public boolean isRedirectOnFederatedAuth() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().isRedirectOnFederatedAuth();
}
return false;
}
@Property
public boolean isResourceManagerEnabled() {
return application.getAppConfiguration().isResourceManagerEnabled();
}
@Property
public long getSessionExpireTime() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getServerConfiguration().getMaxSessionIdleTime();
}
return 0;
}
@Property
public String getLocalHostAddress() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getLocalHostAddress();
}
return "";
}
@Property
public String[] getEnabledFeatures() {
return application.getAppConfiguration().getEnabledFeatures();
@@ -204,10 +118,7 @@ public class WebServerConfig {
@Property
@Nullable
public String[] getDisabledBetaFeatures() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().getDisabledBetaFeatures();
}
return new String[0];
return application.getAppConfiguration().getDisabledBetaFeatures();
}
@Property
@@ -216,14 +127,6 @@ public class WebServerConfig {
return WebServerFeatureRegistry.getInstance().getServerFeatures();
}
@Property
public String[] getEnabledAuthProviders() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().getEnabledAuthProviders();
}
return new String[0];
}
@Property
public WebServerLanguage[] getSupportedLanguages() {
List<PlatformLanguageDescriptor> langs = PlatformLanguageRegistry.getInstance().getLanguages();
@@ -245,23 +148,17 @@ public class WebServerConfig {
@Property
public Map<String, Object> getProductConfiguration() {
return CBPlatform.getInstance().getApplication().getProductConfiguration();
return application.getProductConfiguration();
}
@Property
public DBNBrowseSettings getDefaultNavigatorSettings() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().getDefaultNavigatorSettings();
}
return new DataSourceNavigatorSettings();
return application.getAppConfiguration().getDefaultNavigatorSettings();
}
@Property
public Map<String, Object> getResourceQuotas() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().getResourceQuotas();
}
return Map.of();
return application.getAppConfiguration().getResourceQuotas();
}
@Property
@@ -271,35 +168,11 @@ public class WebServerConfig {
@Property
public String[] getDisabledDrivers() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getAppConfiguration().getDisabledDrivers();
}
return new String[0];
return application.getAppConfiguration().getDisabledDrivers();
}
@Property
public Boolean isDistributed() {
return application.isDistributed();
}
@Property
public String getDefaultAuthRole() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getDefaultAuthRole();
}
return "";
}
@Property
public String getDefaultUserTeam() {
return application.getAppConfiguration().getDefaultUserTeam();
}
@Property
public PasswordPolicyConfiguration getPasswordPolicyConfiguration() {
if (application instanceof CBApplication<?> cbApp) {
return cbApp.getSecurityManagerConfiguration().getPasswordPolicyConfiguration();
}
return new PasswordPolicyConfiguration();
}
}
@@ -0,0 +1,28 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.model.app;
import org.jkiss.code.Nullable;
/**
* Web server configuration.
* Contains only server configuration properties.
*/
public interface WebServerConfiguration extends ServletServerConfiguration {
@Nullable
String getServerName();
}
@@ -17,13 +17,13 @@
package io.cloudbeaver.server;
import io.cloudbeaver.DBWConstants;
import io.cloudbeaver.model.app.WebApplication;
import org.eclipse.core.runtime.Plugin;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.app.DBACertificateStorage;
import org.jkiss.dbeaver.model.app.DBPWorkspace;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.impl.app.DefaultCertificateStorage;
import org.jkiss.dbeaver.model.qm.QMRegistry;
import org.jkiss.dbeaver.model.qm.QMUtils;
@@ -40,17 +40,20 @@ import org.jkiss.utils.StandardConstants;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
public abstract class BaseGQLPlatform extends BasePlatformImpl {
private static final Log log = Log.getLog(BaseGQLPlatform.class);
public abstract class BaseWebPlatform extends BasePlatformImpl {
private static final Log log = Log.getLog(BaseWebPlatform.class);
public static final String BASE_TEMP_DIR = "dbeaver";
public static final String TEMP_FILE_FOLDER = "temp-sql-upload-files";
public static final String TEMP_FILE_IMPORT_FOLDER = "temp-import-files";
private Path tempFolder;
private QMRegistryImpl queryManager;
private QMLogFileWriter qmLogWriter;
private DBACertificateStorage certificateStorage;
private WebGlobalWorkspace workspace;
private ServerGlobalWorkspace workspace;
@Override
protected synchronized void initialize() {
@@ -58,7 +61,7 @@ public abstract class BaseGQLPlatform extends BasePlatformImpl {
SecurityProviderUtils.registerSecurityProvider();
// Register properties adapter
this.workspace = new WebGlobalWorkspace(this, (WebApplication) getApplication());
this.workspace = new ServerGlobalWorkspace(this, getApplication());
this.workspace.initializeProjects();
QMUtils.initApplication(this);
@@ -129,6 +132,8 @@ public abstract class BaseGQLPlatform extends BasePlatformImpl {
@NotNull
public abstract WebApplication getApplication();
protected abstract void scheduleServerJobs();
@Override
public synchronized void dispose() {
super.dispose();
@@ -158,4 +163,5 @@ public abstract class BaseGQLPlatform extends BasePlatformImpl {
return queryManager;
}
public abstract List<DBPDriver> getApplicableDrivers();
}
@@ -21,9 +21,9 @@ import org.jkiss.dbeaver.runtime.ui.console.ConsoleUserInterface;
/**
* The activator class controls the plug-in life cycle
*/
public class CBPlatformUI extends ConsoleUserInterface {
public class ServletPlatformUI extends ConsoleUserInterface {
public static final CBPlatformUI INSTANCE = new CBPlatformUI();
public static final ServletPlatformUI INSTANCE = new ServletPlatformUI();
protected void initialize() {
// just a placeholder for injection
@@ -30,7 +30,7 @@ import org.jkiss.dbeaver.DBException;
import java.util.Collection;
public interface AppWebSessionManager {
public interface WebAppSessionManager {
BaseWebSession closeSession(@NotNull HttpServletRequest request);
@NotNull
@@ -61,4 +61,8 @@ public interface AppWebSessionManager {
WebHeadlessSession getHeadlessSession(Request request, Session session, boolean create) throws DBException;
boolean touchSession(HttpServletRequest request, HttpServletResponse response) throws DBWebException;
default void expireIdleSessions() {
}
}
@@ -0,0 +1,29 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.server;
import org.jkiss.dbeaver.runtime.DBWorkbench;
public class WebAppUtils {
public static WebApplication getWebApplication() {
return (WebApplication) DBWorkbench.getPlatform().getApplication();
}
public static BaseWebPlatform getWebPlatform() {
return (BaseWebPlatform) DBWorkbench.getPlatform();
}
}
@@ -16,7 +16,10 @@
*/
package io.cloudbeaver.server;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.WebServerConfig;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.WebServerConfiguration;
import io.cloudbeaver.registry.WebDriverRegistry;
import org.jkiss.code.NotNull;
@@ -24,13 +27,18 @@ import java.net.InetAddress;
import java.util.List;
import java.util.Map;
//FIXME: this interface should not exist,
// the logic of platforms and applications should be separated from each other
public interface GQLApplicationAdapter extends WebApplication {
AppWebSessionManager getSessionManager();
/**
* Base interface for applications with web ui
*/
public interface WebApplication extends ServletApplication {
WebServerConfiguration getServerConfiguration();
WebAppSessionManager getSessionManager();
WebDriverRegistry getDriverRegistry();
WebAppConfiguration getAppConfiguration();
@NotNull
Map<String, Object> getProductConfiguration();
@@ -41,4 +49,7 @@ public interface GQLApplicationAdapter extends WebApplication {
boolean isLicenseValid();
String getLicenseStatus();
WebServerConfig getWebServerConfig();
}
@@ -18,7 +18,7 @@ package io.cloudbeaver.server.actions;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.service.DBWServletHandler;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import jakarta.servlet.Servlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -44,7 +44,7 @@ public abstract class AbstractActionServletHandler implements DBWServletHandler
action.saveInSession(session);
// Redirect to home
response.sendRedirect(WebAppUtils.getWebApplication().getServerConfiguration().getRootURI());
response.sendRedirect(ServletAppUtils.getServletApplication().getServerConfiguration().getRootURI());
}
protected abstract String getActionConsole();
@@ -17,7 +17,7 @@
package io.cloudbeaver.server.events;
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.websocket.WSEventHandler;
@@ -32,7 +32,9 @@ public class WSDefaultEventHandler<EVENT extends WSEvent> implements WSEventHand
@Override
public void handleEvent(@NotNull EVENT event) {
log.debug(event.getTopicId() + " event handled");
Collection<BaseWebSession> allSessions = CBPlatform.getInstance().getSessionManager().getAllActiveSessions();
Collection<BaseWebSession> allSessions = WebAppUtils.getWebApplication()
.getSessionManager()
.getAllActiveSessions();
for (var activeUserSession : allSessions) {
if (!isAcceptableInSession(activeUserSession, event)) {
log.debug("Cannot handle " + event.getTopicId() + " event '" + event.getId() +
@@ -16,7 +16,8 @@
*/
package io.cloudbeaver.server.events;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.BaseWebPlatform;
import io.cloudbeaver.server.WebAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
@@ -33,9 +34,9 @@ public class WSDeleteTempFileHandler implements WSEventHandler<WSEventDeleteTemp
private static final Log log = Log.getLog(WSDeleteTempFileHandler.class);
public void resetTempFolder(String sessionId) {
Path path = CBPlatform.getInstance()
.getTempFolder(new VoidProgressMonitor(), CBPlatform.TEMP_FILE_FOLDER)
.resolve(sessionId);
Path path = WebAppUtils.getWebPlatform()
.getTempFolder(new VoidProgressMonitor(), BaseWebPlatform.TEMP_FILE_FOLDER)
.resolve(sessionId);
if (Files.exists(path)) {
try {
IOUtils.deleteDirectory(path);
@@ -43,9 +44,9 @@ public class WSDeleteTempFileHandler implements WSEventHandler<WSEventDeleteTemp
log.error("Error deleting temp path", e);
}
}
path = CBPlatform.getInstance()
.getTempFolder(new VoidProgressMonitor(), CBPlatform.TEMP_FILE_IMPORT_FOLDER)
.resolve(sessionId);
path = WebAppUtils.getWebPlatform()
.getTempFolder(new VoidProgressMonitor(), BaseWebPlatform.TEMP_FILE_IMPORT_FOLDER)
.resolve(sessionId);
if (Files.exists(path)) {
try {
IOUtils.deleteDirectory(path);
@@ -35,7 +35,7 @@ import io.cloudbeaver.server.HttpConstants;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.DBWServiceBindingGraphQL;
import io.cloudbeaver.service.WebServiceBindingBase;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
@@ -122,7 +122,7 @@ public class GraphQLEndpoint extends HttpServlet {
}
private void setDevelHeaders(HttpServletRequest request, HttpServletResponse response) {
if (WebAppUtils.getWebApplication().getServerConfiguration().isDevelMode()) {
if (ServletAppUtils.getServletApplication().getServerConfiguration().isDevelMode()) {
// response.setHeader(HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, "*");
// response.setHeader(HEADER_ACCESS_CONTROL_ALLOW_HEADERS, "*");
// response.setHeader(HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS, "*");
@@ -209,7 +209,7 @@ public class GraphQLEndpoint extends HttpServlet {
if (path == null) {
path = request.getServletPath();
}
boolean develMode = WebAppUtils.getWebApplication().getServerConfiguration().isDevelMode();
boolean develMode = ServletAppUtils.getServletApplication().getServerConfiguration().isDevelMode();
if (path.contentEquals("/schema.json") && develMode) {
executeQuery(request, response, GraphQLConstants.SCHEMA_READ_QUERY, null, null);
@@ -16,10 +16,9 @@
*/
package io.cloudbeaver.server.graphql;
import io.cloudbeaver.model.app.BaseWebApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.WebApplication;
import jakarta.servlet.http.HttpServletRequest;
import org.jkiss.code.Nullable;
import org.jkiss.utils.CommonUtils;
@@ -58,20 +57,17 @@ public class GraphQLLoggerUtil {
if (request.getSession() == null) {
return null;
}
WebApplication webApplication = WebAppUtils.getWebApplication();
if (BaseWebApplication.getInstance() instanceof CBApplication<?> cbApp) {
return (WebSession)cbApp.getSessionManager()
.getSession(request.getSession().getId());
} else {
return null;
}
return webApplication.getSessionManager()
.findWebSession(request);
}
public static String buildLoggerMessage(String sessionId, String userId, Map<String, Object> variables) {
StringBuilder loggerMessage = new StringBuilder(" [user: ").append(userId)
.append(", sessionId: ").append(sessionId).append("]");
if (CBPlatform.getInstance().getPreferenceStore().getBoolean(LOG_API_GRAPHQL_DEBUG_PARAMETER)
if (WebAppUtils.getWebPlatform().getPreferenceStore().getBoolean(LOG_API_GRAPHQL_DEBUG_PARAMETER)
&& variables != null
) {
loggerMessage.append(" [variables] ");
@@ -16,14 +16,14 @@
*/
package io.cloudbeaver.server.jetty;
import io.cloudbeaver.server.GQLApplicationAdapter;
import io.cloudbeaver.server.WebApplication;
import org.eclipse.jetty.ee10.servlet.SessionHandler;
public class CBSessionHandler extends SessionHandler {
static final int ONE_MINUTE = 60;
private final GQLApplicationAdapter application;
private final WebApplication application;
public CBSessionHandler(GQLApplicationAdapter application) {
public CBSessionHandler(WebApplication application) {
this.application = application;
}
}
@@ -0,0 +1,59 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.server.jetty;
import io.cloudbeaver.server.WebApplication;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.session.DefaultSessionCache;
import org.eclipse.jetty.session.DefaultSessionIdManager;
import org.eclipse.jetty.session.NullSessionDataStore;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
public class JettyUtils {
private static final Log log = Log.getLog(JettyUtils.class);
public static void initSessionManager(
long maxIdleTime,
@NotNull WebApplication application,
@NotNull Server server,
@NotNull ServletContextHandler servletContextHandler
) {
// Init sessions persistence
CBSessionHandler sessionHandler = new CBSessionHandler(application);
sessionHandler.setRefreshCookieAge(CBSessionHandler.ONE_MINUTE);
int intMaxIdleSeconds;
if (maxIdleTime > Integer.MAX_VALUE) {
log.warn("Max session idle time value is greater than Integer.MAX_VALUE. Integer.MAX_VALUE will be used instead");
maxIdleTime = Integer.MAX_VALUE;
}
intMaxIdleSeconds = (int) (maxIdleTime / 1000);
log.debug("Max http session idle time: " + intMaxIdleSeconds + "s");
sessionHandler.setMaxInactiveInterval(intMaxIdleSeconds);
sessionHandler.setMaxCookieAge(intMaxIdleSeconds);
DefaultSessionCache sessionCache = new DefaultSessionCache(sessionHandler);
sessionCache.setSessionDataStore(new NullSessionDataStore());
sessionHandler.setSessionCache(sessionCache);
servletContextHandler.setSessionHandler(sessionHandler);
DefaultSessionIdManager idMgr = new DefaultSessionIdManager(server);
idMgr.setWorkerName(null);
server.addBean(idMgr, true);
}
}
@@ -16,9 +16,9 @@
*/
package io.cloudbeaver.server.jobs;
import io.cloudbeaver.server.AppWebSessionManager;
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.WebAppSessionManager;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.app.DBPPlatform;
@@ -34,11 +34,11 @@ import java.util.List;
* Web data source monitor job.
*/
public class WebDataSourceMonitorJob extends DataSourceMonitorJob {
private final AppWebSessionManager sessionManager;
private final WebAppSessionManager sessionManager;
public WebDataSourceMonitorJob(
@NotNull DBPPlatform platform,
@NotNull AppWebSessionManager sessionManager
@NotNull WebAppSessionManager sessionManager
) {
super(platform);
this.sessionManager = sessionManager;
@@ -1,14 +1,31 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 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.server.servlets;
import io.cloudbeaver.server.CBConstants;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.FileLocator;
import org.jkiss.dbeaver.Log;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.IOUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -72,9 +89,9 @@ public class CBImageServlet extends HttpServlet {
private void setExpireTime(HttpServletResponse response) {
// Http 1.0 header, set a fix expires date.
response.setDateHeader("Expires", System.currentTimeMillis() + CBStaticServlet.STATIC_CACHE_SECONDS * 1000);
response.setDateHeader("Expires", System.currentTimeMillis() + CBConstants.STATIC_CACHE_SECONDS * 1000);
// Http 1.1 header, set a time after now.
response.setHeader("Cache-Control", "public, max-age=" + CBStaticServlet.STATIC_CACHE_SECONDS);
response.setHeader("Cache-Control", "public, max-age=" + CBConstants.STATIC_CACHE_SECONDS);
}
@@ -17,9 +17,8 @@
package io.cloudbeaver.server.servlets;
import com.google.gson.stream.JsonWriter;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBConstants;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
@@ -34,9 +33,9 @@ import java.util.LinkedHashMap;
import java.util.Map;
@WebServlet(urlPatterns = "/status")
public class CBStatusServlet extends DefaultServlet {
public class WebStatusServlet extends DefaultServlet {
private static final Log log = Log.getLog(CBStatusServlet.class);
private static final Log log = Log.getLog(WebStatusServlet.class);
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
@@ -46,7 +45,7 @@ public class CBStatusServlet extends DefaultServlet {
infoMap.put("health", "ok");
infoMap.put("product.name", GeneralUtils.getProductName());
infoMap.put("product.version", GeneralUtils.getProductVersion().toString());
CBPlatform.getInstance().getApplication().getStatusInfo(infoMap);
WebAppUtils.getWebApplication().getStatusInfo(infoMap);
try (JsonWriter writer = new JsonWriter(response.getWriter())) {
JSONUtils.serializeMap(writer, infoMap);
}
@@ -55,7 +55,7 @@ public class CBEventsWebSocket extends CBAbstractWebSocket implements CBWebSessi
@Override
public void onWebSocketText(String message) {
super.onWebSocketText(message);
var clientEvent = gson.fromJson(message, WSClientEvent.class);
var clientEvent = CBAbstractWebSocket.gson.fromJson(message, WSClientEvent.class);
var clientEventType = WSClientEventType.valueById(clientEvent.getId());
if (clientEventType == null) {
webSession.addSessionError(
@@ -16,11 +16,11 @@
*/
package io.cloudbeaver.server.websockets;
import io.cloudbeaver.server.AppWebSessionManager;
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.model.session.WebHeadlessSession;
import io.cloudbeaver.model.session.WebHttpRequestInfo;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppSessionManager;
import io.cloudbeaver.server.WebAppUtils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.server.ServerUpgradeRequest;
@@ -42,12 +42,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class CBJettyWebSocketManager implements WebSocketCreator {
private static final Log log = Log.getLog(CBJettyWebSocketManager.class);
private final Map<String, List<CBEventsWebSocket>> socketBySessionId = new ConcurrentHashMap<>();
private final AppWebSessionManager webSessionManager;
private final WebAppSessionManager webSessionManager;
public CBJettyWebSocketManager(@NotNull AppWebSessionManager webSessionManager) {
public CBJettyWebSocketManager(@NotNull WebAppSessionManager webSessionManager) {
this.webSessionManager = webSessionManager;
new WebSocketPingPongJob(CBPlatform.getInstance(), this).scheduleMonitor();
new WebSocketPingPongJob(WebAppUtils.getWebPlatform(), this).scheduleMonitor();
}
@Nullable
@@ -16,7 +16,7 @@
*/
package io.cloudbeaver.server.websockets;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.BaseWebPlatform;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
@@ -27,10 +27,10 @@ import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
*/
class WebSocketPingPongJob extends AbstractJob {
private static final int INTERVAL = 1000 * 60 * 1; // once per 1 min
private final CBPlatform platform;
private final BaseWebPlatform platform;
private final CBJettyWebSocketManager webSocketManager;
public WebSocketPingPongJob(CBPlatform platform, CBJettyWebSocketManager webSocketManager) {
public WebSocketPingPongJob(BaseWebPlatform platform, CBJettyWebSocketManager webSocketManager) {
super("WebSocket monitor");
this.platform = platform;
setUser(false);
@@ -16,12 +16,12 @@
*/
package io.cloudbeaver.service;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
public interface DBWServiceBindingWebSocket<APPLICATION extends WebApplication> extends DBWServiceBinding {
default boolean isApplicable(@NotNull WebApplication application) {
public interface DBWServiceBindingWebSocket<APPLICATION extends ServletApplication> extends DBWServiceBinding {
default boolean isApplicable(@NotNull ServletApplication application) {
return true;
}
@@ -21,12 +21,13 @@ import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import io.cloudbeaver.*;
import io.cloudbeaver.model.WebConnectionInfo;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.session.WebSessionProvider;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -103,12 +104,12 @@ public abstract class WebServiceBindingBase<API_TYPE extends DBWService> impleme
}
protected static WebSession getWebSession(DataFetchingEnvironment env) throws DBWebException {
return CBPlatform.getInstance().getSessionManager().getWebSession(
return WebAppUtils.getWebApplication().getSessionManager().getWebSession(
getServletRequest(env), getServletResponse(env));
}
protected static WebSession getWebSession(DataFetchingEnvironment env, boolean errorOnNotFound) throws DBWebException {
return CBPlatform.getInstance().getSessionManager().getWebSession(
return WebAppUtils.getWebApplication().getSessionManager().getWebSession(
getServletRequest(env), getServletResponse(env), errorOnNotFound);
}
@@ -126,12 +127,12 @@ public abstract class WebServiceBindingBase<API_TYPE extends DBWService> impleme
*/
@Nullable
public static WebSession findWebSession(DataFetchingEnvironment env) {
return CBPlatform.getInstance().getSessionManager().findWebSession(
return WebAppUtils.getWebApplication().getSessionManager().findWebSession(
getServletRequest(env));
}
public static WebSession findWebSession(DataFetchingEnvironment env, boolean errorOnNotFound) throws DBWebException {
return CBPlatform.getInstance().getSessionManager().findWebSession(
return WebAppUtils.getWebApplication().getSessionManager().findWebSession(
getServletRequest(env), errorOnNotFound);
}
@@ -242,16 +243,17 @@ public abstract class WebServiceBindingBase<API_TYPE extends DBWService> impleme
private void checkServicePermissions(Method method, WebActionSet actionSet) throws DBWebException {
String[] features = actionSet.requireFeatures();
ServletApplication servletApplication = ServletAppUtils.getServletApplication();
for (String feature : features) {
if (!CBApplication.getInstance().isConfigurationMode() &&
!CBApplication.getInstance().getAppConfiguration().isFeatureEnabled(feature)) {
if (!servletApplication.isConfigurationMode() &&
!servletApplication.getAppConfiguration().isFeatureEnabled(feature)) {
throw new DBWebException("Feature " + feature + " is disabled");
}
}
}
private void checkActionPermissions(@NotNull Method method, @NotNull WebAction webAction) throws DBWebException {
var application = CBPlatform.getInstance().getApplication();
var application = WebAppUtils.getWebPlatform().getApplication();
if (application.isInitializationMode() && webAction.initializationRequired()) {
String message = "Server initialization in progress: "
+ String.join(",", application.getInitActions().values()) + ".\nDo not restart the server.";
@@ -18,18 +18,17 @@ package io.cloudbeaver.service;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import io.cloudbeaver.server.WebAppUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.json.JSONUtils;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
@@ -44,19 +43,19 @@ public abstract class WebServiceServletBase extends HttpServlet {
.setPrettyPrinting()
.create();
private final WebApplication application;
private final ServletApplication application;
public WebServiceServletBase(WebApplication application) {
public WebServiceServletBase(ServletApplication application) {
this.application = application;
}
public WebApplication getApplication() {
public ServletApplication getApplication() {
return application;
}
@Override
protected final void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WebSession webSession = CBPlatform.getInstance().getSessionManager().findWebSession(request);
WebSession webSession = WebAppUtils.getWebApplication().getSessionManager().findWebSession(request);
if (webSession == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Web session not found");
return;
@@ -24,7 +24,9 @@ import io.cloudbeaver.WebServiceUtils;
import io.cloudbeaver.model.WebConnectionConfig;
import io.cloudbeaver.model.WebNetworkHandlerConfigInput;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.BaseWebPlatform;
import io.cloudbeaver.server.WebAppSessionManager;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.graphql.GraphQLEndpoint;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.WebServiceBindingBase;
@@ -48,8 +50,7 @@ public class WebServiceBindingCore extends WebServiceBindingBase<DBWServiceCore>
@Override
public void bindWiring(DBWBindingContext model) throws DBWebException {
CBPlatform platform = CBPlatform.getInstance();
var sessionManager = platform.getSessionManager();
WebAppSessionManager sessionManager = WebAppUtils.getWebApplication().getSessionManager();
model.getQueryType()
.dataFetcher("serverConfig", env -> getService(env).getServerConfig())
.dataFetcher("productSettings", env -> getService(env).getProductSettings(getWebSession(env)))
@@ -19,14 +19,15 @@ package io.cloudbeaver.service.core.impl;
import io.cloudbeaver.*;
import io.cloudbeaver.model.*;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebHandlerRegistry;
import io.cloudbeaver.registry.WebSessionHandlerDescriptor;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.WebApplication;
import io.cloudbeaver.service.core.DBWServiceCore;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import io.cloudbeaver.utils.WebConnectionFolderUtils;
import io.cloudbeaver.utils.WebDataSourceUtils;
import io.cloudbeaver.utils.WebEventUtils;
@@ -76,13 +77,13 @@ public class WebServiceCore implements DBWServiceCore {
@Override
public WebServerConfig getServerConfig() {
return new WebServerConfig(WebAppUtils.getWebApplication());
return WebAppUtils.getWebApplication().getWebServerConfig();
}
@Override
public List<WebDatabaseDriverInfo> getDriverList(@NotNull WebSession webSession, String driverId) {
List<WebDatabaseDriverInfo> result = new ArrayList<>();
for (DBPDriver driver : CBPlatform.getInstance().getApplicableDrivers()) {
for (DBPDriver driver : WebAppUtils.getWebPlatform().getApplicableDrivers()) {
if (driverId == null || driverId.equals(driver.getFullId())) {
result.add(new WebDatabaseDriverInfo(webSession, driver));
}
@@ -139,7 +140,7 @@ public class WebServiceCore implements DBWServiceCore {
for (DBPDataSourceContainer ds : dsRegistry.getDataSources()) {
if (ds.isTemplate()) {
if (CBPlatform.getInstance().getApplicableDrivers().contains(ds.getDriver())) {
if (WebAppUtils.getWebPlatform().getApplicableDrivers().contains(ds.getDriver())) {
result.add(new WebDataSourceConfig(ds));
} else {
log.debug("Template datasource '" + ds.getName() + "' ignored - driver is not applicable");
@@ -178,7 +179,7 @@ public class WebServiceCore implements DBWServiceCore {
for (DBPDataSourceContainer ds : registry.getDataSources()) {
if (ds.isTemplate() &&
project.getDataSourceFilter().filter(ds) &&
CBPlatform.getInstance().getApplicableDrivers().contains(ds.getDriver())) {
WebAppUtils.getWebPlatform().getApplicableDrivers().contains(ds.getDriver())) {
result.add(new WebConnectionInfo(webSession, ds));
}
}
@@ -211,7 +212,7 @@ public class WebServiceCore implements DBWServiceCore {
@Override
public String[] getSessionPermissions(@NotNull WebSession webSession) throws DBWebException {
if (WebAppUtils.getWebApplication().isConfigurationMode()) {
if (ServletAppUtils.getServletApplication().isConfigurationMode()) {
return new String[]{
DBWConstants.PERMISSION_ADMIN
};
@@ -266,7 +267,7 @@ public class WebServiceCore implements DBWServiceCore {
@Override
public boolean closeSession(HttpServletRequest request) throws DBWebException {
try {
var baseWebSession = CBPlatform.getInstance().getSessionManager().closeSession(request);
var baseWebSession = WebAppUtils.getWebApplication().getSessionManager().closeSession(request);
if (baseWebSession instanceof WebSession webSession) {
for (WebSessionHandlerDescriptor hd : WebHandlerRegistry.getInstance().getSessionHandlers()) {
try {
@@ -287,14 +288,14 @@ public class WebServiceCore implements DBWServiceCore {
@Override
@Deprecated
public boolean touchSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws DBWebException {
return CBPlatform.getInstance().getSessionManager().touchSession(request, response);
return WebAppUtils.getWebApplication().getSessionManager().touchSession(request, response);
}
@Override
@Deprecated
public WebSession updateSession(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
throws DBWebException {
var sessionManager = CBPlatform.getInstance().getSessionManager();
var sessionManager = WebAppUtils.getWebApplication().getSessionManager();
sessionManager.touchSession(request, response);
return sessionManager.getWebSession(request, response, true);
}
@@ -302,7 +303,7 @@ public class WebServiceCore implements DBWServiceCore {
@Override
public boolean refreshSessionConnections(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response)
throws DBWebException {
WebSession session = CBPlatform.getInstance().getSessionManager().getWebSession(request, response);
WebSession session = WebAppUtils.getWebApplication().getSessionManager().getWebSession(request, response);
if (session == null) {
return false;
} else {
@@ -439,7 +440,7 @@ public class WebServiceCore implements DBWServiceCore {
var rmProject = project.getRMProject();
if (rmProject.getType() == RMProjectType.USER
&& !webSession.hasPermission(DBWConstants.PERMISSION_ADMIN)
&& !WebAppUtils.getWebApplication().getAppConfiguration().isSupportsCustomConnections()
&& !ServletAppUtils.getServletApplication().getAppConfiguration().isSupportsCustomConnections()
) {
throw new DBWebException("New connection create is restricted by server configuration");
}
@@ -615,8 +616,11 @@ public class WebServiceCore implements DBWServiceCore {
DBPDataSourceRegistry projectRegistry = webSession.getSingletonProject().getDataSourceRegistry();
DBPDataSourceContainer newDataSource = projectRegistry.createDataSource(dataSourceTemplate);
((DataSourceDescriptor) newDataSource).setNavigatorSettings(
CBApplication.getInstance().getAppConfiguration().getDefaultNavigatorSettings());
ServletApplication app = ServletAppUtils.getServletApplication();
if (app instanceof WebApplication webApplication) {
((DataSourceDescriptor) newDataSource).setNavigatorSettings(
webApplication.getAppConfiguration().getDefaultNavigatorSettings());
}
if (!CommonUtils.isEmpty(connectionName)) {
newDataSource.setName(connectionName);
@@ -655,8 +659,11 @@ public class WebServiceCore implements DBWServiceCore {
DBPDataSourceContainer newDataSource = dataSourceRegistry.createDataSource(dataSourceTemplate);
((DataSourceDescriptor) newDataSource).setNavigatorSettings(
CBApplication.getInstance().getAppConfiguration().getDefaultNavigatorSettings());
ServletApplication app = ServletAppUtils.getServletApplication();
if (app instanceof WebApplication webApplication) {
((DataSourceDescriptor) newDataSource).setNavigatorSettings(
webApplication.getAppConfiguration().getDefaultNavigatorSettings());
}
// Copy props from config
if (!CommonUtils.isEmpty(config.getName())) {
@@ -859,7 +866,7 @@ public class WebServiceCore implements DBWServiceCore {
@Override
public List<WebProjectInfo> getProjects(@NotNull WebSession session) {
var customConnectionsEnabled =
WebAppUtils.getWebApplication().getAppConfiguration().isSupportsCustomConnections()
ServletAppUtils.getServletApplication().getAppConfiguration().isSupportsCustomConnections()
|| SMUtils.isRMAdmin(session);
return session.getAccessibleProjects().stream()
.map(pr -> new WebProjectInfo(session, pr, customConnectionsEnabled))
@@ -16,9 +16,9 @@
*/
package io.cloudbeaver.service.sql;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBConstants;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
@@ -36,7 +36,8 @@ import java.text.SimpleDateFormat;
public class WebSQLDataLOBReceiver extends WebSQLCellValueReceiver {
private static final Log log = Log.getLog(WebSQLDataLOBReceiver.class);
public static final Path DATA_EXPORT_FOLDER = CBPlatform.getInstance().getTempFolder(new VoidProgressMonitor(), "sql-lob-files");
public static final Path DATA_EXPORT_FOLDER = WebAppUtils.getWebPlatform().getTempFolder(new VoidProgressMonitor(), "sql-lob" +
"-files");
private final String tableName;
WebSQLDataLOBReceiver(String tableName, DBSDataContainer dataContainer, int rowIndex) {
@@ -63,8 +64,10 @@ public class WebSQLDataLOBReceiver extends WebSQLCellValueReceiver {
fileName.append(s);
exportFileName = CommonUtils.escapeFileName(fileName.toString());
byte[] binaryValue = getBinaryValue(monitor);
Number fileSizeLimit = CBApplication.getInstance().getAppConfiguration().getResourceQuota(CBConstants.QUOTA_PROP_FILE_LIMIT);
if (binaryValue.length > fileSizeLimit.longValue()) {
Number fileSizeLimit = ServletAppUtils.getServletApplication()
.getAppConfiguration()
.getResourceQuota(CBConstants.QUOTA_PROP_FILE_LIMIT);
if (fileSizeLimit != null && binaryValue.length > fileSizeLimit.longValue()) {
throw new DBQuotaException(
"Data export quota exceeded \n Please increase the resourceQuotas parameter in configuration",
CBConstants.QUOTA_PROP_FILE_LIMIT, fileSizeLimit.longValue(), binaryValue.length
@@ -20,10 +20,9 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.service.WebServiceServletBase;
import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletException;
@@ -61,7 +60,7 @@ public class WebSQLFileLoaderServlet extends WebServiceServletBase {
.setPrettyPrinting()
.create();
public WebSQLFileLoaderServlet(WebApplication application) {
public WebSQLFileLoaderServlet(ServletApplication application) {
super(application);
}
@@ -80,7 +79,7 @@ public class WebSQLFileLoaderServlet extends WebServiceServletBase {
return;
}
Path tempFolder = CBPlatform.getInstance()
Path tempFolder = WebAppUtils.getWebPlatform()
.getTempFolder(session.getProgressMonitor(), TEMP_FILE_FOLDER)
.resolve(session.getSessionId());
@@ -20,7 +20,7 @@ import io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.WebConnectionInfo;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.session.WebSessionProvider;
import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.server.WebAppUtils;
import io.cloudbeaver.server.jobs.SqlOutputLogReaderJob;
import org.eclipse.jface.text.Document;
import org.jkiss.code.NotNull;
@@ -1149,7 +1149,7 @@ public class WebSQLProcessor implements WebSessionProvider {
if (cellRow instanceof Map<?, ?>) {
Map<String, Object> variables = (Map<String, Object>) cellRow;
if (variables.get(FILE_ID) != null) {
Path path = CBPlatform.getInstance()
Path path = WebAppUtils.getWebPlatform()
.getTempFolder(webSession.getProgressMonitor(), TEMP_FILE_FOLDER)
.resolve(webSession.getSessionId())
.resolve(variables.get(FILE_ID).toString());
@@ -17,7 +17,7 @@
package io.cloudbeaver.service.sql;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
@@ -55,7 +55,7 @@ class WebSQLQueryDataReceiver implements DBDDataReceiver {
this.contextInfo = contextInfo;
this.dataContainer = dataContainer;
this.dataFormat = dataFormat;
rowLimit = WebAppUtils.getWebApplication()
rowLimit = ServletAppUtils.getServletApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_ROW_LIMIT);
}
@@ -17,10 +17,9 @@
package io.cloudbeaver.service.sql;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.servlets.CBStaticServlet;
import io.cloudbeaver.server.CBConstants;
import io.cloudbeaver.service.WebServiceServletBase;
import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletException;
@@ -52,7 +51,7 @@ public class WebSQLResultServlet extends WebServiceServletBase {
private final DBWServiceSQL sqlService;
public WebSQLResultServlet(WebApplication application, DBWServiceSQL sqlService) {
public WebSQLResultServlet(ServletApplication application, DBWServiceSQL sqlService) {
super(application);
this.sqlService = sqlService;
}
@@ -89,8 +88,8 @@ public class WebSQLResultServlet extends WebServiceServletBase {
response.setHeader("Content-Type", "application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=\"" + dataFile.getFileName().toString() + "\"");
response.setHeader("Content-Length", String.valueOf(Files.size(dataFile)));
response.setDateHeader("Expires", System.currentTimeMillis() + CBStaticServlet.STATIC_CACHE_SECONDS * 1000);
response.setHeader("Cache-Control", "public, max-age=" + CBStaticServlet.STATIC_CACHE_SECONDS);
response.setDateHeader("Expires", System.currentTimeMillis() + CBConstants.STATIC_CACHE_SECONDS * 1000);
response.setHeader("Cache-Control", "public, max-age=" + CBConstants.STATIC_CACHE_SECONDS);
try (InputStream is = Files.newInputStream(dataFile)) {
IOUtils.copyStream(is, response.getOutputStream());
@@ -16,11 +16,11 @@
*/
package io.cloudbeaver.service.sql;
import io.cloudbeaver.model.app.WebAppConfiguration;
import io.cloudbeaver.model.app.ServletAppConfiguration;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.registry.WebServiceRegistry;
import io.cloudbeaver.utils.CBModelConstants;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.*;
@@ -151,7 +151,7 @@ public class WebSQLUtils {
if (ContentUtils.isTextContent(value)) {
String stringValue = ContentUtils.getContentStringValue(session.getProgressMonitor(), value);
int textPreviewMaxLength = CommonUtils.toInt(
WebAppUtils.getWebApplication()
ServletAppUtils.getServletApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH),
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH
@@ -166,7 +166,7 @@ public class WebSQLUtils {
if (binaryValue != null) {
byte[] previewValue = binaryValue;
// gets parameters from the configuration file
WebAppConfiguration config = WebAppUtils.getWebApplication().getAppConfiguration();
ServletAppConfiguration config = ServletAppUtils.getServletApplication().getAppConfiguration();
// the max length of the text preview
int textPreviewMaxLength = CommonUtils.toInt(
config.getResourceQuota(
@@ -215,7 +215,7 @@ public class WebSQLUtils {
*/
public static Object serializeStringValue(Object value) {
int textPreviewMaxLength = CommonUtils.toInt(
WebAppUtils.getWebApplication()
ServletAppUtils.getServletApplication()
.getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_TEXT_PREVIEW_MAX_LENGTH),
WebSQLConstants.TEXT_PREVIEW_MAX_LENGTH
@@ -19,9 +19,8 @@ package io.cloudbeaver.service.sql;
import graphql.schema.DataFetchingEnvironment;
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.WebConnectionInfo;
import io.cloudbeaver.model.app.WebApplication;
import io.cloudbeaver.model.app.ServletApplication;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.service.DBWBindingContext;
import io.cloudbeaver.service.DBWServiceBindingServlet;
import io.cloudbeaver.service.DBWServletContext;
@@ -40,7 +39,8 @@ import java.util.stream.Collectors;
/**
* Web service implementation
*/
public class WebServiceBindingSQL extends WebServiceBindingBase<DBWServiceSQL> implements DBWServiceBindingServlet<WebApplication> {
public class WebServiceBindingSQL extends WebServiceBindingBase<DBWServiceSQL>
implements DBWServiceBindingServlet<ServletApplication> {
public WebServiceBindingSQL() {
super(DBWServiceSQL.class, new WebServiceSQL(), "schema/service.sql.graphqls");
@@ -295,7 +295,7 @@ public class WebServiceBindingSQL extends WebServiceBindingBase<DBWServiceSQL> i
}
@Override
public void addServlets(WebApplication application, DBWServletContext servletContext) throws DBException {
public void addServlets(ServletApplication application, DBWServletContext servletContext) throws DBException {
servletContext.addServlet(
"sqlResultValueViewer",
new WebSQLResultServlet(application, getServiceImpl()),
@@ -309,7 +309,7 @@ public class WebServiceBindingSQL extends WebServiceBindingBase<DBWServiceSQL> i
}
@Override
public boolean isApplicable(WebApplication application) {
public boolean isApplicable(ServletApplication application) {
return application.isMultiuser();
}
@@ -8,6 +8,6 @@ Bundle-Release-Date: 20241223
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Require-Bundle: io.cloudbeaver.server,
Require-Bundle: io.cloudbeaver.server.ce,
org.jkiss.dbeaver.registry
Automatic-Module-Name: io.cloudbeaver.service.admin
@@ -34,7 +34,7 @@ import io.cloudbeaver.server.CBPlatform;
import io.cloudbeaver.service.DBWServiceServerConfigurator;
import io.cloudbeaver.service.admin.*;
import io.cloudbeaver.service.security.SMUtils;
import io.cloudbeaver.utils.WebAppUtils;
import io.cloudbeaver.utils.ServletAppUtils;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
@@ -269,7 +269,7 @@ public class WebServiceAdmin implements DBWServiceAdmin {
if (grantor == null) {
throw new DBWebException("Cannot grant team in anonymous mode");
}
if (!WebAppUtils.getWebApplication().isDistributed()
if (!ServletAppUtils.getServletApplication().isDistributed()
&& CommonUtils.equalObjects(user, webSession.getUser().getUserId())
) {
throw new DBWebException("You cannot edit your own permissions");
@@ -289,7 +289,7 @@ public class WebServiceAdmin implements DBWServiceAdmin {
if (grantor == null) {
throw new DBWebException("Cannot revoke team in anonymous mode");
}
if (!WebAppUtils.getWebApplication().isDistributed() &&
if (!ServletAppUtils.getServletApplication().isDistributed() &&
CommonUtils.equalObjects(user, webSession.getUser().getUserId())
) {
throw new DBWebException("You cannot edit your own permissions");
@@ -8,6 +8,6 @@ Bundle-Release-Date: 20241223
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Require-Bundle: io.cloudbeaver.server
Require-Bundle: io.cloudbeaver.server.ce
Automatic-Module-Name: io.cloudbeaver.service.auth
Export-Package: io.cloudbeaver.service.auth

Some files were not shown because too many files have changed in this diff Show More