use of org.jkiss.dbeaver.model.access.DBAAuthInfo in project dbeaver by serge-rider.
the class DataSourceHandler method askForPassword.
public static boolean askForPassword(@NotNull final DataSourceDescriptor dataSourceContainer, @Nullable final DBWHandlerConfiguration networkHandler) {
final String prompt = networkHandler != null ? NLS.bind(CoreMessages.dialog_connection_auth_title_for_handler, networkHandler.getTitle()) : //$NON-NLS-1$
"'" + dataSourceContainer.getName() + CoreMessages.dialog_connection_auth_title;
final String user = networkHandler != null ? networkHandler.getUserName() : dataSourceContainer.getConnectionConfiguration().getUserName();
final String password = networkHandler != null ? networkHandler.getPassword() : dataSourceContainer.getConnectionConfiguration().getUserPassword();
DBAAuthInfo authInfo = new UITask<DBAAuthInfo>() {
@Override
protected DBAAuthInfo runTask() {
return DBUserInterface.getInstance().promptUserCredentials(prompt, user, password, false);
}
}.execute();
if (authInfo == null) {
return false;
}
if (networkHandler != null) {
networkHandler.setUserName(authInfo.getUserName());
networkHandler.setPassword(authInfo.getUserPassword());
networkHandler.setSavePassword(authInfo.isSavePassword());
} else {
dataSourceContainer.getConnectionConfiguration().setUserName(authInfo.getUserName());
dataSourceContainer.getConnectionConfiguration().setUserPassword(authInfo.getUserPassword());
dataSourceContainer.setSavePassword(authInfo.isSavePassword());
}
if (authInfo.isSavePassword()) {
// Update connection properties
dataSourceContainer.getRegistry().updateDataSource(dataSourceContainer);
}
return true;
}
use of org.jkiss.dbeaver.model.access.DBAAuthInfo in project dbeaver by serge-rider.
the class MavenRegistry method saveConfiguration.
public void saveConfiguration() {
sortRepositories();
try (OutputStream is = new FileOutputStream(getConfigurationFile())) {
XMLBuilder xml = new XMLBuilder(is, GeneralUtils.UTF8_ENCODING);
xml.setButify(true);
try (final XMLBuilder.Element e1 = xml.startElement("maven")) {
for (MavenRepository repository : repositories) {
try (final XMLBuilder.Element e2 = xml.startElement("repository")) {
xml.addAttribute("id", repository.getId());
xml.addAttribute("order", repository.getOrder());
xml.addAttribute("enabled", repository.isEnabled());
if (repository.getType() != MavenRepository.RepositoryType.GLOBAL) {
xml.addAttribute("url", repository.getUrl());
xml.addAttribute("name", repository.getName());
if (!CommonUtils.isEmpty(repository.getDescription())) {
xml.addAttribute("description", repository.getDescription());
}
for (String scope : repository.getScopes()) {
try (final XMLBuilder.Element e3 = xml.startElement("scope")) {
xml.addAttribute("group", scope);
}
}
final DBAAuthInfo authInfo = repository.getAuthInfo();
if (!CommonUtils.isEmpty(authInfo.getUserName())) {
xml.addAttribute("auth-user", authInfo.getUserName());
if (!CommonUtils.isEmpty(authInfo.getUserPassword())) {
xml.addAttribute("auth-password", ENCRYPTOR.encrypt(authInfo.getUserPassword()));
}
}
}
}
}
}
xml.flush();
} catch (Exception e) {
log.error("Error saving Maven registry", e);
}
}
Aggregations