summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2012-11-17 15:55:06 (EST)
committerPascal Rapicault2013-01-19 17:13:46 (EST)
commit467eafdd2b132082810dcd8767f59d7256a1086f (patch)
tree65fcae0e4e04abb3d031bfaa32fb05b142c27a25
parent7008623c6ce66cc8d552b263d9c0f9c0815f5436 (diff)
downloadrt.equinox.p2-467eafdd2b132082810dcd8767f59d7256a1086f.zip
rt.equinox.p2-467eafdd2b132082810dcd8767f59d7256a1086f.tar.gz
rt.equinox.p2-467eafdd2b132082810dcd8767f59d7256a1086f.tar.bz2
Remove undesirable dependency on security bundle
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SlashEncode.java89
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java4
4 files changed, 92 insertions, 5 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
index 560e130..5f5fa2a 100644
--- a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
@@ -48,7 +48,6 @@ Import-Package: javax.xml.parsers,
org.eclipse.equinox.p2.repository.metadata;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.metadata.spi;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.spi;version="2.0.0",
- org.eclipse.equinox.security.storage;version="1.0.0",
org.eclipse.osgi.service.datalocation;version="1.0.0",
org.eclipse.osgi.service.debug;version="1.1.0",
org.eclipse.osgi.service.security;version="1.0.0",
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java
index 01b9aa7..d62eb97 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java
@@ -22,7 +22,6 @@ import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.core.IAgentLocation;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
-import org.eclipse.equinox.security.storage.EncodingUtils;
import org.osgi.framework.*;
import org.osgi.service.prefs.BackingStoreException;
@@ -144,7 +143,7 @@ public class ProfilePreferences extends EclipsePreferences {
* agent location. Never returns null; throws an exception if the agent could not be found.
*/
protected IProvisioningAgent getAgent(String segment) throws BackingStoreException {
- String locationString = EncodingUtils.decodeSlashes(segment);
+ String locationString = SlashEncode.decode(segment);
Exception failure = null;
IProvisioningAgent result = null;
try {
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SlashEncode.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SlashEncode.java
new file mode 100644
index 0000000..9c1a185
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SlashEncode.java
@@ -0,0 +1,89 @@
+package org.eclipse.equinox.internal.p2.engine;
+
+/**
+ * Utility class to encode forward slash characters so that strings containing
+ * forward slashes can be used as node names with secure preferences. It is
+ * the responsibility of the consumer to manually encode such strings before
+ * attempting to obtain corresponding nodes from secure preferences.
+ * <p>
+ * Internally, the class uses a subset of JIT encoding. The forward slashes
+ * and backward slashes are encoded.
+ * </p><p>
+ * This class is not intended to be instantiated or subclassed by users.
+ * </p>
+ */
+final public class SlashEncode {
+
+ final private static char SLASH = '/';
+ final private static char BACK_SLASH = '\\';
+
+ final private static String ENCODED_SLASH = "\\2f"; //$NON-NLS-1$
+ final private static String ENCODED_BACK_SLASH = "\\5c"; //$NON-NLS-1$
+
+ static public String decode(String str) {
+ if (str == null)
+ return null;
+ int size = str.length();
+ if (size == 0)
+ return str;
+
+ StringBuffer processed = new StringBuffer(size);
+ int processedPos = 0;
+
+ for (int i = 0; i < size; i++) {
+ char c = str.charAt(i);
+ if (c == BACK_SLASH) {
+ if (i + 2 >= size)
+ continue;
+ String encoded = str.substring(i, i + 3);
+ char decoded = 0;
+ if (ENCODED_SLASH.equals(encoded))
+ decoded = SLASH;
+ else if (ENCODED_BACK_SLASH.equals(encoded))
+ decoded = BACK_SLASH;
+ if (decoded == 0)
+ continue;
+ if (i > processedPos)
+ processed.append(str.substring(processedPos, i));
+ processed.append(decoded);
+ processedPos = i + 3;
+ i += 2; // skip over remaining encoded portion
+ }
+ }
+ if (processedPos == 0)
+ return str;
+ if (processedPos < size)
+ processed.append(str.substring(processedPos));
+ return new String(processed);
+ }
+
+ static public String encode(String str) {
+ if (str == null)
+ return null;
+ int size = str.length();
+ if (size == 0)
+ return str;
+
+ StringBuffer processed = new StringBuffer(size);
+ int processedPos = 0;
+
+ for (int i = 0; i < size; i++) {
+ char c = str.charAt(i);
+ if (c == SLASH || c == BACK_SLASH) {
+ if (i > processedPos)
+ processed.append(str.substring(processedPos, i));
+ if (c == SLASH)
+ processed.append(ENCODED_SLASH);
+ else if (c == BACK_SLASH)
+ processed.append(ENCODED_BACK_SLASH);
+ processedPos = i + 1;
+ }
+ }
+ if (processedPos == 0)
+ return str;
+ if (processedPos < size)
+ processed.append(str.substring(processedPos));
+ return new String(processed);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java
index 2a4c265..bbb2979 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/ProfileScope.java
@@ -15,8 +15,8 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.equinox.internal.p2.engine.SlashEncode;
import org.eclipse.equinox.p2.core.IAgentLocation;
-import org.eclipse.equinox.security.storage.EncodingUtils;
/**
* A profile scope contains the preferences associated with a particular profile
@@ -72,7 +72,7 @@ public final class ProfileScope implements IScopeContext {
public IEclipsePreferences getNode(String qualifier) {
if (qualifier == null)
throw new IllegalArgumentException();
- String locationString = EncodingUtils.encodeSlashes(location.getRootLocation().toString());
+ String locationString = SlashEncode.encode(location.getRootLocation().toString());
//format is /profile/{agentLocationURI}/{profileId}/qualifier
return (IEclipsePreferences) PreferencesService.getDefault().getRootNode().node(getName()).node(locationString).node(profileId).node(qualifier);
}