Search in sources :

Example 16 with ISecurePreferences

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

the class MarketplaceStorageService method cleanupExtraStorageService.

private static IStorageService cleanupExtraStorageService(IStorageService service, IStorageService extraService) {
    IStorageService.Dynamic removeDynamic;
    IStorageService keepService;
    if (extraService instanceof IStorageService.Dynamic) {
        removeDynamic = (IStorageService.Dynamic) extraService;
        keepService = service;
    } else if (service instanceof IStorageService.Dynamic) {
        removeDynamic = (IStorageService.Dynamic) service;
        keepService = extraService;
    } else {
        return service;
    }
    if (removeDynamic instanceof StorageService && keepService instanceof StorageService) {
        StorageService removeImpl = (StorageService) removeDynamic;
        StorageService keepImpl = (StorageService) keepService;
        ISecurePreferences removeSecurePreferences = removeImpl.getSecurePreferences();
        ISecurePreferences keepSecurePreferences = keepImpl.getSecurePreferences();
        try {
            copySecurePreferences(removeSecurePreferences, keepSecurePreferences);
        } catch (Exception e) {
            MarketplaceClientCore.error(NLS.bind("Failed to migrate secure storage values from {0} to {1}", removeDynamic.getServiceURI(), keepService.getServiceURI()), e);
        }
    }
    removeDynamic.remove();
    return keepService;
}
Also used : IStorageService(org.eclipse.userstorage.IStorageService) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) URISyntaxException(java.net.URISyntaxException) StorageException(org.eclipse.equinox.security.storage.StorageException) IOException(java.io.IOException) IStorageService(org.eclipse.userstorage.IStorageService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService) StorageService(org.eclipse.userstorage.internal.StorageService)

Example 17 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project jbosstools-openshift by jbosstools.

the class Cluster method load.

public void load(Preferences clusterNode, ISecurePreferences secureClusterNode) throws StorageException {
    clusterNode.get(ENDPOINT_URL_KEY, OSIOCoreConstants.OSIO_ENDPOINT);
    try {
        String[] ids = clusterNode.childrenNames();
        for (String id : ids) {
            Account account = new Account(id, this);
            Preferences accountNode = clusterNode.node(id);
            ISecurePreferences secureAccountNode = secureClusterNode.node(id);
            try {
                account.load(accountNode, secureAccountNode);
                identities.add(account);
            } catch (StorageException e) {
                OpenShiftIOCoreActivator.logError(e.getLocalizedMessage(), e);
            }
        }
    } catch (BackingStoreException e) {
        OpenShiftIOCoreActivator.logError(e.getLocalizedMessage(), e);
    }
}
Also used : IAccount(org.jboss.tools.openshift.io.core.model.IAccount) BackingStoreException(org.osgi.service.prefs.BackingStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) Preferences(org.osgi.service.prefs.Preferences) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 18 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project jbosstools-openshift by jbosstools.

the class Cluster method save.

@Override
public void save() {
    try {
        Preferences accountsNode = AccountModel.getAccountsPreferences();
        Preferences clusterNode = accountsNode.node(getId());
        ISecurePreferences clusterSecureNode = AccountModel.getSecureAccountsPreferences().node(getId());
        clusterNode.put(ENDPOINT_URL_KEY, getEndpointURL());
        removed.forEach(id -> {
            try {
                clusterNode.node(id).removeNode();
                clusterSecureNode.node(id).removeNode();
            } catch (BackingStoreException e) {
                OpenShiftIOCoreActivator.logError(e.getLocalizedMessage(), e);
            }
        });
        removed.clear();
        clusterNode.flush();
        clusterSecureNode.flush();
    } catch (BackingStoreException | IOException e) {
        OpenShiftIOCoreActivator.logError("Error saving cluster in storage", e);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 19 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project jbosstools-openshift by jbosstools.

the class Account method save.

@Override
public void save() {
    try {
        ISecurePreferences secureAccountsRoot = AccountModel.getSecureAccountsPreferences();
        Preferences accountsRoot = AccountModel.getAccountsPreferences();
        ISecurePreferences secureAccountNode = secureAccountsRoot.node(cluster.getId()).node(getId());
        Preferences accountNode = accountsRoot.node(cluster.getId()).node(getId());
        accountNode.putLong(ACCESS_TOKEN_EXPIRY_TIME_KEY, getAccessTokenExpiryTime());
        accountNode.putLong(KEYREFRESH_TOKEN_EXPIRY_TIME, getRefreshTokenExpiryTime());
        accountNode.putLong(LAST_REFRESHED_TIME_KEY, getLastRefreshedTime());
        secureAccountNode.put(ACCESS_TOKEN_KEY, getAccessToken(), true);
        secureAccountNode.put(REFRESH_TOKEN_KEY, getRefreshToken(), true);
        accountNode.flush();
        secureAccountNode.flush();
    } catch (StorageException | BackingStoreException | IOException e) {
        OpenShiftIOCoreActivator.logError("Error saving credentials ", e);
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) IOException(java.io.IOException) Preferences(org.osgi.service.prefs.Preferences) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 20 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project polymap4-core by Polymap4.

the class InternalExchangeUtils method defaultStorageDelete.

/**
 * Closes open default storage, if any, and deletes the actual file.
 */
public static void defaultStorageDelete() {
    ISecurePreferences defaultStorage = SecurePreferencesFactory.getDefault();
    if (defaultStorage == null)
        return;
    URL location = defaultStorageLocation();
    if (location == null)
        return;
    // clear the default preferences store from the mapper
    SecurePreferencesMapper.clearDefault();
    // delete the actual file
    if (StorageUtils.exists(location))
        StorageUtils.delete(location);
// FUTURE: this is a good place to notify delete listeners
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) URL(java.net.URL)

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