Skip to content

Commit

Permalink
Dbeaver/dbeaver vscode#3 remove redundunt plugins (#2891)
Browse files Browse the repository at this point in the history
* CB-5530 wip

* dbeaver-vscode#3 cleanup servlets

* dbeaver-vscode#3 endpoint fixes

* dbeaver-vscode#3 resolve conflicts

* dbeaver-vscode#3 fix conflict

* dbeaver-vscode# jetty 12 conflict fixes

* dbeaver-vscode#3 servlets filter

---------

Co-authored-by: mr-anton-t <[email protected]>
  • Loading branch information
alexander-skoblikov and mr-anton-t authored Sep 19, 2024
1 parent 90acaaf commit efb42d3
Show file tree
Hide file tree
Showing 37 changed files with 439 additions and 174 deletions.
1 change: 1 addition & 0 deletions server/bundles/io.cloudbeaver.model/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Export-Package: io.cloudbeaver,
io.cloudbeaver.model,
io.cloudbeaver.model.app,
io.cloudbeaver.model.fs,
io.cloudbeaver.model.log,
io.cloudbeaver.model.rm,
io.cloudbeaver.model.rm.local,
io.cloudbeaver.model.rm.lock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.jkiss.code.NotNull;

/**
* Abstract class that contains methods for loading configuration with gson.
*/
public abstract class BaseServerConfigurationController<T extends WebServerConfiguration>
implements WebServerConfigurationController<T> {

@NotNull
public Gson getGson() {
return getGsonBuilder().create();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public abstract class BaseWebApplication extends BaseApplicationImpl implements
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 String instanceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public abstract class BaseWebSession extends AbstractSessionPersistent {
@NotNull
protected final WebUserContext userContext;
@NotNull
protected final WebAuthApplication application;
protected final WebApplication 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 WebAuthApplication application) throws DBException {
public BaseWebSession(@NotNull String id, @NotNull WebApplication application) throws DBException {
this.id = id;
this.application = application;
this.createTime = System.currentTimeMillis();
Expand Down Expand Up @@ -232,6 +232,9 @@ public boolean isValid() {

@Property
public long getRemainingTime() {
return application.getMaxSessionIdleTime() + lastAccessTime - System.currentTimeMillis();
if (application instanceof WebAuthApplication authApplication) {
return authApplication.getMaxSessionIdleTime() + lastAccessTime - System.currentTimeMillis();
}
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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.user.WebUser;
import io.cloudbeaver.service.DBWSessionHandler;
Expand Down Expand Up @@ -88,6 +89,7 @@
* Web session.
* Is the main source of data in web application
*/
//TODO: split to authenticated and non authenticated context
public class WebSession extends BaseWebSession
implements SMSessionWithAuth, SMCredentialsProvider, DBACredentialsProvider, IAdaptable {

Expand Down Expand Up @@ -140,6 +142,24 @@ public WebSession(
updateSessionParameters(requestInfo);
}

protected WebSession(
@NotNull String id,
@Nullable String locale,
@NotNull WebApplication application,
@NotNull Map<String, DBWSessionHandler> sessionHandlers
) throws DBException {
super(id, application);
this.lastAccessTime = this.createTime;
this.sessionHandlers = sessionHandlers;
setLocale(locale);
//force authorization of anonymous session to avoid access error,
//because before authorization could be called by any request,
//but now 'updateInfo' is called only in special requests,
//and the order of requests is not guaranteed.
//look at CB-4747
refreshSessionAuth();
}

@Nullable
@Override
public SMSessionPrincipal getSessionPrincipal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* Web user context.
* Contains user state and services based on available permissions
*/
//TODO: split to authenticated and non authenticated context
public class WebUserContext implements SMCredentialsProvider {
private static final Log log = Log.getLog(WebUserContext.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* 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 io.cloudbeaver.DBWConstants;
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.impl.app.DefaultCertificateStorage;
import org.jkiss.dbeaver.model.qm.QMRegistry;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.registry.BasePlatformImpl;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
import org.jkiss.dbeaver.runtime.SecurityProviderUtils;
import org.jkiss.dbeaver.runtime.qm.QMLogFileWriter;
import org.jkiss.dbeaver.runtime.qm.QMRegistryImpl;
import org.jkiss.dbeaver.utils.ContentUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public abstract class BaseGQLPlatform extends BasePlatformImpl {
private static final Log log = Log.getLog(BaseGQLPlatform.class);
public static final String WORK_DATA_FOLDER_NAME = ".work-data";

private Path tempFolder;

private QMRegistryImpl queryManager;
private QMLogFileWriter qmLogWriter;
private DBACertificateStorage certificateStorage;
private WebGlobalWorkspace workspace;

@Override
protected synchronized void initialize() {
// Register BC security provider
SecurityProviderUtils.registerSecurityProvider();

// Register properties adapter
this.workspace = new WebGlobalWorkspace(this);
this.workspace.initializeProjects();
QMUtils.initApplication(this);

this.queryManager = new QMRegistryImpl();

this.qmLogWriter = new QMLogFileWriter();
this.queryManager.registerMetaListener(qmLogWriter);

this.certificateStorage = new DefaultCertificateStorage(
WebPlatformActivator.getInstance()
.getStateLocation()
.toFile()
.toPath()
.resolve(DBConstants.CERTIFICATE_STORAGE_FOLDER));
super.initialize();
}

@Override
protected Plugin getProductPlugin() {
return WebPlatformActivator.getInstance();
}

@NotNull
@Override
public DBACertificateStorage getCertificateStorage() {
return certificateStorage;
}

@NotNull
@Override
public DBPWorkspace getWorkspace() {
return workspace;
}

@NotNull
public Path getTempFolder(@NotNull DBRProgressMonitor monitor, @NotNull String name) {
if (tempFolder == null) {
// Make temp folder
monitor.subTask("Create temp folder");
tempFolder = workspace.getAbsolutePath().resolve(DBWConstants.WORK_DATA_FOLDER_NAME);
}
if (!Files.exists(tempFolder)) {
try {
Files.createDirectories(tempFolder);
} catch (IOException e) {
log.error("Can't create temp directory " + tempFolder, e);
}
}
Path folder = tempFolder.resolve(name);
if (!Files.exists(folder)) {
try {
Files.createDirectories(folder);
} catch (IOException e) {
log.error("Error creating temp folder '" + folder.toAbsolutePath() + "'", e);
}
}
return folder;
}

@Override
public synchronized void dispose() {
super.dispose();
if (this.qmLogWriter != null) {
this.queryManager.unregisterMetaListener(qmLogWriter);
this.qmLogWriter.dispose();
this.qmLogWriter = null;
}
if (this.queryManager != null) {
this.queryManager.dispose();
//queryManager = null;
}
DataSourceProviderRegistry.dispose();

// Remove temp folder
if (tempFolder != null) {

if (!ContentUtils.deleteFileRecursive(tempFolder.toFile())) {
log.warn("Can't delete temp folder '" + tempFolder.toAbsolutePath() + "'");
}
tempFolder = null;
}
}

@NotNull
public QMRegistry getQueryManager() {
return queryManager;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Servlet service
*/
public interface DBWServiceBindingServlet<APPLICATION extends WebApplication> extends DBWServiceBinding {
default boolean isApplicable(WebApplication application) {
return true;
}

void addServlets(APPLICATION application, DBWServletContext servletContext) throws DBException;
}
3 changes: 3 additions & 0 deletions server/bundles/io.cloudbeaver.server/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ Export-Package: io.cloudbeaver,
io.cloudbeaver.server.events,
io.cloudbeaver.server,
io.cloudbeaver.server.actions,
io.cloudbeaver.server.jetty,
io.cloudbeaver.server.graphql,
io.cloudbeaver.server.jobs,
io.cloudbeaver.server.servlets,
io.cloudbeaver.server.websockets,
io.cloudbeaver.service,
io.cloudbeaver.service.navigator,
io.cloudbeaver.service.session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.cloudbeaver.auth.provisioning.SMProvisioner;
import io.cloudbeaver.registry.WebAuthProviderConfiguration;
import io.cloudbeaver.registry.WebAuthProviderDescriptor;
import io.cloudbeaver.server.CBAppConfig;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import org.jkiss.dbeaver.Log;
Expand Down Expand Up @@ -64,7 +65,10 @@ public String getDescription() {
}

public boolean isDefaultProvider() {
return descriptor.getId().equals(CBPlatform.getInstance().getApplication().getAppConfiguration().getDefaultAuthProvider());
if (CBPlatform.getInstance().getApplication().getAppConfiguration() instanceof CBAppConfig cbAppConfig) {
return descriptor.getId().equals(cbAppConfig.getDefaultAuthProvider());
}
return false;
}

public boolean isConfigurable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 io.cloudbeaver.DBWebException;
import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.model.session.WebHeadlessSession;
import io.cloudbeaver.model.session.WebSession;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Session;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;

import java.util.Collection;

public interface AppWebSessionManager {
BaseWebSession closeSession(@NotNull HttpServletRequest request);

@NotNull
WebSession getWebSession(
@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response
) throws DBWebException;

@NotNull
WebSession getWebSession(
@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
boolean errorOnNoFound
) throws DBWebException;

@Nullable
BaseWebSession getSession(@NotNull String sessionId);

@Nullable
WebSession findWebSession(HttpServletRequest request);

WebSession findWebSession(HttpServletRequest request, boolean errorOnNoFound) throws DBWebException;

Collection<BaseWebSession> getAllActiveSessions();

WebSession getOrRestoreSession(Request httpRequest);

WebHeadlessSession getHeadlessSession(Request request, Session session, boolean create) throws DBException;

boolean touchSession(HttpServletRequest request, HttpServletResponse response) throws DBWebException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
/**
* This class controls all aspects of the application's execution
*/
public abstract class CBApplication<T extends CBServerConfig> extends BaseWebApplication implements WebAuthApplication {
public abstract class CBApplication<T extends CBServerConfig> extends
BaseWebApplication implements WebAuthApplication, GQLApplicationAdapter {

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

Expand Down
Loading

0 comments on commit efb42d3

Please sign in to comment.