Search in sources :

Example 31 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.

the class PostgreDataSource method openConnection.

@Override
protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @NotNull String purpose) throws DBCException {
    Connection pgConnection;
    final DBPConnectionConfiguration conConfig = getContainer().getActualConnectionConfiguration();
    if (activeDatabaseName != null && !CommonUtils.equalObjects(activeDatabaseName, conConfig.getDatabaseName())) {
        // If database was changed then use new name for connection
        final DBPConnectionConfiguration originalConfig = new DBPConnectionConfiguration(conConfig);
        try {
            // Patch URL with new database name
            conConfig.setDatabaseName(activeDatabaseName);
            conConfig.setUrl(getContainer().getDriver().getDataSourceProvider().getConnectionURL(getContainer().getDriver(), conConfig));
            pgConnection = super.openConnection(monitor, purpose);
        } finally {
            conConfig.setDatabaseName(originalConfig.getDatabaseName());
            conConfig.setUrl(originalConfig.getUrl());
        }
    } else {
        pgConnection = super.openConnection(monitor, purpose);
    }
    {
        // Provide client info
        try {
            pgConnection.setClientInfo("ApplicationName", DBUtils.getClientApplicationName(getContainer(), purpose));
        } catch (Throwable e) {
            // just ignore
            log.debug(e);
        }
    }
    return pgConnection;
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) Connection(java.sql.Connection)

Example 32 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.

the class ExasolWizardPageSettings method createSecurityGroup.

public void createSecurityGroup(Composite parent) {
    try {
        final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
        final DBPConnectionConfiguration connectionInfo = wizard.getConnectionInfo();
        final String authProperty = DBConstants.INTERNAL_PROP_PREFIX + "-auth-" + wizard.getObjectsName() + "@";
        String authUser = null;
        String authPassword = null;
        {
            String authValue = connectionInfo.getProperty(authProperty);
            if (authValue != null) {
                String authCredentials = encrypter.decrypt(authValue);
                int divPos = authCredentials.indexOf(':');
                if (divPos != -1) {
                    authUser = authCredentials.substring(0, divPos);
                    authPassword = authCredentials.substring(divPos + 1);
                }
            }
        }
        wizard.setToolUserName(authUser == null ? connectionInfo.getUserName() : authUser);
        wizard.setToolUserPassword(authPassword == null ? connectionInfo.getUserPassword() : authPassword);
        final boolean savePassword = authUser != null;
        Group securityGroup = UIUtils.createControlGroup(parent, "Security", 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        Label infoLabel = new Label(securityGroup, SWT.NONE);
        infoLabel.setText("Override user credentials (" + wizard.getConnectionInfo().getUserName() + ") for objects '" + wizard.getObjectsName() + "'.\nExternal tools like 'mysqldump' may require different set of permissions.");
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        infoLabel.setLayoutData(gd);
        Button authButton = new Button(securityGroup, SWT.PUSH);
        authButton.setText("Authentication");
        authButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BaseAuthDialog authDialog = new BaseAuthDialog(getShell(), "Authentication", false);
                authDialog.setUserName(wizard.getToolUserName());
                authDialog.setUserPassword(wizard.getToolUserPassword());
                authDialog.setSavePassword(savePassword);
                if (authDialog.open() == IDialogConstants.OK_ID) {
                    wizard.setToolUserName(authDialog.getUserName());
                    wizard.setToolUserPassword(authDialog.getUserPassword());
                    if (authDialog.isSavePassword()) {
                        try {
                            connectionInfo.setProperty(authProperty, encrypter.encrypt(wizard.getToolUserName() + ':' + wizard.getToolUserPassword()));
                        } catch (EncryptionException e1) {
                        // Never be here
                        }
                    }
                }
            }
        });
        Button resetButton = new Button(securityGroup, SWT.PUSH);
        resetButton.setText("Reset to default");
        resetButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                connectionInfo.getProperties().remove(authProperty);
                wizard.setToolUserName(connectionInfo.getUserName());
                wizard.setToolUserPassword(connectionInfo.getUserPassword());
            }
        });
    } catch (EncryptionException e) {
    // Never be here
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SecuredPasswordEncrypter(org.jkiss.dbeaver.registry.encode.SecuredPasswordEncrypter) Button(org.eclipse.swt.widgets.Button) BaseAuthDialog(org.jkiss.dbeaver.ui.dialogs.connection.BaseAuthDialog) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EncryptionException(org.jkiss.dbeaver.registry.encode.EncryptionException)

Example 33 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.

the class ExasolConnectionPage method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    setImageDescriptor(EXASOL_LOGO_IMG);
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    if (hostText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
            hostText.setText(connectionInfo.getHostName());
        } else {
            hostText.setText("");
        }
    }
    if (portText != null) {
        if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
            portText.setText(String.valueOf(connectionInfo.getHostPort()));
        } else if (site.getDriver().getDefaultPort() != null) {
            portText.setText(site.getDriver().getDefaultPort());
        } else {
            portText.setText("8563");
        }
    }
    if (usernameText != null) {
        usernameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
    }
    if (passwordText != null) {
        passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
    }
    String backupHostText = connectionInfo.getProviderProperty(ExasolConstants.DRV_BACKUP_HOST_LIST);
    if (!CommonUtils.isEmpty(backupHostText)) {
        this.backupHostLabel.setEnabled(true);
        this.backupHostText.setText(backupHostText);
        this.backupHostText.setEnabled(true);
        this.useBackupHostList.setSelection(true);
    } else {
        this.backupHostLabel.setEnabled(false);
        this.backupHostText.setEnabled(false);
        this.useBackupHostList.setSelection(false);
    }
    String encryptComm = connectionInfo.getProviderProperty(ExasolConstants.DRV_ENCRYPT);
    if (encryptComm != null) {
        if (encryptComm.equals("1"))
            this.encryptCommunication.setEnabled(true);
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 34 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.

the class GenericConnectionPage method createEmbeddedDatabase.

private void createEmbeddedDatabase() {
    String paramCreate = CommonUtils.toString(site.getDriver().getDriverParameter(GenericConstants.PARAM_CREATE_URL_PARAM));
    DataSourceDescriptor dataSource = (DataSourceDescriptor) site.getActiveDataSource();
    final DataSourceDescriptor testDataSource = new DataSourceDescriptor(site.getDataSourceRegistry(), dataSource.getId(), dataSource.getDriver(), new DBPConnectionConfiguration(dataSource.getConnectionConfiguration()));
    saveSettings(testDataSource);
    DBPConnectionConfiguration cfg = testDataSource.getConnectionConfiguration();
    cfg.setUrl(cfg.getUrl() + paramCreate);
    String databaseName = cfg.getDatabaseName();
    testDataSource.setName(databaseName);
    if (!UIUtils.confirmAction(getShell(), "Create Database", "Are you sure you want to create database '" + databaseName + "'?")) {
        testDataSource.dispose();
        return;
    }
    try {
        site.getRunnableContext().run(true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    createEmbeddedDatabase(monitor, testDataSource);
                } catch (DBException e1) {
                    throw new InvocationTargetException(e1);
                }
            }
        });
        MessageDialog.openInformation(getShell(), "Database Create", "Database '" + databaseName + "' created!");
    } catch (InvocationTargetException e1) {
        UIUtils.showErrorDialog(getShell(), "Create database", "Error creating database", e1.getTargetException());
    } catch (InterruptedException e1) {
    // Just ignore
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBException(org.jkiss.dbeaver.DBException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 35 with DBPConnectionConfiguration

use of org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration in project dbeaver by serge-rider.

the class ConfigImportWizard method importConnection.

private void importConnection(ImportConnectionInfo connectionInfo) throws DBException {
    try {
        adaptConnectionUrl(connectionInfo);
    } catch (DBException e) {
        UIUtils.showMessageBox(getShell(), "Extract URL parameters", e.getMessage(), SWT.ICON_WARNING);
    }
    final DataSourceRegistry dataSourceRegistry = DBeaverCore.getInstance().getProjectRegistry().getActiveDataSourceRegistry();
    String name = connectionInfo.getAlias();
    for (int i = 0; ; i++) {
        if (dataSourceRegistry.findDataSourceByName(name) == null) {
            break;
        }
        name = connectionInfo.getAlias() + " " + (i + 1);
    }
    DBPConnectionConfiguration config = new DBPConnectionConfiguration();
    config.setProperties(connectionInfo.getProperties());
    config.setProviderProperties(connectionInfo.getProviderProperties());
    config.setUrl(connectionInfo.getUrl());
    config.setUserName(connectionInfo.getUser());
    config.setUserPassword(connectionInfo.getPassword());
    config.setHostName(connectionInfo.getHost());
    config.setHostPort(connectionInfo.getPort());
    config.setDatabaseName(connectionInfo.getDatabase());
    DataSourceDescriptor dataSource = new DataSourceDescriptor(dataSourceRegistry, DataSourceDescriptor.generateNewId(connectionInfo.getDriver()), connectionInfo.getDriver(), config);
    dataSource.setName(name);
    dataSource.setSavePassword(!CommonUtils.isEmpty(config.getUserPassword()));
    dataSourceRegistry.addDataSource(dataSource);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Aggregations

DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)38 DBException (org.jkiss.dbeaver.DBException)7 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)4 ArrayList (java.util.ArrayList)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 Button (org.eclipse.swt.widgets.Button)3 Group (org.eclipse.swt.widgets.Group)3 Label (org.eclipse.swt.widgets.Label)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 EncryptionException (org.jkiss.dbeaver.registry.encode.EncryptionException)3 SecuredPasswordEncrypter (org.jkiss.dbeaver.registry.encode.SecuredPasswordEncrypter)3 BaseAuthDialog (org.jkiss.dbeaver.ui.dialogs.connection.BaseAuthDialog)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBPConnectionBootstrap (org.jkiss.dbeaver.model.connection.DBPConnectionBootstrap)2 DBPConnectionEventType (org.jkiss.dbeaver.model.connection.DBPConnectionEventType)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)2 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)2