Storage/Retrieval of IDs, IContainers using Equinox Secure Preferences

From Eclipsepedia

Jump to: navigation, search

In the Platform 3.4M6a release, secure storage was introduced in Equinox. (See secure storage section on [http://download.eclipse.org/eclipse/downloads/drops/S-3.4M6a-200804091425/eclipse-news-M6.html Platform 3.4M6a).

ECF IDs can represent many things: from user accounts, to target files/URIs, to remote services. IDs are fully extensible: plugins can extend ECF's notion of ID by introducing new Namespaces (org.eclipse.ecf.namespace extension point), which then construct IDs of appropriate types.

To connect an ECF IContainer to a corresponding network service, a target ID must be provided, along with an IConnectContext to specify credentials (e.g. passwords). Typically, in ECF connection is done in a manner something like this

IContainer container = ...
// Create targetID
ID targetID = IDFactory.getDefault().createID(container.getConnectNamespace(),"fliwatuet@ecf.eclipse.org");
// Create connectContext with password
IConnectContext connectContext = ConnectContextFactory.createPasswordConnectContext("password");
// Connect to target using targetID and connectContext
container.connect(targetID,connectContext);

A common use case is to securely persist account information (username/ID and associated password) and upon Eclipse/ECF startup restore the information and use it to connect to a remote service.

In ECF terms, this requires storing and restoring the targetID, credentials like password associated with the targetID, and possibly the container instance as well.

To make this possible, I've implemented two new services: org.eclipse.ecf.storage.IIDStore and org.eclipse.ecf.storage.IContainerStore. See the complete source for these interfaces here. These two stores allow the storage and retrieval of ECF Namespaces/IDs and IContainers, respectively.

Here's some example code that shows how to save and restore an ID and associated password with the IIDStore

// Store
IDStore idStore = getIDStoreOSGiService();
// Create an ID
ID newGUID = IDFactory.getDefault().createGUID();
// Store it using the idStore
IIDEntry newGUIDEntry = idStore.store(newGUID);
// Associate and save password to secure store also
newGUIDEntry.getPreferences().put("password",password,true);

// Retrieve
IDStore idStore = getIDStoreOSGiService();
// Get namespace entry from store
INamespaceEntry restoredNamespace = idStore.getNamespaceEntry(guidNamespace);
// Get previously stored IDs
IIDEntry[] idEntries = namespaceEntry.getIDEntries();
// Create ID instance from idEntries[0]
ID restoredNewGUID = idEntries[0].createID();
// Get password from idEntries[0]
String restoredPassword = (String) idEntries[0].getPreferences().get("password");

// Now can use restoredNewGUID and restoredPassword

There is a test project with further test and example code here.

To load into your own workspace use here for anonymous and here for committers.