Search in sources :

Example 11 with ISecurePreferences

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

the class IDEntry method addAssociateFromName.

private void addAssociateFromName(String name, SortedMap results) {
    try {
        // Get index of first :
        int index = name.indexOf(DELIMITER);
        // If not found then the name is not well-formed
        if (index == -1)
            // $NON-NLS-1$
            throw new IDStoreException("Associate ID not well-formed");
        // Get the index string
        String indexStr = name.substring(0, index);
        Integer resultIndex = null;
        // Create resultIndex from indexStr
        try {
            resultIndex = Integer.valueOf(indexStr);
        } catch (NumberFormatException e) {
            // $NON-NLS-1$
            throw new IDStoreException("Associate ID not well-formed", e);
        }
        // get remainder string
        name = name.substring(index + 1);
        // Get index of second :
        index = name.indexOf(DELIMITER);
        if (index == -1)
            // $NON-NLS-1$
            throw new IDStoreException("Associate ID not well-formed");
        // Get namespace name before index
        String namespaceName = name.substring(0, index);
        ISecurePreferences namespacePrefs = getPreferences(getNamespaceRoot(), namespaceName);
        if (namespacePrefs == null)
            throw new IDStoreException(// $NON-NLS-1$
            "Cannot find Namespace=" + namespaceName);
        // Get ID name after index
        String idName = name.substring(index + 1);
        ISecurePreferences idPrefs = getPreferences(namespacePrefs, idName);
        if (idPrefs == null)
            throw new IDStoreException(// $NON-NLS-1$ //$NON-NLS-2$
            "ID=" + idName + " not found in Namespace=" + namespaceName);
        // Put new IDEntry in sorted collection ordered by resultIndex
        results.put(resultIndex, new IDEntry(idPrefs));
    } catch (IDStoreException e) {
        Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Unable to create associate ID", // $NON-NLS-1$
        e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IIDEntry(org.eclipse.ecf.storage.IIDEntry) IDStoreException(org.eclipse.ecf.storage.IDStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 12 with ISecurePreferences

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

the class IDEntry method putAssociate.

public void putAssociate(String key, IIDEntry entry, boolean encrypt) throws IDStoreException {
    if (key == null)
        // $NON-NLS-1$
        throw new IDStoreException("key cannot be null");
    if (entry == null)
        // $NON-NLS-1$
        throw new IDStoreException("entry cannot be null");
    ISecurePreferences associateNode = prefs.node(key);
    ISecurePreferences prefs = entry.getPreferences();
    // This is where associates are created with form:
    // <index>:<namespace>:<idname>
    String entryAssociate = String.valueOf(associateNode.childrenNames().length) + DELIMITER + prefs.parent().name() + DELIMITER + prefs.name();
    associateNode.node(entryAssociate);
}
Also used : IDStoreException(org.eclipse.ecf.storage.IDStoreException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 13 with ISecurePreferences

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

the class IDStoreTest method testGetNamespaceNode.

public void testGetNamespaceNode() throws Exception {
    final ID newGUID = IDFactory.getDefault().createGUID();
    idStore.store(newGUID);
    final ISecurePreferences namespacePrefs = idStore.getNamespaceEntry(newGUID.getNamespace()).getPreferences();
    assertNotNull(namespacePrefs);
    assertTrue(namespacePrefs.name().equals(newGUID.getNamespace().getName()));
}
Also used : ID(org.eclipse.ecf.core.identity.ID) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 14 with ISecurePreferences

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

the class IDStoreTest method testStoreGUID.

public void testStoreGUID() throws Exception {
    final ISecurePreferences prefs = addGUID().getPreferences();
    assertNotNull(prefs);
}
Also used : ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences)

Example 15 with ISecurePreferences

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

the class P2PasswordUtil method setCredentials.

static void setCredentials(URI location, String username, String password, MavenLogger logger) {
    ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault();
    // if URI is not opaque, just getting the host may be enough
    String host = location.getHost();
    if (host == null) {
        String scheme = location.getScheme();
        if (URIUtil.isFileURI(location) || scheme == null) {
            // If the URI references a file, a password could possibly be needed for the directory
            // (it could be a protected zip file representing a compressed directory) - in this
            // case the key is the path without the last segment.
            // Using "Path" this way may result in an empty string - which later will result in
            // an invalid key.
            host = new Path(location.toString()).removeLastSegments(1).toString();
        } else {
            // it is an opaque URI - details are unknown - can only use entire string.
            host = location.toString();
        }
    }
    String nodeKey;
    try {
        // $NON-NLS-1$
        nodeKey = URLEncoder.encode(host, "UTF-8");
    } catch (UnsupportedEncodingException e2) {
        // fall back to default platform encoding
        try {
            // Uses getProperty "file.encoding" instead of using deprecated URLEncoder.encode(String location)
            // which does the same, but throws NPE on missing property.
            // $NON-NLS-1$
            String enc = System.getProperty("file.encoding");
            if (enc == null) {
                throw new UnsupportedEncodingException(// $NON-NLS-1$
                "No UTF-8 encoding and missing system property: file.encoding");
            }
            nodeKey = URLEncoder.encode(host, enc);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
    String nodeName = IRepository.PREFERENCE_NODE + '/' + nodeKey;
    ISecurePreferences prefNode = securePreferences.node(nodeName);
    try {
        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);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ISecurePreferences(org.eclipse.equinox.security.storage.ISecurePreferences) StorageException(org.eclipse.equinox.security.storage.StorageException)

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