Skip to content

Commit 04365d1

Browse files
committed
dbeaver/pro#6532 fix adding project settings
1 parent 0cc27a7 commit 04365d1

File tree

8 files changed

+24
-104
lines changed

8 files changed

+24
-104
lines changed

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/WebConnectionInfo.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.jkiss.dbeaver.model.rm.RMConstants;
4444
import org.jkiss.dbeaver.model.rm.RMProjectPermission;
4545
import org.jkiss.dbeaver.model.runtime.DBRRunnableParametrized;
46-
import org.jkiss.dbeaver.model.security.SMObjectType;
4746
import org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor;
4847
import org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry;
4948
import org.jkiss.dbeaver.runtime.DBWorkbench;
@@ -526,14 +525,6 @@ public List<String> getTools() {
526525
return tools;
527526
}
528527

529-
public Map<String, Object> getConnectionSettings() throws DBException {
530-
return session.getSecurityController().getObjectSettings(
531-
dataSourceContainer.getId(),
532-
SMObjectType.datasource,
533-
null
534-
);
535-
}
536-
537528
/**
538529
* Updates param that checks whether credentials were saved only in session.
539530
*/

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/rm/local/LocalResourceController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ public void deleteProject(@NotNull String projectId) throws DBException {
308308
log.debug("Deleting project '" + projectId + "'");
309309
IOUtils.deleteDirectory(targetPath);
310310
getSecurityController().deleteAllObjectPermissions(projectId, SMObjectType.project);
311+
getSecurityController().deleteObjectSettings(projectId, SMObjectType.project, null);
311312
synchronized (projectRegistries) {
312313
projectRegistries.remove(projectId);
313314
}

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/DBWServiceCore.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,4 @@ WebConnectionInfo setConnectionNavigatorSettings(
208208
@WebAction(authRequired = false)
209209
boolean cancelAsyncTask(WebSession webSession, String taskId) throws DBWebException;
210210

211-
@NotNull
212-
WebConnectionInfo addConnectionSettings(
213-
@NotNull WebSession webSession,
214-
@NotNull @WebObjectId String projectId,
215-
@NotNull String connectionId,
216-
@NotNull Map<String, Object> settings
217-
) throws DBWebException;
218-
219-
220-
@NotNull
221-
WebConnectionInfo removeConnectionSettings(
222-
@NotNull WebSession webSession,
223-
@NotNull @WebObjectId String projectId,
224-
@NotNull String connectionId,
225-
@Nullable List<String> settingIds
226-
) throws DBWebException;
227-
228211
}

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/WebServiceBindingCore.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,6 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
171171
getProjectReference(env),
172172
env.getArgument("folderPath")
173173
))
174-
.dataFetcher(
175-
"addConnectionSettings", env -> getService(env).addConnectionSettings(
176-
getWebSession(env),
177-
getProjectReference(env),
178-
env.getArgument("id"),
179-
env.getArgument("settings")
180-
)
181-
)
182-
.dataFetcher(
183-
"removeConnectionSettings", env -> getService(env).removeConnectionSettings(
184-
getWebSession(env),
185-
getProjectReference(env),
186-
env.getArgument("id"),
187-
env.getArgument("settingIds")
188-
)
189-
)
190174
;
191175

192176
model.getRuntimeWiring().type(TypeRuntimeWiring.newTypeWiring("AsyncTaskResult").typeResolver(TypeResolutionEnvironment::getObject)

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/core/impl/WebServiceCore.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.jkiss.dbeaver.model.net.ssh.SSHSession;
4949
import org.jkiss.dbeaver.model.rm.RMProjectType;
5050
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
51-
import org.jkiss.dbeaver.model.security.SMObjectType;
5251
import org.jkiss.dbeaver.model.websocket.WSConstants;
5352
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty;
5453
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
@@ -644,48 +643,6 @@ public boolean cancelAsyncTask(WebSession webSession, String taskId) throws DBWe
644643
return webSession.asyncTaskCancel(taskId);
645644
}
646645

647-
@NotNull
648-
@Override
649-
public WebConnectionInfo addConnectionSettings(
650-
@NotNull WebSession webSession,
651-
@NotNull String projectId,
652-
@NotNull String connectionId,
653-
@NotNull Map<String, Object> settings
654-
) throws DBWebException {
655-
WebConnectionInfo connectionInfo = WebDataSourceUtils.getWebConnectionInfo(webSession, projectId, connectionId);
656-
try {
657-
webSession.getSecurityController().addObjectSettings(
658-
connectionId,
659-
SMObjectType.datasource,
660-
settings
661-
);
662-
} catch (DBException e) {
663-
throw new DBWebException("Error adding settings to connection %s".formatted(connectionId), e);
664-
}
665-
return connectionInfo;
666-
}
667-
668-
@NotNull
669-
@Override
670-
public WebConnectionInfo removeConnectionSettings(
671-
@NotNull WebSession webSession,
672-
@NotNull String projectId,
673-
@NotNull String connectionId,
674-
@Nullable List<String> settingIds
675-
) throws DBWebException {
676-
WebConnectionInfo connectionInfo = WebDataSourceUtils.getWebConnectionInfo(webSession, projectId, connectionId);
677-
try {
678-
webSession.getSecurityController().deleteObjectSettings(
679-
connectionId,
680-
SMObjectType.datasource,
681-
settingIds == null ? null : new HashSet<>(settingIds)
682-
);
683-
} catch (DBException e) {
684-
throw new DBWebException("Error adding settings to connection %s".formatted(connectionId), e);
685-
}
686-
return connectionInfo;
687-
}
688-
689646
@Override
690647
public WebGroupPropertiesInfo<ProductSettingDescriptor> getProductSettings(@NotNull WebSession webSession) {
691648
return new WebGroupPropertiesInfo<>(webSession, ProductSettingsRegistry.getInstance().getSettings());

server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/DBWServiceRM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,6 @@ boolean addProjectSettings(
204204
boolean deleteProjectSettings(
205205
@NotNull WebSession webSession,
206206
@NotNull @WebObjectId String projectId,
207-
@NotNull List<String> settings
207+
@Nullable List<String> settings
208208
) throws DBWebException;
209209
}

server/bundles/io.cloudbeaver.service.rm/src/io/cloudbeaver/service/rm/impl/WebServiceRM.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public boolean addProjectSettings(
491491
public boolean deleteProjectSettings(
492492
@NotNull WebSession webSession,
493493
@NotNull String projectId,
494-
@NotNull List<String> settings
494+
@Nullable List<String> settings
495495
) throws DBWebException {
496496
try {
497497
var project = webSession.getProjectById(projectId);
@@ -501,7 +501,7 @@ public boolean deleteProjectSettings(
501501
webSession.getSecurityController().deleteObjectSettings(
502502
projectId,
503503
SMObjectType.project,
504-
new HashSet<>(settings)
504+
settings == null ? null : new HashSet<>(settings)
505505
);
506506
return true;
507507
} catch (DBException e) {

server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/CBEmbeddedSecurityController.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,26 @@ public void addObjectSettings(
112112
) throws DBException {
113113
String userId = getUserIdOrThrow();
114114
try (Connection dbCon = database.openConnection()) {
115-
try (
116-
PreparedStatement dbStat = dbCon.prepareStatement(
117-
"INSERT INTO {table_prefix}CB_OBJECT_SETTINGS" +
118-
"(OBJECT_ID,OBJECT_TYPE,SUBJECT_ID,SETTING_ID,SETTING_VALUE,UPDATED_BY,UPDATE_TIME) " +
119-
"VALUES(?,?,?,?,?,?,CURRENT_TIMESTAMP)")
120-
) {
121-
for (Map.Entry<String, Object> entry : settings.entrySet()) {
122-
dbStat.setString(1, objectId);
123-
dbStat.setString(2, objectType.name());
124-
dbStat.setString(3, userId);
125-
dbStat.setString(4, entry.getKey());
126-
dbStat.setString(5, CommonUtils.toString(entry.getValue()));
127-
dbStat.setString(6, userId);
128-
dbStat.addBatch();
129-
}
130-
dbStat.executeBatch();
115+
try (JDBCTransaction txn = new JDBCTransaction(dbCon)) {
116+
deleteObjectSettings(objectId, objectType, settings.keySet());
117+
try (
118+
PreparedStatement dbStat = dbCon.prepareStatement(
119+
"INSERT INTO {table_prefix}CB_OBJECT_SETTINGS" +
120+
"(OBJECT_ID,OBJECT_TYPE,SUBJECT_ID,SETTING_ID,SETTING_VALUE,UPDATED_BY,UPDATE_TIME) " +
121+
"VALUES(?,?,?,?,?,?,CURRENT_TIMESTAMP)")
122+
) {
123+
for (Map.Entry<String, Object> entry : settings.entrySet()) {
124+
dbStat.setString(1, objectId);
125+
dbStat.setString(2, objectType.name());
126+
dbStat.setString(3, userId);
127+
dbStat.setString(4, entry.getKey());
128+
dbStat.setString(5, CommonUtils.toString(entry.getValue()));
129+
dbStat.setString(6, userId);
130+
dbStat.addBatch();
131+
}
132+
dbStat.executeBatch();
133+
}
134+
txn.commit();
131135
}
132136
} catch (SQLException e) {
133137
throw new DBCException("Error while adding object settings", e);

0 commit comments

Comments
 (0)