提交 b8f5f3d6 编写于 作者: S ShadelessFox

#9983 Checkbox to override credentials stored in system

上级 bfdb886b
......@@ -47,11 +47,11 @@ abstract class MySQLWizardPageSettings<WIZARD extends AbstractNativeToolWizard>
{
final DBPConnectionConfiguration connectionInfo = wizard.getSettings().getDataSourceContainer().getActualConnectionConfiguration();
if (connectionInfo != null) {
Group securityGroup = UIUtils.createControlGroup(parent, MySQLUIMessages.tools_db_export_wizard_page_settings_security_group, 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
Group securityGroup = UIUtils.createControlGroup(parent, MySQLUIMessages.tools_db_export_wizard_page_settings_security_group, 3, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
Label infoLabel = new Label(securityGroup, SWT.NONE);
infoLabel.setText(NLS.bind(MySQLUIMessages.tools_db_export_wizard_page_settings_security_label_info, connectionInfo.getUserName()));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
gd.horizontalSpan = 3;
infoLabel.setLayoutData(gd);
Button authButton = new Button(securityGroup, SWT.PUSH);
authButton.setText(MySQLUIMessages.tools_db_export_wizard_page_settings_security_button_auth);
......@@ -78,6 +78,15 @@ abstract class MySQLWizardPageSettings<WIZARD extends AbstractNativeToolWizard>
wizard.getSettings().setToolUserPassword(null);
}
});
Button checkbox = UIUtils.createCheckbox(securityGroup, MySQLUIMessages.tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials, wizard.getSettings().isToolOverrideCredentials());
checkbox.setToolTipText(MySQLUIMessages.tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials_tip);
checkbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
wizard.getSettings().setToolOverrideCredentials(checkbox.getSelection());
}
});
}
}
......
......@@ -143,5 +143,7 @@ public class MySQLUIMessages extends NLS {
public static String tools_db_export_wizard_page_settings_security_label_info;
public static String tools_db_export_wizard_page_settings_security_button_auth;
public static String tools_db_export_wizard_page_settings_security_button_reset;
public static String tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials;
public static String tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials_tip;
public static String tools_db_export_wizard_page_settings_auth_title;
}
......@@ -108,7 +108,9 @@ tools_script_execute_wizard_page_settings_set_script_execution_settings=Set scri
tools_script_execute_wizard_page_settings_checkbox_disable_foreign_key_checks = Disable foreign key checks
tools_script_execute_wizard_page_settings_checkbox_disable_foreign_key_checks_tooltip = Disables foreign key checks while performing restore
tools_db_export_wizard_page_settings_security_group=Security
tools_db_export_wizard_page_settings_security_label_info=Override user credentials ({0}) for external tools.\nIf not set, external tools like ''mysqldump'' will likely use credentials stored in the system.
tools_db_export_wizard_page_settings_security_label_info=Override user credentials ({0}) for external tools.\nExternal tools like ''mysqldump'' may require different set of permissions.
tools_db_export_wizard_page_settings_security_button_auth=Authenticate
tools_db_export_wizard_page_settings_security_button_reset=Reset to default
tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials=Override host credentials
tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials_tip=If checked, host credentials (on this machine, if any) will be overridden with credentials set in connection configuration.
tools_db_export_wizard_page_settings_auth_title=Authentication
......@@ -104,7 +104,9 @@ tools_script_execute_wizard_page_settings_set_script_execution_settings=\u041D\u
tools_script_execute_wizard_page_settings_checkbox_disable_foreign_key_checks = \u041E\u0442\u043A\u043B\u044E\u0447\u0438\u0442\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443 \u0432\u043D\u0435\u0448\u043D\u0438\u0439 \u043A\u043B\u044E\u0447\u0435\u0439
tools_script_execute_wizard_page_settings_checkbox_disable_foreign_key_checks_tooltip = \u041E\u0442\u043A\u043B\u044E\u0447\u0430\u0435\u0442 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443 \u0432\u043D\u0435\u0448\u043D\u0438\u0439 \u043A\u043B\u044E\u0447\u0435\u0439 \u043D\u0430 \u0432\u0440\u0435\u043C\u044F \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F \u0438\u043C\u043F\u043E\u0440\u0442\u0430
tools_db_export_wizard_page_settings_security_group=\u0411\u0435\u0437\u043E\u043F\u0430\u0441\u043D\u043E\u0441\u0442\u044C
tools_db_export_wizard_page_settings_security_label_info=\u0423\u043A\u0430\u0437\u0430\u0442\u044C \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0447\u0451\u0442\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435 \u0432\u043C\u0435\u0441\u0442\u043E \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u044B\u0445 ({0}).\n\u0421\u0442\u043E\u0440\u043E\u043D\u043D\u0438\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B \u043F\u043E \u0442\u0438\u043F\u0443 ''mysqldump'' \u043C\u043E\u0433\u0443\u0442 \u0442\u0440\u0435\u0431\u043E\u0432\u0430\u0442\u044C \u0438\u043D\u044B\u0435 \u0443\u0447\u0451\u0442\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435, \u0438 \u0435\u0441\u043B\u0438 \u043E\u043D\u0438 \u043D\u0435 \u0437\u0430\u0434\u0430\u043D\u044B, \u0442\u043E \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0443\u0447\u0451\u0442\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043C\u044B.
tools_db_export_wizard_page_settings_security_label_info=\u0423\u043A\u0430\u0437\u0430\u0442\u044C \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0447\u0451\u0442\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435 \u0432\u043C\u0435\u0441\u0442\u043E \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u044B\u0445 ({0}).\n\u0421\u0442\u043E\u0440\u043E\u043D\u043D\u0438\u0435 \u0438\u043D\u0441\u0442\u0440\u0443\u043C\u0435\u043D\u0442\u044B \u043F\u043E \u0442\u0438\u043F\u0443 ''mysqldump'' \u043C\u043E\u0433\u0443\u0442 \u0442\u0440\u0435\u0431\u043E\u0432\u0430\u0442\u044C \u0438\u043D\u043E\u0439 \u043D\u0430\u0431\u043E\u0440 \u043F\u0440\u0430\u0432.
tools_db_export_wizard_page_settings_security_button_auth=\u0410\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F
tools_db_export_wizard_page_settings_security_button_reset=\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E
tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials=\u041F\u0435\u0440\u0435\u043E\u043F\u0440\u0435\u0434\u0435\u043B\u0438\u0442\u044C \u0443\u0447\u0451\u0442\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435 \u0441\u0438\u0441\u0442\u0435\u043C\u044B
tools_db_export_wizard_page_settings_security_checkbox_override_host_credentials_tip=\u0415\u0441\u043B\u0438 \u043E\u0442\u043C\u0435\u0447\u0435\u043D\u043E, \u0442\u043E \u043B\u043E\u043A\u0430\u043B\u044C\u043D\u044B\u0435 \u0443\u0447\u0451\u0442\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435 \u0431\u0443\u0434\u0443\u0442 \u043F\u0435\u0440\u0435\u043E\u043F\u0440\u0435\u0434\u0435\u043B\u0435\u043D\u044B \u0443\u0447\u0451\u0442\u043D\u044B\u043C\u0438 \u0434\u0430\u043D\u043D\u044B\u043C\u0438 \u0438\u0437 \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u044F.
tools_db_export_wizard_page_settings_auth_title=\u0410\u0432\u0442\u043E\u0440\u0438\u0437\u0430\u0446\u0438\u044F
package org.jkiss.dbeaver.ext.mysql.tasks;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.task.DBTTask;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolHandler;
import org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolSettings;
......@@ -18,6 +22,32 @@ import java.util.List;
public abstract class MySQLNativeToolHandler<SETTINGS extends AbstractNativeToolSettings<BASE_OBJECT>, BASE_OBJECT extends DBSObject, PROCESS_ARG>
extends AbstractNativeToolHandler<SETTINGS, BASE_OBJECT, PROCESS_ARG> {
private File config;
@Override
protected boolean doExecute(DBRProgressMonitor monitor, DBTTask task, SETTINGS settings, Log log) throws DBException, InterruptedException {
try {
return super.doExecute(monitor, task, settings, log);
} finally {
if (config != null && !config.delete()) {
log.debug("Failed to delete configuration file");
}
}
}
@Override
protected void setupProcessParameters(SETTINGS settings, PROCESS_ARG process_arg, ProcessBuilder process) {
if (!settings.isToolOverrideCredentials()) {
String toolUserPassword = settings.getToolUserPassword();
if (CommonUtils.isEmpty(settings.getToolUserName())) {
toolUserPassword = settings.getDataSourceContainer().getActualConnectionConfiguration().getUserPassword();
}
process.environment().put("MYSQL_PWD", toolUserPassword);
}
}
protected List<String> getMySQLToolCommandLine(AbstractNativeToolHandler<SETTINGS, BASE_OBJECT, PROCESS_ARG> handler, SETTINGS settings, PROCESS_ARG arg) throws IOException {
List<String> cmd = new ArrayList<>();
handler.fillProcessParameters(settings, arg, cmd);
......@@ -35,13 +65,12 @@ public abstract class MySQLNativeToolHandler<SETTINGS extends AbstractNativeTool
toolUserPassword = settings.getDataSourceContainer().getActualConnectionConfiguration().getUserPassword();
}
/*
* Let's assume that if username is not set, then
* native tool must search for credentials on its own.
*/
if (!CommonUtils.isEmpty(toolUserName)) {
String credentialsFile = createCredentialsFile(toolUserName, toolUserPassword);
cmd.add(1, "--defaults-file=" + credentialsFile);
if (settings.isToolOverrideCredentials()) {
config = createCredentialsFile(toolUserName, toolUserPassword);
cmd.add(1, "--defaults-file=" + config.getAbsolutePath());
} else {
cmd.add("-u");
cmd.add(toolUserName);
}
DBPConnectionConfiguration connectionInfo = settings.getDataSourceContainer().getActualConnectionConfiguration();
......@@ -53,22 +82,17 @@ public abstract class MySQLNativeToolHandler<SETTINGS extends AbstractNativeTool
return cmd;
}
/*
* Native tools like mysqldump doesn't read password set in
* MYSQL_PWD (also it's deprecated since MySQL 8.0) and prefer
* to grab credentials from my.cnf (that is located somewhere in the system),
* so we'll generate our own my.cnf with required credentials (#5350)
*/
private static String createCredentialsFile(String username, String password) throws IOException {
private static File createCredentialsFile(String username, String password) throws IOException {
File dir = DBWorkbench.getPlatform().getTempFolder(new VoidProgressMonitor(), "mysql-native-handler"); //$NON-NLS-1$
File cnf = new File(dir, ".my.cnf"); //$NON-NLS-1$
cnf.deleteOnExit();
try (Writer writer = new FileWriter(cnf)) {
writer.write("[client]"); //$NON-NLS-1$
writer.write("\nuser=" + (CommonUtils.isEmpty(username) ? "" : username)); //$NON-NLS-1$
writer.write("\npassword=" + (CommonUtils.isEmpty(password) ? "" : password)); //$NON-NLS-1$
writer.write("\nuser=" + CommonUtils.notEmpty(username)); //$NON-NLS-1$
writer.write("\npassword=" + CommonUtils.notEmpty(password)); //$NON-NLS-1$
}
return cnf.getPath();
return cnf;
}
}
......@@ -51,6 +51,7 @@ public abstract class AbstractNativeToolSettings<BASE_OBJECT extends DBSObject>
private String toolUserName;
private String toolUserPassword;
private boolean toolOverrideCredentials;
private String extraCommandArgs;
private DBPDataSourceContainer dataSourceContainer;
......@@ -121,6 +122,14 @@ public abstract class AbstractNativeToolSettings<BASE_OBJECT extends DBSObject>
this.toolUserPassword = toolUserPassword;
}
public boolean isToolOverrideCredentials() {
return toolOverrideCredentials;
}
public void setToolOverrideCredentials(boolean toolOverrideCredentials) {
this.toolOverrideCredentials = toolOverrideCredentials;
}
public String getExtraCommandArgs() {
return extraCommandArgs;
}
......@@ -198,6 +207,7 @@ public abstract class AbstractNativeToolSettings<BASE_OBJECT extends DBSObject>
clientHomeName = preferenceStore.getString("clientHomeName");
toolUserName = preferenceStore.getString("tool.user");
toolUserPassword = preferenceStore.getString("tool.password");
toolOverrideCredentials = preferenceStore.getBoolean("tool.overrideCredentials");
try {
final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
......@@ -230,6 +240,8 @@ public abstract class AbstractNativeToolSettings<BASE_OBJECT extends DBSObject>
preferenceStore.setValue("clientHomeName", clientHomeName);
}
preferenceStore.setValue("tool.overrideCredentials", toolOverrideCredentials);
try {
final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册