Skip to content

Commit b7440f1

Browse files
Merge pull request dbeaver#1101 from dbeaver/tech/CB-2506
CB-2506 create session context for virtual project
2 parents ad31a85 + fe980ff commit b7440f1

2 files changed

Lines changed: 67 additions & 6 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* DBeaver - Universal Database Manager
3+
* Copyright (C) 2010-2022 DBeaver Corp and others
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.cloudbeaver.model.session;
19+
20+
import org.jkiss.code.NotNull;
21+
import org.jkiss.code.Nullable;
22+
import org.jkiss.dbeaver.DBException;
23+
import org.jkiss.dbeaver.model.auth.SMAuthSpace;
24+
import org.jkiss.dbeaver.model.auth.SMAuthToken;
25+
import org.jkiss.dbeaver.model.auth.SMSession;
26+
import org.jkiss.dbeaver.model.auth.SMSessionContext;
27+
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
28+
29+
public class SMWebSessionContext implements SMSessionContext {
30+
31+
private final WebSession session;
32+
private final SMSessionContext parentContext;
33+
34+
public SMWebSessionContext(SMSessionContext parentContext, WebSession session) {
35+
this.parentContext = parentContext;
36+
this.session = session;
37+
}
38+
39+
@Nullable
40+
@Override
41+
public SMSession getSpaceSession(@NotNull DBRProgressMonitor monitor, @NotNull SMAuthSpace space, boolean open) throws DBException {
42+
return parentContext.getSpaceSession(monitor, session.getSessionSpace(), open);
43+
}
44+
45+
@Nullable
46+
@Override
47+
public SMSession findSpaceSession(@NotNull SMAuthSpace space) {
48+
return parentContext.findSpaceSession(session.getSessionSpace());
49+
}
50+
51+
@Override
52+
public SMAuthToken[] getSavedTokens() {
53+
return parentContext.getSavedTokens();
54+
}
55+
56+
@Override
57+
public void addSession(@NotNull SMSession session) {
58+
parentContext.addSession(session);
59+
}
60+
61+
@Override
62+
public boolean removeSession(@NotNull SMSession session) {
63+
return parentContext.removeSession(session);
64+
}
65+
}

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/session/WebSession.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.jkiss.dbeaver.model.security.*;
5959
import org.jkiss.dbeaver.model.security.user.SMObjectPermissions;
6060
import org.jkiss.dbeaver.model.sql.DBQuotaException;
61-
import org.jkiss.dbeaver.registry.DataSourceRegistry;
6261
import org.jkiss.dbeaver.runtime.DBWorkbench;
6362
import org.jkiss.dbeaver.runtime.jobs.DisconnectJob;
6463
import org.jkiss.utils.CommonUtils;
@@ -186,10 +185,6 @@ public SMSessionContext getSessionContext() {
186185
return defaultProject.getSessionContext();
187186
}
188187

189-
public SMSessionContext getSessionAuthContext() {
190-
return sessionAuthContext;
191-
}
192-
193188
@Property
194189
public String getCreateTime() {
195190
return CBModelConstants.ISO_DATE_FORMAT.format(createTime);
@@ -357,9 +352,10 @@ private void loadProjects() {
357352
public VirtualProjectImpl createVirtualProject(RMProject project) {
358353
// Do not filter data sources from user project
359354
DataSourceFilter filter = project.getType() == RMProject.Type.USER ? x -> true : this::isDataSourceAccessible;
355+
SMSessionContext projectSessionContext = new SMWebSessionContext(sessionAuthContext, this);
360356
VirtualProjectImpl sessionProject = application.createProjectImpl(
361357
project,
362-
getSessionAuthContext(),
358+
projectSessionContext,
363359
this,
364360
filter);
365361
DBPDataSourceRegistry dataSourceRegistry = sessionProject.getDataSourceRegistry();

0 commit comments

Comments
 (0)