Search in sources :

Example 31 with ISecurePreferences

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

the class AccountModel method save.

@Override
public void save() {
    clusters.forEach(ICluster::save);
    Preferences accountRoot = getAccountsPreferences();
    ISecurePreferences accountSecureRoot = getSecureAccountsPreferences();
    removed.forEach(id -> {
        removeAccount(id, accountRoot, accountSecureRoot);
    });
    removed.clear();
}
Also used : ICluster(org.jboss.tools.openshift.io.core.model.ICluster) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 32 with ISecurePreferences

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

the class AccountModel method loadModel.

private void loadModel() {
    ISecurePreferences secureAccountRoot = getSecureAccountsPreferences();
    Preferences accountsRoot = getAccountsPreferences();
    try {
        String[] ids = accountsRoot.childrenNames();
        for (String id : ids) {
            Cluster cluster = new Cluster(this, id);
            Preferences clusterNode = accountsRoot.node(id);
            ISecurePreferences secureClusterNode = secureAccountRoot.node(id);
            addCluster(cluster, clusterNode, secureClusterNode);
        }
    } catch (BackingStoreException e) {
        OpenShiftIOCoreActivator.logError(e.getLocalizedMessage(), e);
    }
    if (clusters.isEmpty()) {
        addCluster(createCluster("OpenShift.io"));
    }
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) ICluster(org.jboss.tools.openshift.io.core.model.ICluster) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) Preferences(org.osgi.service.prefs.Preferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 33 with ISecurePreferences

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

the class ReEncrypter method encrypt.

/**
 * The method will encrypt all data from the memory structure created by decrypt using current
 * passwords and providers. The original encrypted data will be overwritten.
 */
public boolean encrypt() {
    boolean result = true;
    // we'll directly inject here a requirement to use the specified module to encrypt data
    SecurePreferencesContainer container = ((SecurePreferencesWrapper) root).getContainer();
    Object originalProperty = container.getOption(IProviderHints.REQUIRED_MODULE_ID);
    container.setOption(IProviderHints.REQUIRED_MODULE_ID, moduleID);
    for (Iterator i = elements.iterator(); i.hasNext(); ) {
        TmpElement element = (TmpElement) i.next();
        ISecurePreferences node = root.node(element.getPath());
        Map values = element.getValues();
        for (Iterator j = values.keySet().iterator(); j.hasNext(); ) {
            String key = (String) j.next();
            try {
                node.put(key, (String) values.get(key), true);
            } catch (StorageException e) {
                // this value will not be re-coded
                String msg = NLS.bind(SecAuthMessages.encryptingError, key, node.absolutePath());
                AuthPlugin.getDefault().logError(msg, e);
                result = false;
            }
        }
    }
    if (originalProperty != null)
        container.setOption(IProviderHints.REQUIRED_MODULE_ID, originalProperty);
    else
        container.removeOption(IProviderHints.REQUIRED_MODULE_ID);
    return result;
}
Also used : SecurePreferencesWrapper(org.eclipse.equinox.internal.security.storage.SecurePreferencesWrapper) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) SecurePreferencesContainer(org.eclipse.equinox.internal.security.storage.SecurePreferencesContainer) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 34 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project mdw-designer by CenturyLinkCloud.

the class WorkflowProjectManager method authenticate.

/**
 * Authenticates using the designated authenticator impl.
 */
public void authenticate(Authenticator authenticator, String user, String password, boolean saveInSecureStore) throws MdwSecurityException {
    String key = authenticator.getClass().getName() + "_" + authenticator.getKey();
    authenticatedUsers.remove(key);
    try {
        authenticator.authenticate(user, password);
        if (saveInSecureStore) {
            try {
                ISecurePreferences securePrefs = SecurePreferencesFactory.getDefault();
                securePrefs.put(PreferenceConstants.PREFS_MDW_USER + "_" + key, user, false);
                securePrefs.put(PreferenceConstants.PREFS_MDW_PASSWORD + "_" + key, password, true);
                securePrefs.flush();
            } catch (Exception ex) {
                // don't prevent user from being authenticated because of
                // this
                PluginMessages.log(ex);
            }
        }
        if (authenticator instanceof MdwAuthenticator)
            authenticatedUsers.put(key, new User(user, password, ((MdwAuthenticator) authenticator).getJwtToken()));
        else
            authenticatedUsers.put(key, new User(user, password, null));
    } catch (MdwSecurityException ex) {
        PluginMessages.log(ex);
        throw ex;
    } catch (Exception ex) {
        PluginMessages.log(ex);
        throw new MdwSecurityException(ex.getMessage(), ex);
    }
}
Also used : User(com.centurylink.mdw.plugin.User) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException)

Example 35 with ISecurePreferences

use of org.eclipse.equinox.security.storage.ISecurePreferences in project mdw-designer by CenturyLinkCloud.

the class WorkflowProjectManager method getAuthenticatedUser.

/**
 * Triggers automatic authentication if credentials are in Eclipse secure
 * store.
 */
public User getAuthenticatedUser(Authenticator authenticator) {
    String key = authenticator.getClass().getName() + "_" + authenticator.getKey();
    User authUser = authenticatedUsers.get(key);
    if (authUser == null) {
        try {
            ISecurePreferences securePrefs = SecurePreferencesFactory.getDefault();
            String user = securePrefs.get(PreferenceConstants.PREFS_MDW_USER + "_" + key, "");
            if (user.length() > 0) {
                String password = securePrefs.get(PreferenceConstants.PREFS_MDW_PASSWORD + "_" + key, "");
                if (password.length() > 0) {
                    try {
                        authenticate(authenticator, user, password, false);
                        if (authenticator instanceof MdwAuthenticator)
                            authUser = new User(user, password, ((MdwAuthenticator) authenticator).getJwtToken());
                        else
                            authUser = new User(user, password, null);
                    } catch (MdwSecurityException ex) {
                        // prevent repeated attempts to auto-authenticate
                        securePrefs.put(PreferenceConstants.PREFS_MDW_USER + "_" + key, "", false);
                        securePrefs.flush();
                    }
                }
            }
        } catch (Exception ex) {
            // just log exception and force user to log in -- if pw expired
            // they'll enter the new one
            PluginMessages.log(ex);
        }
    }
    return authUser;
}
Also used : User(com.centurylink.mdw.plugin.User) MdwAuthenticator(com.centurylink.mdw.designer.auth.MdwAuthenticator) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) ResourceException(org.eclipse.core.internal.resources.ResourceException) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MdwSecurityException(com.centurylink.mdw.auth.MdwSecurityException) DiscoveryException(com.centurylink.mdw.plugin.designer.DiscoveryException) XmlException(org.apache.xmlbeans.XmlException)

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