Search in sources :

Example 1 with DBAAuthInfo

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;
}
Also used : DBAAuthInfo(org.jkiss.dbeaver.model.access.DBAAuthInfo)

Example 2 with DBAAuthInfo

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) DBAAuthInfo(org.jkiss.dbeaver.model.access.DBAAuthInfo) XMLBuilder(org.jkiss.utils.xml.XMLBuilder) IOException(java.io.IOException)

Aggregations

DBAAuthInfo (org.jkiss.dbeaver.model.access.DBAAuthInfo)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)1