protected void export(ISecurePreferences node, PrintStream stream) { if (IStorageConst.PROVIDER_NODE.equals(node.absolutePath())) return; // skip internal node String[] keys = node.keys(); if (keys.length > 0) { String header = '[' + node.absolutePath() + ']'; stream.println(header); for (int i = 0; i < keys.length; i++) { try { String data = keys[i] + " := " + node.get(keys[i], ""); //$NON-NLS-1$ //$NON-NLS-2$ stream.println(data); } catch (StorageException e) { Activator.log(IStatus.ERROR, SecUIMessages.failedDecrypt, null, e); } } } String[] children = node.childrenNames(); for (int i = 0; i < children.length; i++) { export(node.node(children[i]), stream); } }
ISecurePreferences root = org.eclipse.equinox.security.storage.SecurePreferencesFactory.getDefault(); if (root == null) return null; ISecurePreferences node = root.node("/your.class.path.or.something.else"); // get the node for your application e.g. this.getClass().getCanonicalName() node = node.node( "some name"); // get custom node from the tree node.get( "key" ); // load node.put("key","value", true / false (encrypt) ); // store (no save operation) node.remove("key"); // remove node.flush(); // save
private static void tryRemoveSecureProperties(String serverNodeName) { ISecurePreferences secureServersNode = getSecureServersNode(); if (secureServersNode.nodeExists(serverNodeName)) { secureServersNode.node(serverNodeName).removeNode(); } }
public Object[] getChildren(Object parent) { if (!(parent instanceof ISecurePreferences)) return new Object[0]; ISecurePreferences node = (ISecurePreferences) parent; String[] childrenNames = node.childrenNames(); ISecurePreferences[] result = new ISecurePreferences[childrenNames.length]; for (int i = 0; i < childrenNames.length; i++) result[i] = node.node(childrenNames[i]); return result; }
ISecurePreferences prefNode = null; try { if (securePreferences.nodeExists(nodeName)) prefNode = securePreferences.node(nodeName); } catch (IllegalArgumentException e) { try { if (prefNode != null) { String username = prefNode.get(IRepository.PROP_USERNAME, null); String password = prefNode.get(IRepository.PROP_PASSWORD, null); if (DebugHelper.DEBUG_REPOSITORY_CREDENTIALS) { if (username != null && password != null) { prefNode = securePreferences.node(nodeName); try { prefNode.put(IRepository.PROP_USERNAME, loginDetails.getUserName(), true); prefNode.put(IRepository.PROP_PASSWORD, loginDetails.getPassword(), true); prefNode.flush(); } catch (StorageException e1) { throw internalError(e1); if (securePreferences.nodeExists(nodeName)) { if (DebugHelper.DEBUG_REPOSITORY_CREDENTIALS) { DebugHelper.debug("Credentials", "forLocation:REMOVING PREVIOUSLY SAVED INFO", // //$NON-NLS-1$ //$NON-NLS-2$ prefNode = securePreferences.node(nodeName); prefNode.removeNode(); try { prefNode.flush();
private static void storeCredentials(IServer server, String username, String password) { try { ISecurePreferences secureServersNode = getSecureServersNode(); ISecurePreferences secureServerNode = secureServersNode.node(getServerNodeName(server)); secureServerNode.put(USERNAME_ATTRIBUTE, username, true); secureServerNode.put(PASSWORD_ATTRIBUTE, password, true); secureServersNode.flush(); } catch (StorageException | IOException e) { throw new IllegalStateException("Unable to store server credentials in secure storage: " + e.getMessage(), e); } }
ISecurePreferences prefNode = securePreferences.node(nodeName); if (!username.equals(prefNode.get(IRepository.PROP_USERNAME, username)) || !password.equals(prefNode.get(IRepository.PROP_PASSWORD, password))) { logger.info("Redefining access credentials for repository host " + host); prefNode.put(IRepository.PROP_USERNAME, username, false); prefNode.put(IRepository.PROP_PASSWORD, password, false); } catch (StorageException e) { throw new RuntimeException(e);
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) { String msg = NLS.bind(SecAuthMessages.encryptingError, key, node.absolutePath()); AuthPlugin.getDefault().logError(msg, e); result = false;
private static String getFromSecure(IServer server, String attribute) throws StorageException { ISecurePreferences secureServersNode = getSecureServersNode(); if (!secureServersNode.nodeExists(getServerNodeName(server))) { return null; } ISecurePreferences secureServerNode = secureServersNode.node(getServerNodeName(server)); return secureServerNode.get(attribute, null); }
import org.eclipse.equinox.security.storage.SecurePreferencesFactory; import org.eclipse.equinox.security.storage.ISecurePreferences; ISecurePreferences root = SecurePreferencesFactory.getDefault(); ISecurePreferences coresec = root.node("org.eclipse.rse.core.security"); ISecurePreferences typeftp = coresec.node("org.eclipse.rse.systemtype.ftp"); pass = typeftp.get("HERE_FTP_HOST//HERE_MY_FTP_USER_NAME", "test");
public Object[] getElements(Object parent) { if (selectedNode == null) return new Object[0]; String[] keys = selectedNode.keys(); TableValuesElement[] result = new TableValuesElement[keys.length]; for (int i = 0; i < keys.length; i++) { try { if (selectedNode.isEncrypted(keys[i])) result[i] = new TableValuesElement(keys[i]); else result[i] = new TableValuesElement(keys[i], selectedNode.get(keys[i], null)); } catch (StorageException e) { Activator.log(IStatus.ERROR, SecUIMessages.failedDecrypt, null, e); } } return result; } }
private void saveProxyAuth(IProxyData data) { ISecurePreferences node= getNode(); if (node == null) return; try { if (data.getUserId() != null) node.put(INFO_PROXY_USER, data.getUserId(), true /* store encrypted */); else node.remove(INFO_PROXY_USER); if (data.getPassword() != null) node.put(INFO_PROXY_PASS, data.getPassword(), true /* store encrypted */); else node.remove(INFO_PROXY_PASS); } catch (StorageException e) { Activator.logError(e.getMessage(), e); return; } // optional: save it right away in case something crashes later try { node.flush(); } catch (IOException e) { Activator.logError(e.getMessage(), e); return; } }
private String getString(ISecurePreferences settings, String key) { try { return settings.get(key, ""); //$NON-NLS-1$ } catch (StorageException e) { return ""; //$NON-NLS-1$ } }
public void run() { if (selectedNode == null) return; NewValueDialog newValueDialog = new NewValueDialog(selectedNode.keys(), tableViewer.getControl().getShell()); if (newValueDialog.open() != Window.OK) return; String key = newValueDialog.getKey(); String value = newValueDialog.getValue(); boolean encrypt = newValueDialog.encrypt(); try { selectedNode.put(key, value, encrypt); parentView.modified(); } catch (StorageException e) { Activator.log(IStatus.ERROR, SecUIMessages.failedEncrypt, null, e); } tableViewer.refresh(); } };
public boolean flush(String newServerId) { String oldServerId = getServerId(); if (oldServerId != null && !oldServerId.equals(newServerId)) { initialize(); ISecurePreferences preferences = getSecurePreferences(); if (preferences != null) { preferences.removeNode(); } } this.serverId = newServerId; ISecurePreferences preferences = getSecurePreferences(); if (preferences != null) { try { preferences.put(KEY_USERNAME, username, true); preferences.put(KEY_PASSWORD, password, true); return true; } catch (StorageException e) { disableSecurePreferences(e); } } return false; }
public void run() { TreeSelection selection = (TreeSelection) nodeTreeViewer.getSelection(); Object selected = selection.getFirstElement(); if (selected instanceof ISecurePreferences) { ISecurePreferences node = (ISecurePreferences) selected; NewNodeDialog nodeDialog = new NewNodeDialog(nodeTreeViewer.getControl().getShell()); if (nodeDialog.open() != Window.OK) return; String name = nodeDialog.getNodeName(); ISecurePreferences child = node.node(name); parentView.modified(); // expand and select new node ISecurePreferences parentNode = child.parent(); if (parentNode != null) nodeTreeViewer.refresh(parentNode, false); else nodeTreeViewer.refresh(false); nodeTreeViewer.expandToLevel(child, 0); nodeTreeViewer.setSelection(new StructuredSelection(child), true); } } };
public void widgetSelected(SelectionEvent e) { ISecurePreferences root = SecurePreferencesFactory.getDefault(); if (root == null) return; try { root.flush(); } catch (IOException exception) { Activator.log(IStatus.ERROR, exception.getMessage(), null, exception); } validateSave(); // save could fail so re-check } });
public void run() { TreeSelection selection = (TreeSelection) nodeTreeViewer.getSelection(); Object selected = selection.getFirstElement(); if (selected instanceof ISecurePreferences) { ISecurePreferences node = (ISecurePreferences) selected; ISecurePreferences parentNode = node.parent(); if (parentNode == null) return; // can't remove root node node.removeNode(); parentView.modified(); // refresh parent node and select it nodeTreeViewer.refresh(parentNode, false); nodeTreeViewer.setSelection(new StructuredSelection(parentNode), true); } } };