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);
}
}
}
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();
}
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();
}
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);
}
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[] {});
}
Aggregations