0

如何以编程方式删除 eclipse 安全存储中保存的内容?在运行一些 SWTBot 测试之前,我需要重置所有设置。

我知道,我可以删除文件夹,但没有其他方法吗?

../.eclipse/org.eclipse.equinox.security

编辑:

感谢克里斯,我解决了这个问题。

    //part 1
    try {
        AuthPlugin.getDefault().stop(null);
    } catch (final Exception e) {
        e.printStackTrace();
    }
    //part 2
    final ISecurePreferences rootNode = SecurePreferencesFactory.getDefault()
            .node(ROOT_NODE_NAME);
    final String[] names = rootNode.childrenNames().clone();
    for (int i = 0; i < names.length; i++) {
        rootNode.node(names[i]).removeNode();
    }

该问题已在第 2 部分中解决。我还想通过使用 SWTBot 进行测试来展示如何停止安全存储身份验证的方法,因为这很烦人。

4

1 回答 1

1

您可以使用 ISecurePreferences 删除安全存储中存储的值。看看这里

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
于 2011-09-13T12:18:10.687 回答