Search in sources :

Example 1 with EncryptionException

use of org.jkiss.dbeaver.runtime.encode.EncryptionException in project dbeaver by dbeaver.

the class PrefPageDrivers method performDefaults.

@Override
protected void performDefaults() {
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    versionUpdateCheck.setSelection(store.getBoolean(ModelPreferences.UI_DRIVERS_VERSION_UPDATE));
    proxyHostText.setText(store.getString(ModelPreferences.UI_PROXY_HOST));
    proxyPortSpinner.setSelection(store.getInt(ModelPreferences.UI_PROXY_PORT));
    proxyUserText.setText(store.getString(ModelPreferences.UI_PROXY_USER));
    // Load and decrypt password
    String passwordString = store.getString(ModelPreferences.UI_PROXY_PASSWORD);
    if (!CommonUtils.isEmpty(passwordString) && encrypter != null) {
        try {
            passwordString = encrypter.decrypt(passwordString);
        } catch (EncryptionException e) {
            log.warn(e);
        }
    }
    proxyPasswordText.setText(passwordString);
    customDriversHome.setText(DriverDescriptor.getCustomDriversHome().getAbsolutePath());
    for (String source : DriverDescriptor.getDriversSources()) {
        sourceList.add(source);
    }
    super.performDefaults();
}
Also used : EncryptionException(org.jkiss.dbeaver.runtime.encode.EncryptionException) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 2 with EncryptionException

use of org.jkiss.dbeaver.runtime.encode.EncryptionException in project dbeaver by dbeaver.

the class PostgreToolWizardPageSettings method createSecurityGroup.

public void createSecurityGroup(Composite parent) {
    try {
        final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
        final DBPConnectionConfiguration connectionInfo = wizard.getSettings().getDataSourceContainer().getActualConnectionConfiguration();
        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);
                }
            }
        }
        final boolean savePassword = authUser != null;
        Group securityGroup = UIUtils.createControlGroup(parent, PostgreMessages.wizard_backup_page_setting_group_security, 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        Label infoLabel = new Label(securityGroup, SWT.NONE);
        infoLabel.setText(NLS.bind(PostgreMessages.wizard_backup_page_setting_group_security_label_info, connectionInfo.getUserName(), wizard.getObjectsName()));
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        infoLabel.setLayoutData(gd);
        Button authButton = new Button(securityGroup, SWT.PUSH);
        authButton.setText(PostgreMessages.wizard_backup_page_setting_group_security_btn_authentication);
        authButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BaseAuthDialog authDialog = new BaseAuthDialog(getShell(), PostgreMessages.wizard_backup_page_setting_group_security_btn_authentication, false, true);
                authDialog.setUserName(wizard.getSettings().getToolUserName());
                authDialog.setUserPassword(wizard.getSettings().getToolUserPassword());
                authDialog.setSavePassword(savePassword);
                authDialog.setSavePasswordText(PostgreMessages.wizard_backup_page_setting_authentication_save_password);
                authDialog.setSavePasswordToolTipText(PostgreMessages.wizard_backup_page_setting_authentication_save_password_tip);
                if (authDialog.open() == IDialogConstants.OK_ID) {
                    wizard.getSettings().setToolUserName(authDialog.getUserName());
                    wizard.getSettings().setToolUserPassword(authDialog.getUserPassword());
                }
            }
        });
        Button resetButton = new Button(securityGroup, SWT.PUSH);
        resetButton.setText(PostgreMessages.wizard_backup_page_setting_group_security_btn_reset_default);
        resetButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                connectionInfo.getProviderProperties().remove(authProperty);
                wizard.getSettings().setToolUserName(null);
                wizard.getSettings().setToolUserPassword(null);
            }
        });
    } 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.runtime.encode.SecuredPasswordEncrypter) Button(org.eclipse.swt.widgets.Button) BaseAuthDialog(org.jkiss.dbeaver.ui.dialogs.BaseAuthDialog) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EncryptionException(org.jkiss.dbeaver.runtime.encode.EncryptionException)

Example 3 with EncryptionException

use of org.jkiss.dbeaver.runtime.encode.EncryptionException in project dbeaver by serge-rider.

the class PostgreToolWizardPageSettings method createSecurityGroup.

public void createSecurityGroup(Composite parent) {
    try {
        final SecuredPasswordEncrypter encrypter = new SecuredPasswordEncrypter();
        final DBPConnectionConfiguration connectionInfo = wizard.getSettings().getDataSourceContainer().getActualConnectionConfiguration();
        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);
                }
            }
        }
        final boolean savePassword = authUser != null;
        Group securityGroup = UIUtils.createControlGroup(parent, PostgreMessages.wizard_backup_page_setting_group_security, 2, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
        Label infoLabel = new Label(securityGroup, SWT.NONE);
        infoLabel.setText(NLS.bind(PostgreMessages.wizard_backup_page_setting_group_security_label_info, connectionInfo.getUserName(), wizard.getObjectsName()));
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        infoLabel.setLayoutData(gd);
        Button authButton = new Button(securityGroup, SWT.PUSH);
        authButton.setText(PostgreMessages.wizard_backup_page_setting_group_security_btn_authentication);
        authButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                BaseAuthDialog authDialog = new BaseAuthDialog(getShell(), PostgreMessages.wizard_backup_page_setting_group_security_btn_authentication, false, true);
                authDialog.setUserName(wizard.getSettings().getToolUserName());
                authDialog.setUserPassword(wizard.getSettings().getToolUserPassword());
                authDialog.setSavePassword(savePassword);
                authDialog.setSavePasswordText(PostgreMessages.wizard_backup_page_setting_authentication_save_password);
                authDialog.setSavePasswordToolTipText(PostgreMessages.wizard_backup_page_setting_authentication_save_password_tip);
                if (authDialog.open() == IDialogConstants.OK_ID) {
                    wizard.getSettings().setToolUserName(authDialog.getUserName());
                    wizard.getSettings().setToolUserPassword(authDialog.getUserPassword());
                }
            }
        });
        Button resetButton = new Button(securityGroup, SWT.PUSH);
        resetButton.setText(PostgreMessages.wizard_backup_page_setting_group_security_btn_reset_default);
        resetButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                connectionInfo.getProviderProperties().remove(authProperty);
                wizard.getSettings().setToolUserName(null);
                wizard.getSettings().setToolUserPassword(null);
            }
        });
    } 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.runtime.encode.SecuredPasswordEncrypter) Button(org.eclipse.swt.widgets.Button) BaseAuthDialog(org.jkiss.dbeaver.ui.dialogs.BaseAuthDialog) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EncryptionException(org.jkiss.dbeaver.runtime.encode.EncryptionException)

Example 4 with EncryptionException

use of org.jkiss.dbeaver.runtime.encode.EncryptionException in project dbeaver by serge-rider.

the class PrefPageDrivers method performDefaults.

@Override
protected void performDefaults() {
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    versionUpdateCheck.setSelection(store.getBoolean(ModelPreferences.UI_DRIVERS_VERSION_UPDATE));
    proxyHostText.setText(store.getString(ModelPreferences.UI_PROXY_HOST));
    proxyPortSpinner.setSelection(store.getInt(ModelPreferences.UI_PROXY_PORT));
    proxyUserText.setText(store.getString(ModelPreferences.UI_PROXY_USER));
    // Load and decrypt password
    String passwordString = store.getString(ModelPreferences.UI_PROXY_PASSWORD);
    if (!CommonUtils.isEmpty(passwordString) && encrypter != null) {
        try {
            passwordString = encrypter.decrypt(passwordString);
        } catch (EncryptionException e) {
            log.warn(e);
        }
    }
    proxyPasswordText.setText(passwordString);
    customDriversHome.setText(DriverDescriptor.getCustomDriversHome().getAbsolutePath());
    for (String source : DriverDescriptor.getDriversSources()) {
        sourceList.add(source);
    }
    super.performDefaults();
}
Also used : EncryptionException(org.jkiss.dbeaver.runtime.encode.EncryptionException) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Example 5 with EncryptionException

use of org.jkiss.dbeaver.runtime.encode.EncryptionException in project dbeaver by serge-rider.

the class PrefPageDrivers method performOk.

@Override
public boolean performOk() {
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    store.setValue(ModelPreferences.UI_DRIVERS_VERSION_UPDATE, versionUpdateCheck.getSelection());
    store.setValue(ModelPreferences.UI_PROXY_HOST, proxyHostText.getText());
    store.setValue(ModelPreferences.UI_PROXY_PORT, proxyPortSpinner.getSelection());
    store.setValue(ModelPreferences.UI_PROXY_USER, proxyUserText.getText());
    String password = proxyPasswordText.getText();
    if (!CommonUtils.isEmpty(password) && encrypter != null) {
        // Encrypt password
        try {
            password = encrypter.encrypt(password);
        } catch (EncryptionException e) {
            log.warn(e);
        }
    }
    store.setValue(ModelPreferences.UI_PROXY_PASSWORD, password);
    store.setValue(ModelPreferences.UI_DRIVERS_HOME, customDriversHome.getText());
    {
        StringBuilder sources = new StringBuilder();
        for (String item : sourceList.getItems()) {
            if (sources.length() > 0)
                sources.append('|');
            sources.append(item);
        }
        store.setValue(ModelPreferences.UI_DRIVERS_SOURCES, sources.toString());
    }
    PrefUtils.savePreferenceStore(store);
    return super.performOk();
}
Also used : EncryptionException(org.jkiss.dbeaver.runtime.encode.EncryptionException) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)

Aggregations

EncryptionException (org.jkiss.dbeaver.runtime.encode.EncryptionException)6 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Button (org.eclipse.swt.widgets.Button)2 Group (org.eclipse.swt.widgets.Group)2 Label (org.eclipse.swt.widgets.Label)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 SecuredPasswordEncrypter (org.jkiss.dbeaver.runtime.encode.SecuredPasswordEncrypter)2 BaseAuthDialog (org.jkiss.dbeaver.ui.dialogs.BaseAuthDialog)2