use of org.jkiss.dbeaver.registry.encode.EncryptionException 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
}
}
use of org.jkiss.dbeaver.registry.encode.EncryptionException in project dbeaver by serge-rider.
the class DataSourceRegistry method saveSecuredCredentials.
private void saveSecuredCredentials(XMLBuilder xml, DataSourceDescriptor dataSource, String subNode, String userName, String password) throws IOException {
boolean saved = false;
final DBASecureStorage secureStorage = getPlatform().getSecureStorage();
{
try {
ISecurePreferences prefNode = dataSource.getSecurePreferences();
if (!secureStorage.useSecurePreferences()) {
prefNode.removeNode();
} else {
if (subNode != null) {
for (String nodeName : subNode.split("/")) {
prefNode = prefNode.node(nodeName);
}
}
prefNode.put("name", dataSource.getName(), false);
if (!CommonUtils.isEmpty(userName)) {
prefNode.put(RegistryConstants.ATTR_USER, userName, true);
saved = true;
} else {
prefNode.remove(RegistryConstants.ATTR_USER);
}
if (!CommonUtils.isEmpty(password)) {
prefNode.put(RegistryConstants.ATTR_PASSWORD, password, true);
saved = true;
} else {
prefNode.remove(RegistryConstants.ATTR_PASSWORD);
}
}
} catch (StorageException e) {
log.error("Can't save password in secure storage", e);
}
}
if (!saved) {
try {
if (!CommonUtils.isEmpty(userName)) {
xml.addAttribute(RegistryConstants.ATTR_USER, CommonUtils.notEmpty(userName));
}
if (!CommonUtils.isEmpty(password)) {
xml.addAttribute(RegistryConstants.ATTR_PASSWORD, ENCRYPTOR.encrypt(password));
}
} catch (EncryptionException e) {
log.error("Error encrypting password", e);
}
}
}
use of org.jkiss.dbeaver.registry.encode.EncryptionException in project dbeaver by dbeaver.
the class MySQLWizardPageSettings 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 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.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.getProperties().remove(authProperty);
wizard.setToolUserName(connectionInfo.getUserName());
wizard.setToolUserPassword(connectionInfo.getUserPassword());
}
});
} catch (EncryptionException e) {
// Never be here
}
}
use of org.jkiss.dbeaver.registry.encode.EncryptionException in project dbeaver by dbeaver.
the class PrefPageDrivers method performDefaults.
@Override
protected void performDefaults() {
DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
versionUpdateCheck.setSelection(store.getBoolean(DBeaverPreferences.UI_DRIVERS_VERSION_UPDATE));
proxyHostText.setText(store.getString(DBeaverPreferences.UI_PROXY_HOST));
proxyPortSpinner.setSelection(store.getInt(DBeaverPreferences.UI_PROXY_PORT));
proxyUserText.setText(store.getString(DBeaverPreferences.UI_PROXY_USER));
// Load and decrypt password
String passwordString = store.getString(DBeaverPreferences.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();
}
use of org.jkiss.dbeaver.registry.encode.EncryptionException in project dbeaver by dbeaver.
the class DataSourceRegistry method saveSecuredCredentials.
private void saveSecuredCredentials(XMLBuilder xml, DataSourceDescriptor dataSource, String subNode, String userName, String password) throws IOException {
boolean saved = false;
final DBASecureStorage secureStorage = getPlatform().getSecureStorage();
{
try {
ISecurePreferences prefNode = dataSource.getSecurePreferences();
if (!secureStorage.useSecurePreferences()) {
prefNode.removeNode();
} else {
if (subNode != null) {
for (String nodeName : subNode.split("/")) {
prefNode = prefNode.node(nodeName);
}
}
prefNode.put("name", dataSource.getName(), false);
if (!CommonUtils.isEmpty(userName)) {
prefNode.put(RegistryConstants.ATTR_USER, userName, true);
saved = true;
} else {
prefNode.remove(RegistryConstants.ATTR_USER);
}
if (!CommonUtils.isEmpty(password)) {
prefNode.put(RegistryConstants.ATTR_PASSWORD, password, true);
saved = true;
} else {
prefNode.remove(RegistryConstants.ATTR_PASSWORD);
}
}
} catch (Throwable e) {
log.error("Can't save password in secure storage", e);
}
}
if (!saved) {
try {
if (!CommonUtils.isEmpty(userName)) {
xml.addAttribute(RegistryConstants.ATTR_USER, CommonUtils.notEmpty(userName));
}
if (!CommonUtils.isEmpty(password)) {
xml.addAttribute(RegistryConstants.ATTR_PASSWORD, ENCRYPTOR.encrypt(password));
}
} catch (EncryptionException e) {
log.error("Error encrypting password", e);
}
}
}
Aggregations