Search in sources :

Example 21 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project dbeaver by serge-rider.

the class DataSourceSerializerModern method readSecuredCredentials.

private SecureCredentials readSecuredCredentials(@Nullable DataSourceDescriptor dataSource, @Nullable DBPConfigurationProfile profile, @Nullable String subNode) {
    assert dataSource != null || profile != null;
    SecureCredentials creds = new SecureCredentials();
    final DBASecureStorage secureStorage = dataSource == null ? registry.getProject().getSecureStorage() : dataSource.getProject().getSecureStorage();
    {
        try {
            if (secureStorage.useSecurePreferences()) {
                ISecurePreferences prefNode = dataSource == null ? secureStorage.getSecurePreferences() : dataSource.getSecurePreferences();
                if (subNode != null) {
                    for (String nodeName : subNode.split("/")) {
                        prefNode = prefNode.node(nodeName);
                    }
                }
                for (String key : prefNode.keys()) {
                    switch(key) {
                        case RegistryConstants.ATTR_USER:
                            creds.setUserName(prefNode.get(key, null));
                            break;
                        case RegistryConstants.ATTR_PASSWORD:
                            creds.setUserPassword(prefNode.get(key, null));
                            break;
                        default:
                            creds.setSecureProp(key, prefNode.get(key, null));
                            break;
                    }
                }
            }
        } catch (Throwable e) {
            // Most likely user canceled master password enter of failed by some other reason.
            // Anyhow we won't try it again
            log.error("Can't read password from secure storage", e);
            passwordReadCanceled = true;
        }
    }
    String topNodeId = profile != null ? "profile:" + profile.getProfileId() : dataSource.getId();
    if (subNode == null)
        subNode = NODE_CONNECTION;
    Map<String, Map<String, String>> subMap = secureProperties.get(topNodeId);
    if (subMap != null) {
        Map<String, String> propMap = subMap.get(subNode);
        if (propMap != null) {
            for (Map.Entry<String, String> prop : propMap.entrySet()) {
                switch(prop.getKey()) {
                    case RegistryConstants.ATTR_USER:
                        creds.setUserName(prop.getValue());
                        break;
                    case RegistryConstants.ATTR_PASSWORD:
                        creds.setUserPassword(prop.getValue());
                        break;
                    default:
                        creds.setSecureProp(prop.getKey(), prop.getValue());
                        break;
                }
            }
        }
    }
    return creds;
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) DBASecureStorage(org.jkiss.dbeaver.model.app.DBASecureStorage)

Example 22 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project generator by mybatis.

the class LauncherUtils method getSecurePreferencesNode.

private static ISecurePreferences getSecurePreferencesNode() {
    ISecurePreferences root = SecurePreferencesFactory.getDefault();
    // $NON-NLS-1$
    ISecurePreferences node = root.node("/org.mybatis.generator/sqlscript");
    return node;
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 23 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project generator by mybatis.

the class LauncherUtils method getPassword.

public static String getPassword(ILaunchConfiguration configuration) {
    boolean secure = getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS);
    String password;
    if (secure) {
        ISecurePreferences node = getSecurePreferencesNode();
        // $NON-NLS-1$
        password = getTextOrBlank(node, "password");
    } else {
        password = getTextOrBlank(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_PASSWORD);
    }
    return password;
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 24 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project hale by halestudio.

the class PreferenceInitializer method initializeDefaultPreferences.

/**
 * @see AbstractPreferenceInitializer#initializeDefaultPreferences()
 */
@Override
public void initializeDefaultPreferences() {
    IPreferenceStore store = UIUtilitiesPlugin.getDefault().getPreferenceStore();
    // configure proxy host
    String proxyHost = System.getProperty(PreferenceConstants.CONNECTION_PROXY_HOST);
    if (proxyHost == null) {
        // $NON-NLS-1$
        proxyHost = "";
    }
    store.setDefault(PreferenceConstants.CONNECTION_PROXY_HOST, proxyHost);
    // configure proxy port
    String proxyPortStr = System.getProperty(PreferenceConstants.CONNECTION_PROXY_PORT);
    int proxyPort = 8080;
    if (proxyPortStr != null && !proxyPortStr.isEmpty()) {
        proxyPort = Integer.parseInt(proxyPortStr);
    }
    store.setDefault(PreferenceConstants.CONNECTION_PROXY_PORT, proxyPort);
    // configure proxy user
    String proxyUser = System.getProperty(CONNECTION_PROXY_USER);
    if (proxyUser == null) {
        // $NON-NLS-1$
        proxyUser = "";
    }
    store.setDefault(CONNECTION_PROXY_USER, proxyUser);
    // configure proxy user
    ISecurePreferences secPref = SecurePreferencesFactory.getDefault();
    String proxyPassword = System.getProperty(CONNECTION_PROXY_PASSWORD);
    try {
        if (proxyPassword != null && secPref.node(SECURE_NODE_NAME).get(CONNECTION_PROXY_PASSWORD, null) == null) {
            secPref.node(SECURE_NODE_NAME).put(CONNECTION_PROXY_PASSWORD, proxyPassword, true);
        }
    } catch (StorageException e) {
        // $NON-NLS-1$
        log.warn("Error accessing secure preferences");
    }
    // configure non proxy hosts
    String nonProxyHosts = System.getProperty(PreferenceConstants.CONNECTION_NON_PROXY_HOSTS);
    if (nonProxyHosts == null) {
        // $NON-NLS-1$
        nonProxyHosts = "";
    }
    store.setDefault(PreferenceConstants.CONNECTION_NON_PROXY_HOSTS, nonProxyHosts);
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 25 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project dbeaver by dbeaver.

the class DataSourceSerializerModern method readSecuredCredentials.

private SecureCredentials readSecuredCredentials(@Nullable DataSourceDescriptor dataSource, @Nullable DBPConfigurationProfile profile, @Nullable String subNode) {
    assert dataSource != null || profile != null;
    SecureCredentials creds = new SecureCredentials();
    final DBASecureStorage secureStorage = dataSource == null ? registry.getProject().getSecureStorage() : dataSource.getProject().getSecureStorage();
    {
        try {
            if (secureStorage.useSecurePreferences()) {
                ISecurePreferences prefNode = dataSource == null ? secureStorage.getSecurePreferences() : dataSource.getSecurePreferences();
                if (subNode != null) {
                    for (String nodeName : subNode.split("/")) {
                        prefNode = prefNode.node(nodeName);
                    }
                }
                for (String key : prefNode.keys()) {
                    switch(key) {
                        case RegistryConstants.ATTR_USER:
                            creds.setUserName(prefNode.get(key, null));
                            break;
                        case RegistryConstants.ATTR_PASSWORD:
                            creds.setUserPassword(prefNode.get(key, null));
                            break;
                        default:
                            creds.setSecureProp(key, prefNode.get(key, null));
                            break;
                    }
                }
            }
        } catch (Throwable e) {
            // Most likely user canceled master password enter of failed by some other reason.
            // Anyhow we won't try it again
            log.error("Can't read password from secure storage", e);
            passwordReadCanceled = true;
        }
    }
    String topNodeId = profile != null ? "profile:" + profile.getProfileId() : dataSource.getId();
    if (subNode == null)
        subNode = NODE_CONNECTION;
    Map<String, Map<String, String>> subMap = secureProperties.get(topNodeId);
    if (subMap != null) {
        Map<String, String> propMap = subMap.get(subNode);
        if (propMap != null) {
            for (Map.Entry<String, String> prop : propMap.entrySet()) {
                switch(prop.getKey()) {
                    case RegistryConstants.ATTR_USER:
                        creds.setUserName(prop.getValue());
                        break;
                    case RegistryConstants.ATTR_PASSWORD:
                        creds.setUserPassword(prop.getValue());
                        break;
                    default:
                        creds.setSecureProp(prop.getKey(), prop.getValue());
                        break;
                }
            }
        }
    }
    return creds;
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) DBASecureStorage(org.jkiss.dbeaver.model.app.DBASecureStorage)

Aggregations

ISecurePreferences (org.eclipse.equinox.security.storage.ISecurePreferences)46 StorageException (org.eclipse.equinox.security.storage.StorageException)13 Preferences (org.osgi.service.prefs.Preferences)5 IOException (java.io.IOException)4 DBASecureStorage (org.jkiss.dbeaver.model.app.DBASecureStorage)4 BackingStoreException (org.osgi.service.prefs.BackingStoreException)4 ArrayList (java.util.ArrayList)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 MdwSecurityException (com.centurylink.mdw.auth.MdwSecurityException)2 MdwAuthenticator (com.centurylink.mdw.designer.auth.MdwAuthenticator)2 User (com.centurylink.mdw.plugin.User)2 DiscoveryException (com.centurylink.mdw.plugin.designer.DiscoveryException)2 XmlException (org.apache.xmlbeans.XmlException)2 ResourceException (org.eclipse.core.internal.resources.ResourceException)2 CoreException (org.eclipse.core.runtime.CoreException)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 IDStoreException (org.eclipse.ecf.storage.IDStoreException)2 IIDEntry (org.eclipse.ecf.storage.IIDEntry)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2