Merge pull request #1100 from dbeaver/tech/CB-2506

CB-2506 create session context for virtual project
This commit is contained in:
Alexander Skoblikov
2022-09-01 17:35:13 +03:00
committed by GitHub
2 changed files with 67 additions and 6 deletions
@@ -0,0 +1,65 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2022 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.session;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.auth.SMAuthSpace;
import org.jkiss.dbeaver.model.auth.SMAuthToken;
import org.jkiss.dbeaver.model.auth.SMSession;
import org.jkiss.dbeaver.model.auth.SMSessionContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
public class SMWebSessionContext implements SMSessionContext {
private final WebSession session;
private final SMSessionContext parentContext;
public SMWebSessionContext(SMSessionContext parentContext, WebSession session) {
this.parentContext = parentContext;
this.session = session;
}
@Nullable
@Override
public SMSession getSpaceSession(@NotNull DBRProgressMonitor monitor, @NotNull SMAuthSpace space, boolean open) throws DBException {
return parentContext.getSpaceSession(monitor, session.getSessionSpace(), open);
}
@Nullable
@Override
public SMSession findSpaceSession(@NotNull SMAuthSpace space) {
return parentContext.findSpaceSession(session.getSessionSpace());
}
@Override
public SMAuthToken[] getSavedTokens() {
return parentContext.getSavedTokens();
}
@Override
public void addSession(@NotNull SMSession session) {
parentContext.addSession(session);
}
@Override
public boolean removeSession(@NotNull SMSession session) {
return parentContext.removeSession(session);
}
}
@@ -58,7 +58,6 @@ import org.jkiss.dbeaver.model.runtime.ProxyProgressMonitor;
import org.jkiss.dbeaver.model.security.*;
import org.jkiss.dbeaver.model.security.user.SMObjectPermissions;
import org.jkiss.dbeaver.model.sql.DBQuotaException;
import org.jkiss.dbeaver.registry.DataSourceRegistry;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.jobs.DisconnectJob;
import org.jkiss.utils.CommonUtils;
@@ -186,10 +185,6 @@ public class WebSession extends AbstractSessionPersistent implements SMSession,
return defaultProject.getSessionContext();
}
public SMSessionContext getSessionAuthContext() {
return sessionAuthContext;
}
@Property
public String getCreateTime() {
return CBModelConstants.ISO_DATE_FORMAT.format(createTime);
@@ -357,9 +352,10 @@ public class WebSession extends AbstractSessionPersistent implements SMSession,
public VirtualProjectImpl createVirtualProject(RMProject project) {
// Do not filter data sources from user project
DataSourceFilter filter = project.getType() == RMProject.Type.USER ? x -> true : this::isDataSourceAccessible;
SMSessionContext projectSessionContext = new SMWebSessionContext(sessionAuthContext, this);
VirtualProjectImpl sessionProject = application.createProjectImpl(
project,
getSessionAuthContext(),
projectSessionContext,
this,
filter);
DBPDataSourceRegistry dataSourceRegistry = sessionProject.getDataSourceRegistry();