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();
}
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"));
}
}
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;
}
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);
}
}
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;
}
Aggregations