提交 1aa42785 编写于 作者: S serge-rider

#8557 Anonymous access + "empty password" settings save/load fix


Former-commit-id: 55151af0
上级 3545e43d
......@@ -98,7 +98,7 @@ public interface DBPDriver extends DBPNamedObject
boolean isUseURL();
// Can be created
boolean isInstantiable();
// Driver shipped along with JDK/DBeaver, doesn't need any additional libraries
// Driver shipped along with JDK/DBeaver, doesn't need any additional libraries. Basically it is ODBC driver.
boolean isInternalDriver();
// Custom driver: created by user
boolean isCustom();
......
......@@ -115,12 +115,22 @@ public abstract class JDBCDataSource
{
// It MUST be a JDBC driver
Driver driverInstance = null;
if (getContainer().getDriver().isInstantiable()) {
DBPDriver driver = getContainer().getDriver();
if (driver.isInstantiable()) {
try {
driverInstance = getDriverInstance(monitor);
} catch (DBException e) {
throw new DBCConnectException("Can't create driver instance", e, this);
}
} else {
if (!CommonUtils.isEmpty(driver.getDriverClassName())) {
try {
driver.loadDriver(monitor);
Class.forName(driver.getDriverClassName(), true, driver.getClassLoader());
} catch (Exception e) {
throw new DBCException("Driver class '" + driver.getDriverClassName() + "' not found", e);
}
}
}
DBPConnectionConfiguration connectionInfo = new DBPConnectionConfiguration(container.getActualConnectionConfiguration());
......
......@@ -86,6 +86,7 @@ public class RegistryConstants {
public static final String ATTR_EMBEDDED = "embedded"; //$NON-NLS-1$
public static final String ATTR_CUSTOM_DRIVER_LOADER = "customDriverLoader"; //$NON-NLS-1$
public static final String ATTR_USE_URL_TEMPLATE = "useURL"; //$NON-NLS-1$
public static final String ATTR_INSTANTIABLE = "instantiable"; //$NON-NLS-1$
public static final String ATTR_PROMOTED = "promoted"; //$NON-NLS-1$
public static final String ATTR_ICON = "icon"; //$NON-NLS-1$
......
......@@ -127,6 +127,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver {
private boolean licenseRequired;
private boolean customDriverLoader;
private boolean useURLTemplate;
private boolean instantiable;
private boolean custom;
private boolean modified;
private boolean disabled;
......@@ -173,6 +174,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver {
this.id = id;
this.custom = true;
this.useURLTemplate = true;
this.instantiable = true;
this.promoted = 0;
this.origName = null;
......@@ -208,6 +210,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver {
this.licenseRequired = copyFrom.licenseRequired;
this.customDriverLoader = copyFrom.customDriverLoader;
this.useURLTemplate = copyFrom.useURLTemplate;
this.instantiable = copyFrom.instantiable;
this.promoted = copyFrom.promoted;
this.nativeClientHomes.addAll(copyFrom.nativeClientHomes);
for (DriverFileSource fs : copyFrom.fileSources) {
......@@ -254,6 +257,7 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver {
this.clientRequired = CommonUtils.getBoolean(config.getAttribute(RegistryConstants.ATTR_CLIENT_REQUIRED), false);
this.customDriverLoader = CommonUtils.getBoolean(config.getAttribute(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER), false);
this.useURLTemplate = CommonUtils.getBoolean(config.getAttribute(RegistryConstants.ATTR_USE_URL_TEMPLATE), true);
this.instantiable = CommonUtils.getBoolean(config.getAttribute(RegistryConstants.ATTR_INSTANTIABLE), true);
this.promoted = CommonUtils.toInt(config.getAttribute(RegistryConstants.ATTR_PROMOTED), 0);
this.supportsDriverProperties = CommonUtils.getBoolean(config.getAttribute(RegistryConstants.ATTR_SUPPORTS_DRIVER_PROPERTIES), true);
this.embedded = CommonUtils.getBoolean(config.getAttribute(RegistryConstants.ATTR_EMBEDDED));
......@@ -690,7 +694,11 @@ public class DriverDescriptor extends AbstractDescriptor implements DBPDriver {
@Override
public boolean isInstantiable() {
return !CommonUtils.isEmpty(driverClassName);
return instantiable && !CommonUtils.isEmpty(driverClassName);
}
public void setInstantiable(boolean instantiable) {
this.instantiable = instantiable;
}
@Override
......
......@@ -65,8 +65,7 @@ public class DriverDescriptorSerializerLegacy extends DriverDescriptorSerializer
xml.addAttribute(RegistryConstants.ATTR_CATEGORY, driver.getCategory());
}
xml.addAttribute(RegistryConstants.ATTR_CATEGORIES, String.join(",", driver.getCategories()));
xml.addAttribute(RegistryConstants.ATTR_CUSTOM, driver.isCustom());
xml.addAttribute(RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
xml.addAttribute(RegistryConstants.ATTR_NAME, driver.getName());
xml.addAttribute(RegistryConstants.ATTR_CLASS, driver.getDriverClassName());
if (!CommonUtils.isEmpty(driver.getSampleURL())) {
......@@ -79,6 +78,19 @@ public class DriverDescriptorSerializerLegacy extends DriverDescriptorSerializer
if (driver.isCustomDriverLoader()) {
xml.addAttribute(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER, driver.isCustomDriverLoader());
}
xml.addAttribute(RegistryConstants.ATTR_CUSTOM, driver.isCustom());
if (driver.isEmbedded()) {
xml.addAttribute(RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
}
if (driver.isAnonymousAccess()) {
xml.addAttribute(RegistryConstants.ATTR_ANONYMOUS, driver.isAnonymousAccess());
}
if (driver.isAllowsEmptyPassword()) {
xml.addAttribute("allowsEmptyPassword", driver.isAllowsEmptyPassword());
}
if (!driver.isInstantiable()) {
xml.addAttribute(RegistryConstants.ATTR_INSTANTIABLE, driver.isInstantiable());
}
// Libraries
for (DBPDriverLibrary lib : driver.getDriverLibraries()) {
......@@ -209,7 +221,9 @@ public class DriverDescriptorSerializerLegacy extends DriverDescriptorSerializer
curDriver.setSampleURL(CommonUtils.toString(atts.getValue(RegistryConstants.ATTR_URL), curDriver.getSampleURL()));
curDriver.setDriverDefaultPort(CommonUtils.toString(atts.getValue(RegistryConstants.ATTR_PORT), curDriver.getDefaultPort()));
curDriver.setEmbedded(CommonUtils.getBoolean(atts.getValue(RegistryConstants.ATTR_EMBEDDED), curDriver.isEmbedded()));
curDriver.setAnonymousAccess(CommonUtils.getBoolean(atts.getValue(RegistryConstants.ATTR_ANONYMOUS), curDriver.isAnonymousAccess()));
curDriver.setAllowsEmptyPassword(CommonUtils.getBoolean(atts.getValue("allowsEmptyPassword"), curDriver.isAllowsEmptyPassword()));
curDriver.setInstantiable(CommonUtils.getBoolean(atts.getValue(RegistryConstants.ATTR_INSTANTIABLE), curDriver.isInstantiable()));
}
if (atts.getValue(RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER) != null) {
curDriver.setCustomDriverLoader((
......
......@@ -63,6 +63,7 @@ public class DriverDescriptorSerializerModern extends DriverDescriptorSerializer
JSONUtils.field(json, RegistryConstants.ATTR_EMBEDDED, driver.isEmbedded());
JSONUtils.field(json, RegistryConstants.ATTR_ANONYMOUS, driver.isAnonymousAccess());
JSONUtils.field(json, "allowsEmptyPassword", driver.isAnonymousAccess());
JSONUtils.field(json, RegistryConstants.ATTR_INSTANTIABLE, driver.isInstantiable());
if (driver.isCustomDriverLoader()) {
JSONUtils.field(json, RegistryConstants.ATTR_CUSTOM_DRIVER_LOADER, driver.isCustomDriverLoader());
}
......
......@@ -26,6 +26,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
......@@ -98,6 +99,7 @@ public class DriverEditDialog extends HelpEnabledDialog {
private Button embeddedDriverCheck;
private Button anonymousDriverCheck;
private Button allowsEmptyPasswordCheck;
private Button nonInstantiableCheck;
private boolean showAddFiles = false;
......@@ -164,7 +166,7 @@ public class DriverEditDialog extends HelpEnabledDialog {
@Override
protected IDialogSettings getDialogBoundsSettings() {
return UIUtils.getDialogSettings(DIALOG_ID);
return null;//UIUtils.getDialogSettings(DIALOG_ID);
}
@Override
......@@ -243,28 +245,26 @@ public class DriverEditDialog extends HelpEnabledDialog {
driverURLText.addModifyListener(e -> onChangeProperty());
driverURLText.setEnabled(driver == null || driver.isUseURL());
gd = new GridData(GridData.FILL_HORIZONTAL);
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
driverPortText = UIUtils.createLabelText(propsGroup, UIConnectionMessages.dialog_edit_driver_label_default_port, driver.getDefaultPort() == null ? "" : driver.getDefaultPort(), SWT.BORDER | advStyle, gd);
driverPortText.setLayoutData(new GridData(SWT.NONE));
driverPortText.addModifyListener(e -> onChangeProperty());
Composite optionsPanel = UIUtils.createComposite(propsGroup, 3);
Composite optionsPanel = new Composite(propsGroup, SWT.NONE);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
optionsPanel.setLayoutData(gd);
optionsPanel.setLayout(new RowLayout());
embeddedDriverCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_embedded_label, UIConnectionMessages.dialog_edit_driver_embedded_tip, driver.isEmbedded(), 1);
embeddedDriverCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
anonymousDriverCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_anonymous_label, UIConnectionMessages.dialog_edit_driver_anonymous_tip, driver.isAnonymousAccess(), 1);
anonymousDriverCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
allowsEmptyPasswordCheck = UIUtils.createCheckbox(optionsPanel, UIConnectionMessages.dialog_edit_driver_aloows_empty_password_label, UIConnectionMessages.dialog_edit_driver_aloows_empty_password_tip, driver.isAnonymousAccess(), 1);
allowsEmptyPasswordCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
nonInstantiableCheck = UIUtils.createCheckbox(optionsPanel, "Use legacy JDBC instantiation", "Do not instantiate driver directly, use DriverManager always.", !driver.isInstantiable(), 1);
if (isReadOnly) {
embeddedDriverCheck.setEnabled(false);
anonymousDriverCheck.setEnabled(false);
allowsEmptyPasswordCheck.setEnabled(false);
nonInstantiableCheck.setEnabled(false);
}
}
......@@ -726,6 +726,7 @@ public class DriverEditDialog extends HelpEnabledDialog {
embeddedDriverCheck.setSelection(driver.isEmbedded());
anonymousDriverCheck.setSelection(driver.isAnonymousAccess());
allowsEmptyPasswordCheck.setSelection(driver.isAllowsEmptyPassword());
nonInstantiableCheck.setSelection(!driver.isInstantiable());
if (original) {
resetLibraries(true);
......@@ -783,6 +784,7 @@ public class DriverEditDialog extends HelpEnabledDialog {
driver.setEmbedded(embeddedDriverCheck.getSelection());
driver.setAnonymousAccess(anonymousDriverCheck.getSelection());
driver.setAllowsEmptyPassword(allowsEmptyPasswordCheck.getSelection());
driver.setInstantiable(!nonInstantiableCheck.getSelection());
// driver.setAnonymousAccess(anonymousCheck.getSelection());
driver.setModified(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册