Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: for the plan.

Jump to: navigation, search

Storage/Retrieval of IDs, IContainers using Equinox Secure Preferences

In the Platform 3.4M6a release, secure storage was introduced in Equinox. (See secure storage section on [ 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(),"");
// Create connectContext with password
IConnectContext connectContext = ConnectContextFactory.createPasswordConnectContext("password");
// Connect to target using targetID and 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: and 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 =;
// Associate and save password to secure store also

// 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.

Back to the top