提交 381cf471 编写于 作者: S Serge Rider

#11119 Native tool password management enhancement (+MySQL)


Former-commit-id: e96895d3
上级 02579848
......@@ -56,9 +56,8 @@ public abstract class MySQLNativeToolHandler<SETTINGS extends AbstractNativeTool
protected void setupProcessParameters(DBRProgressMonitor monitor, SETTINGS settings, PROCESS_ARG arg, ProcessBuilder process) {
if (!isOverrideCredentials(settings)) {
String toolUserPassword = settings.getToolUserPassword();
if (CommonUtils.isEmpty(settings.getToolUserName())) {
toolUserPassword = settings.getDataSourceContainer().getActualConnectionConfiguration().getUserPassword();
if (CommonUtils.isEmpty(toolUserPassword)) {
toolUserPassword = getDataSourcePassword(monitor, settings);
}
if (CommonUtils.isNotEmpty(toolUserPassword)) {
......
package org.jkiss.dbeaver.ext.postgresql.tasks;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.postgresql.PostgreConstants;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.auth.DBAAuthCredentials;
import org.jkiss.dbeaver.model.auth.DBAAuthModel;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.impl.auth.AuthModelDatabaseNative;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolHandler;
......@@ -18,7 +12,6 @@ import org.jkiss.utils.CommonUtils;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
public abstract class PostgreNativeToolHandler<SETTINGS extends AbstractNativeToolSettings<BASE_OBJECT>, BASE_OBJECT extends DBSObject, PROCESS_ARG>
extends AbstractNativeToolHandler<SETTINGS, BASE_OBJECT, PROCESS_ARG> {
......@@ -27,26 +20,7 @@ public abstract class PostgreNativeToolHandler<SETTINGS extends AbstractNativeTo
protected void setupProcessParameters(DBRProgressMonitor monitor, SETTINGS settings, PROCESS_ARG arg, ProcessBuilder process) {
String userPassword = settings.getToolUserPassword();
if (CommonUtils.isEmpty(userPassword)) {
// Try to obtain password thru auth model (mnakes sense for IAM-like models)
DBPDataSourceContainer dataSourceContainer = settings.getDataSourceContainer();
DBPConnectionConfiguration cfg = new DBPConnectionConfiguration(dataSourceContainer.getActualConnectionConfiguration());
DBAAuthModel authModel = cfg.getAuthModel();
if (authModel != AuthModelDatabaseNative.INSTANCE) {
DBAAuthCredentials credentials = authModel.loadCredentials(dataSourceContainer, cfg);
try {
Properties connProperties = new Properties();
authModel.initAuthentication(monitor, dataSourceContainer.getDataSource(), credentials, cfg, connProperties);
Object authPassword = connProperties.get(DBConstants.DATA_SOURCE_PROPERTY_PASSWORD);
if (authPassword != null) {
userPassword = CommonUtils.toString(authPassword);
}
} catch (DBException e) {
// ignore
}
}
if (CommonUtils.isEmpty(userPassword)) {
userPassword = dataSourceContainer.getActualConnectionConfiguration().getUserPassword();
}
userPassword = getDataSourcePassword(monitor, settings);
}
if (!CommonUtils.isEmpty(userPassword)) {
process.environment().put("PGPASSWORD", userPassword);
......
......@@ -4,12 +4,17 @@ import org.eclipse.core.runtime.IStatus;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.auth.DBAAuthCredentials;
import org.jkiss.dbeaver.model.auth.DBAAuthModel;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.connection.DBPDriver;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocation;
import org.jkiss.dbeaver.model.connection.DBPNativeClientLocationManager;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.impl.auth.AuthModelDatabaseNative;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableContext;
......@@ -20,6 +25,7 @@ import org.jkiss.dbeaver.model.task.DBTTaskHandler;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.ProgressStreamReader;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils;
import org.jkiss.utils.IOUtils;
import java.io.*;
......@@ -537,4 +543,29 @@ public abstract class AbstractNativeToolHandler<SETTINGS extends AbstractNativeT
return GeneralUtils.UTF8_ENCODING;
}
protected String getDataSourcePassword(DBRProgressMonitor monitor, SETTINGS settings) {
// Try to obtain password thru auth model (mnakes sense for IAM-like models)
String userPassword = null;
DBPDataSourceContainer dataSourceContainer = settings.getDataSourceContainer();
DBPConnectionConfiguration cfg = new DBPConnectionConfiguration(dataSourceContainer.getActualConnectionConfiguration());
DBAAuthModel authModel = cfg.getAuthModel();
if (authModel != AuthModelDatabaseNative.INSTANCE) {
DBAAuthCredentials credentials = authModel.loadCredentials(dataSourceContainer, cfg);
try {
Properties connProperties = new Properties();
authModel.initAuthentication(monitor, dataSourceContainer.getDataSource(), credentials, cfg, connProperties);
Object authPassword = connProperties.get(DBConstants.DATA_SOURCE_PROPERTY_PASSWORD);
if (authPassword != null) {
userPassword = CommonUtils.toString(authPassword);
}
} catch (DBException e) {
// ignore
}
}
if (CommonUtils.isEmpty(userPassword)) {
userPassword = dataSourceContainer.getActualConnectionConfiguration().getUserPassword();
}
return userPassword;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册