Search in sources :

Example 91 with DBPConnectionConfiguration

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

the class OracleConnectionExtraPage method loadSettings.

@Override
public void loadSettings() {
    //oraHomeSelector.setVisible(isOCI);
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    Map<String, String> providerProperties = connectionInfo.getProviderProperties();
    // Settings
    final Object nlsLanguage = providerProperties.get(OracleConstants.PROP_SESSION_LANGUAGE);
    if (nlsLanguage != null) {
        languageCombo.setText(nlsLanguage.toString());
    }
    final Object nlsTerritory = providerProperties.get(OracleConstants.PROP_SESSION_TERRITORY);
    if (nlsTerritory != null) {
        territoryCombo.setText(nlsTerritory.toString());
    }
    final Object dateFormat = providerProperties.get(OracleConstants.PROP_SESSION_NLS_DATE_FORMAT);
    if (dateFormat != null) {
        nlsDateFormat.setText(dateFormat.toString());
    }
    final Object checkSchemaContent = providerProperties.get(OracleConstants.PROP_CHECK_SCHEMA_CONTENT);
    if (checkSchemaContent != null) {
        hideEmptySchemasCheckbox.setSelection(CommonUtils.getBoolean(checkSchemaContent, false));
    }
    showDBAAlwaysCheckbox.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_ALWAYS_SHOW_DBA), false));
    useRuleHint.setSelection(CommonUtils.getBoolean(providerProperties.get(OracleConstants.PROP_USE_RULE_HINT), false));
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 92 with DBPConnectionConfiguration

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

the class OracleConnectionPage method saveSettings.

@Override
public void saveSettings(DBPDataSourceContainer dataSource) {
    DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
    connectionInfo.setClientHomeId(oraHomeSelector.getSelectedHome());
    connectionInfo.setProviderProperty(OracleConstants.PROP_CONNECTION_TYPE, connectionType.name());
    switch(connectionType) {
        case BASIC:
            connectionInfo.setHostName(hostText.getText().trim());
            connectionInfo.setHostPort(portText.getText().trim());
            connectionInfo.setDatabaseName(serviceNameCombo.getText().trim());
            break;
        case TNS:
            connectionInfo.setDatabaseName(tnsNameCombo.getText().trim());
            connectionInfo.setProviderProperty(OracleConstants.PROP_TNS_PATH, tnsPathText.getText());
            break;
        case CUSTOM:
            connectionInfo.setUrl(connectionUrlText.getText());
            break;
    }
    if (osAuthCheck.getSelection()) {
        connectionInfo.setUserName(OracleConstants.OS_AUTH_USER_NAME);
        //$NON-NLS-1$
        connectionInfo.setUserPassword("");
    } else {
        connectionInfo.setUserName(userNameText.getText());
        connectionInfo.setUserPassword(passwordText.getText());
    }
    connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.getTypeForTitle(sidServiceCombo.getText()).name());
    if (userRoleCombo.getSelectionIndex() > 0) {
        connectionInfo.setProviderProperty(OracleConstants.PROP_INTERNAL_LOGON, userRoleCombo.getText().toLowerCase(Locale.ENGLISH));
    } else {
        connectionInfo.getProviderProperties().remove(OracleConstants.PROP_INTERNAL_LOGON);
    }
    saveConnectionURL(connectionInfo);
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 93 with DBPConnectionConfiguration

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

the class OracleConnectionPage method loadSettings.

@Override
public void loadSettings() {
    super.loadSettings();
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    final String sidService = connectionInfo.getProviderProperty(OracleConstants.PROP_SID_SERVICE);
    if (sidService != null) {
        sidServiceCombo.setText(OracleConnectionType.valueOf(sidService).getTitle());
    }
    //if (isOCI) {
    oraHomeSelector.populateHomes(site.getDriver(), connectionInfo.getClientHomeId());
    if (tnsNameCombo.getItemCount() == 0) {
        populateTnsNameCombo();
    }
    if (serviceNameCombo.getItemCount() == 0) {
        for (String alias : getAvailableServiceNames()) {
            serviceNameCombo.add(alias);
        }
    }
    String conTypeProperty = connectionInfo.getProviderProperty(OracleConstants.PROP_CONNECTION_TYPE);
    if (conTypeProperty != null) {
        connectionType = OracleConstants.ConnectionType.valueOf(CommonUtils.toString(conTypeProperty));
    } else {
        connectionType = OracleConstants.ConnectionType.BASIC;
    }
    connectionTypeFolder.setSelection(connectionType.ordinal());
    switch(connectionType) {
        case BASIC:
            hostText.setText(CommonUtils.notEmpty(connectionInfo.getHostName()));
            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("");
            }
            serviceNameCombo.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
            break;
        case TNS:
            {
                tnsNameCombo.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
                String tnsPathProperty = connectionInfo.getProviderProperty(OracleConstants.PROP_TNS_PATH);
                //                }
                if (tnsPathProperty != null) {
                    tnsPathText.setText(tnsPathProperty);
                }
                break;
            }
        case CUSTOM:
            connectionUrlText.setText(CommonUtils.notEmpty(connectionInfo.getUrl()));
            break;
    }
    if (OracleConstants.OS_AUTH_USER_NAME.equals(connectionInfo.getUserName())) {
        userNameText.setEnabled(false);
        passwordText.setEnabled(false);
        osAuthCheck.setSelection(true);
    } else {
        userNameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
        passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
        osAuthCheck.setSelection(false);
    }
    final String roleName = connectionInfo.getProviderProperty(OracleConstants.PROP_INTERNAL_LOGON);
    if (roleName != null) {
        userRoleCombo.setText(roleName.toUpperCase(Locale.ENGLISH));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 94 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 95 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)

Aggregations

DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)172 DBException (org.jkiss.dbeaver.DBException)25 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)16 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)14 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)12 ArrayList (java.util.ArrayList)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 GridData (org.eclipse.swt.layout.GridData)10 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 Button (org.eclipse.swt.widgets.Button)8 Group (org.eclipse.swt.widgets.Group)8 Label (org.eclipse.swt.widgets.Label)8 DBPDataSourceFolder (org.jkiss.dbeaver.model.DBPDataSourceFolder)7 Map (java.util.Map)6 Properties (java.util.Properties)6 DriverDescriptor (org.jkiss.dbeaver.registry.driver.DriverDescriptor)6 File (java.io.File)5