mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-2415 Do not save admin connection on connect in public interface (#1083)
This commit is contained in:
@@ -34,6 +34,7 @@ import org.jkiss.dbeaver.model.DBPDataSourceContainer;
|
||||
import org.jkiss.dbeaver.model.DBPDataSourceFolder;
|
||||
import org.jkiss.dbeaver.model.access.DBAAuthCredentials;
|
||||
import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
|
||||
import org.jkiss.dbeaver.model.app.DBPProject;
|
||||
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
|
||||
import org.jkiss.dbeaver.model.connection.DBPDriver;
|
||||
import org.jkiss.dbeaver.model.impl.auth.AuthModelDatabaseNativeCredentials;
|
||||
@@ -42,7 +43,6 @@ import org.jkiss.dbeaver.model.navigator.DBNModel;
|
||||
import org.jkiss.dbeaver.model.navigator.DBNProject;
|
||||
import org.jkiss.dbeaver.model.net.DBWHandlerConfiguration;
|
||||
import org.jkiss.dbeaver.model.net.ssh.SSHConstants;
|
||||
import org.jkiss.dbeaver.model.rm.RMProject;
|
||||
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
|
||||
import org.jkiss.dbeaver.registry.DataSourceNavigatorSettings;
|
||||
import org.jkiss.dbeaver.registry.DataSourceProviderDescriptor;
|
||||
@@ -340,6 +340,9 @@ public class WebServiceUtils extends WebCommonUtils {
|
||||
DBNModel.updateConfigAndRefreshDatabases(projectNode.getDatabases());
|
||||
}
|
||||
|
||||
public static boolean isGlobalProject(DBPProject project) {
|
||||
return CommonUtils.equalObjects(CBApplication.getInstance().getDefaultProjectName(), project.getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+11
-6
@@ -21,17 +21,14 @@ import io.cloudbeaver.DBWConstants;
|
||||
import io.cloudbeaver.DBWebException;
|
||||
import io.cloudbeaver.WebServiceUtils;
|
||||
import io.cloudbeaver.model.*;
|
||||
import io.cloudbeaver.model.app.BaseWebApplication;
|
||||
import io.cloudbeaver.model.app.WebAppConfiguration;
|
||||
import io.cloudbeaver.model.session.WebSession;
|
||||
import io.cloudbeaver.registry.WebHandlerRegistry;
|
||||
import io.cloudbeaver.registry.WebSessionHandlerDescriptor;
|
||||
import io.cloudbeaver.server.CBAppConfig;
|
||||
import io.cloudbeaver.server.CBApplication;
|
||||
import io.cloudbeaver.server.CBPlatform;
|
||||
import io.cloudbeaver.service.core.DBWServiceCore;
|
||||
import io.cloudbeaver.utils.WebDataSourceUtils;
|
||||
import io.cloudbeaver.utils.WebConnectionFolderUtils;
|
||||
import io.cloudbeaver.utils.WebDataSourceUtils;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.code.Nullable;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
@@ -55,7 +52,6 @@ import org.jkiss.dbeaver.registry.DataSourceDescriptor;
|
||||
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
|
||||
import org.jkiss.dbeaver.registry.network.NetworkHandlerDescriptor;
|
||||
import org.jkiss.dbeaver.registry.network.NetworkHandlerRegistry;
|
||||
import org.jkiss.dbeaver.runtime.DBWorkbench;
|
||||
import org.jkiss.dbeaver.runtime.jobs.ConnectionTestJob;
|
||||
import org.jkiss.dbeaver.utils.RuntimeUtils;
|
||||
import org.jkiss.utils.CommonUtils;
|
||||
@@ -294,6 +290,8 @@ public class WebServiceCore implements DBWServiceCore {
|
||||
connectionInfo.clearSavedCredentials();
|
||||
}
|
||||
// Mark all specified network configs as saved
|
||||
boolean[] saveConfig = new boolean[1];
|
||||
|
||||
if (networkCredentials != null) {
|
||||
networkCredentials.forEach(c -> {
|
||||
if (CommonUtils.toBoolean(c.isSavePassword()) && !CommonUtils.isEmpty(c.getUserName())) {
|
||||
@@ -302,7 +300,7 @@ public class WebServiceCore implements DBWServiceCore {
|
||||
handlerCfg.setUserName(c.getUserName());
|
||||
handlerCfg.setPassword(c.getPassword());
|
||||
handlerCfg.setSavePassword(true);
|
||||
dataSourceContainer.persistConfiguration();
|
||||
saveConfig[0] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -316,6 +314,13 @@ public class WebServiceCore implements DBWServiceCore {
|
||||
true);
|
||||
|
||||
WebDataSourceUtils.saveCredentialsInDataSource(connectionInfo, dataSourceContainer, dataSourceContainer.getConnectionConfiguration());
|
||||
saveConfig[0] = true;
|
||||
}
|
||||
if (WebServiceUtils.isGlobalProject(dataSourceContainer.getProject())) {
|
||||
// Do not flush config for global project (only admin can do it - CB-2415)
|
||||
saveConfig[0] = false;
|
||||
}
|
||||
if (saveConfig[0]) {
|
||||
dataSourceContainer.persistConfiguration();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -660,7 +660,7 @@ public class WebServiceAdmin implements DBWServiceAdmin {
|
||||
String connectionId
|
||||
) throws DBWebException {
|
||||
DBPProject globalProject = webSession.getProjectById(projectId);
|
||||
if (!CommonUtils.equalObjects(globalProject.getName(), CBApplication.getInstance().getDefaultProjectName())) {
|
||||
if (!WebServiceUtils.isGlobalProject(globalProject)) {
|
||||
throw new DBWebException("Project '" + projectId + "'is not global");
|
||||
}
|
||||
try {
|
||||
@@ -685,7 +685,7 @@ public class WebServiceAdmin implements DBWServiceAdmin {
|
||||
@NotNull List<String> subjects
|
||||
) throws DBWebException {
|
||||
DBPProject globalProject = webSession.getProjectById(projectId);
|
||||
if (!CommonUtils.equalObjects(globalProject.getName(), CBApplication.getInstance().getDefaultProjectName())) {
|
||||
if (!WebServiceUtils.isGlobalProject(globalProject)) {
|
||||
throw new DBWebException("Project '" + projectId + "'is not global");
|
||||
}
|
||||
DBPDataSourceContainer dataSource = getGlobalRegistry(webSession).getDataSource(connectionId);
|
||||
|
||||
Reference in New Issue
Block a user