Search in sources :

Example 6 with DBPConnectionConfiguration

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

the class DB2ConnectionTracePage method loadSettings.

@Override
public void loadSettings() {
    // Load values from new connection info
    DBPConnectionConfiguration connectionInfo = site.getActiveDataSource().getConnectionConfiguration();
    Map<String, String> providerProperties = connectionInfo.getProviderProperties();
    // Settings
    enableTraceCheck.setSelection(CommonUtils.getBoolean(providerProperties.get(DB2Constants.PROP_TRACE_ENABLED), false));
    if (!enableTraceCheck.getSelection()) {
        traceEnableState = ControlEnableState.disable(traceGroup);
    }
    if (providerProperties.containsKey(DB2Constants.PROP_TRACE_FOLDER)) {
        folderText.setText(CommonUtils.toString(providerProperties.get(DB2Constants.PROP_TRACE_FOLDER)));
    }
    if (providerProperties.containsKey(DB2Constants.PROP_TRACE_FILE)) {
        fileNameText.setText(CommonUtils.toString(providerProperties.get(DB2Constants.PROP_TRACE_FILE)));
    }
    traceAppendCheck.setSelection(CommonUtils.getBoolean(providerProperties.get(DB2Constants.PROP_TRACE_APPEND), false));
    int traceLevel = CommonUtils.toInt(providerProperties.get(DB2Constants.PROP_TRACE_LEVEL));
    for (LevelConfig level : levels) {
        level.checkbox.setSelection((traceLevel & level.level) != 0);
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)

Example 7 with DBPConnectionConfiguration

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

the class PostgreWizardPageSettings 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.getProviderProperty(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 pg_dump'.");
        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.setProviderProperty(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.getProviderProperties().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 8 with DBPConnectionConfiguration

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

the class WMIDataSource method initialize.

@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
    final DBPConnectionConfiguration connectionInfo = container.getActualConnectionConfiguration();
    try {
        WMIService service = WMIService.connect(connectionInfo.getServerName(), connectionInfo.getHostName(), connectionInfo.getUserName(), connectionInfo.getUserPassword(), null, connectionInfo.getDatabaseName());
        this.rootNamespace = new WMINamespace(null, this, connectionInfo.getDatabaseName(), service);
    } catch (UnsatisfiedLinkError e) {
        throw new DBException("Can't link with WMI native library", e);
    } catch (Throwable e) {
        throw new DBException("Can't connect to WMI service", e);
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBException(org.jkiss.dbeaver.DBException) WMIService(org.jkiss.wmi.service.WMIService)

Example 9 with DBPConnectionConfiguration

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

the class WMIConnectionPage method loadSettings.

@Override
public void loadSettings() {
    // Load values from new connection info
    DBPDataSourceContainer activeDataSource = site.getActiveDataSource();
    DBPConnectionConfiguration connectionInfo = activeDataSource.getConnectionConfiguration();
    if (connectionInfo.getHostName() == null) {
        connectionInfo.setHostName(DEFAULT_HOST);
    }
    if (connectionInfo.getDatabaseName() == null) {
        connectionInfo.setDatabaseName(DEFAULT_NAMESPACE);
    }
    if (hostText != null) {
        hostText.setText(CommonUtils.notEmpty(connectionInfo.getHostName()));
    }
    if (domainText != null) {
        domainText.setText(CommonUtils.notEmpty(connectionInfo.getServerName()));
    }
    if (usernameText != null) {
        usernameText.setText(CommonUtils.notEmpty(connectionInfo.getUserName()));
    }
    if (passwordText != null) {
        passwordText.setText(CommonUtils.notEmpty(connectionInfo.getUserPassword()));
    }
    if (namespaceCombo != null) {
        namespaceCombo.setText(CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 10 with DBPConnectionConfiguration

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

the class DataSourceDescriptor method processEvents.

private void processEvents(DBRProgressMonitor monitor, DBPConnectionEventType eventType) {
    DBPConnectionConfiguration info = getActualConnectionConfiguration();
    DBRShellCommand command = info.getEvent(eventType);
    if (command != null && command.isEnabled()) {
        Map<String, Object> variables = new HashMap<>();
        for (Map.Entry<String, String> entry : info.getProperties().entrySet()) {
            variables.put(CommonUtils.toString(entry.getKey()), entry.getValue());
        }
        variables.put(RegistryConstants.VARIABLE_HOST, info.getHostName());
        variables.put(RegistryConstants.VARIABLE_PORT, info.getHostPort());
        variables.put(RegistryConstants.VARIABLE_SERVER, info.getServerName());
        variables.put(RegistryConstants.VARIABLE_DATABASE, info.getDatabaseName());
        variables.put(RegistryConstants.VARIABLE_USER, info.getUserName());
        variables.put(RegistryConstants.VARIABLE_PASSWORD, info.getUserPassword());
        variables.put(RegistryConstants.VARIABLE_URL, info.getUrl());
        final DBRProcessDescriptor processDescriptor = new DBRProcessDescriptor(command, variables);
        monitor.subTask("Execute process " + processDescriptor.getName());
        DBUserInterface.getInstance().executeProcess(processDescriptor);
        if (command.isWaitProcessFinish()) {
            processDescriptor.waitFor();
        }
        addChildProcess(processDescriptor);
    }
}
Also used : 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