Search in sources :

Example 6 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences 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);
        }
    }
}
Also used : EncryptionException(org.jkiss.dbeaver.registry.encode.EncryptionException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) DBASecureStorage(org.jkiss.dbeaver.model.app.DBASecureStorage)

Example 7 with ISecurePreferences

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

the class EGitSecureStore method clearCredentials.

/**
 * Clear credentials for the given uri.
 *
 * @param uri
 * @throws IOException
 */
public void clearCredentials(URIish uri) throws IOException {
    String pathName = calcNodePath(uri);
    if (!preferences.nodeExists(pathName))
        return;
    ISecurePreferences node = preferences.node(pathName);
    node.removeNode();
    node.flush();
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 8 with ISecurePreferences

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

the class EGitSecureStore method putCredentials.

/**
 * Puts credentials for the given URI into the secure store
 *
 * @param uri
 * @param credentials
 * @throws StorageException
 * @throws IOException
 */
public void putCredentials(URIish uri, UserPasswordCredentials credentials) throws StorageException, IOException {
    String pathName = calcNodePath(uri);
    ISecurePreferences node = preferences.node(pathName);
    node.put(USER, credentials.getUser(), false);
    node.put(PASSWORD, credentials.getPassword(), true);
    node.flush();
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 9 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project balzac by balzac-lang.

the class TrustedNodesPreferences method setBitcoinClientFactoryNodes.

public static void setBitcoinClientFactoryNodes(IPreferenceStore store) throws StorageException {
    ISecurePreferences secureStore = SecurePreferencesFactory.getDefault();
    String testnetHost = store.getString(PreferenceConstants.P_TESTNET_HOST);
    int testnetPort = store.getInt(PreferenceConstants.P_TESTNET_PORT);
    String testnetProtocol = store.getBoolean(PreferenceConstants.P_TESTNET_HTTPS) ? "https" : "http";
    String testnetUrl = store.getString(PreferenceConstants.P_TESTNET_URL);
    String testnetUsername = store.getString(PreferenceConstants.P_TESTNET_USERNAME);
    int testnetTimeout = store.getInt(PreferenceConstants.P_TESTNET_TIMEOUT);
    String testnetPassword = secureStore.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__TESTNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__TESTNET_PASSWORD, "");
    String mainnetHost = store.getString(PreferenceConstants.P_MAINNET_HOST);
    int mainnetPort = store.getInt(PreferenceConstants.P_MAINNET_PORT);
    String mainnetProtocol = store.getBoolean(PreferenceConstants.P_MAINNET_HTTPS) ? "https" : "http";
    String mainnetUrl = store.getString(PreferenceConstants.P_MAINNET_URL);
    String mainnetUsername = store.getString(PreferenceConstants.P_MAINNET_USERNAME);
    int mainnetTimeout = store.getInt(PreferenceConstants.P_MAINNET_TIMEOUT);
    String mainnetPassword = secureStore.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__MAINNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__MAINNET_PASSWORD, "");
    BitcoinClientI testnetClient = new RPCBitcoinClient(testnetHost, testnetPort, testnetProtocol, testnetUrl, testnetUsername, testnetPassword, testnetTimeout, TimeUnit.MILLISECONDS);
    BitcoinClientI mainnetClient = new RPCBitcoinClient(mainnetHost, mainnetPort, mainnetProtocol, mainnetUrl, mainnetUsername, mainnetPassword, mainnetTimeout, TimeUnit.MILLISECONDS);
    Injector injector = BitcointmActivator.getInstance().getInjector(BitcointmActivator.IT_UNICA_TCS_BITCOINTM);
    BitcoinClientFactory factory = injector.getInstance(BitcoinClientFactory.class);
    factory.setMainnetClient(mainnetClient);
    factory.setTestnetClient(testnetClient);
}
Also used : Injector(com.google.inject.Injector) BitcoinClientFactory(it.unica.tcs.utils.BitcoinClientFactory) BitcoinClientI(it.unica.tcs.lib.client.BitcoinClientI) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) RPCBitcoinClient(it.unica.tcs.lib.client.impl.RPCBitcoinClient)

Example 10 with ISecurePreferences

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

the class ContainerStore method getContainerEntries.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.storage.IContainerStore#getContainerEntries()
	 */
public IContainerEntry[] getContainerEntries() {
    INamespaceEntry[] namespaceEntries = idStore.getNamespaceEntries();
    List results = new ArrayList();
    for (int i = 0; i < namespaceEntries.length; i++) {
        IIDEntry[] idEntries = namespaceEntries[i].getIDEntries();
        for (int j = 0; j < idEntries.length; j++) {
            ISecurePreferences pref = idEntries[j].getPreferences();
            String[] names = pref.childrenNames();
            for (int k = 0; k < names.length; k++) {
                if (names[k].equals(CONTAINER_NODE_NAME))
                    results.add(new ContainerEntry(idEntries[j]));
            }
        }
    }
    return (IContainerEntry[]) results.toArray(new IContainerEntry[] {});
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

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