Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2015-10-10 08:04:32 +0000
committerEike Stepper2015-10-10 08:04:32 +0000
commitb9bec64db5d3d403beaeddc761e109bccd561253 (patch)
tree747509e65d6e4f24f83f2b4d2cb47b0cf971f5cb /plugins/org.eclipse.emf.cdo.explorer
parent7b5b1da475c629fc3644c58e89d54e65c41f04df (diff)
downloadcdo-b9bec64db5d3d403beaeddc761e109bccd561253.tar.gz
cdo-b9bec64db5d3d403beaeddc761e109bccd561253.tar.xz
cdo-b9bec64db5d3d403beaeddc761e109bccd561253.zip
[479422] CDO Credential Provider not implemented for CDORepositoryImpl
https://bugs.eclipse.org/bugs/show_bug.cgi?id=479422
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.explorer')
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryManager.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/bundle/OM.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java65
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java16
5 files changed, 94 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF
index 3df4f3e844..4593ae40f8 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.explorer/META-INF/MANIFEST.MF
@@ -11,6 +11,7 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.equinox.security;bundle-version="[1.0.0,2.0.0)",
org.eclipse.emf.cdo.net4j;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.workspace;bundle-version="[4.0.0,5.0.0)",
org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)",
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryManager.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryManager.java
index 6299906de9..771cc9724d 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryManager.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryManager.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.explorer.CDOExplorerManager;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.security.IPasswordCredentials;
import java.util.Properties;
@@ -42,6 +43,11 @@ public interface CDORepositoryManager extends CDOExplorerManager<CDORepository>
public CDORepository addRepository(Properties properties);
/**
+ * @since 4.5
+ */
+ public CDORepository addRepository(Properties properties, IPasswordCredentials credentials);
+
+ /**
* @author Eike Stepper
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/bundle/OM.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/bundle/OM.java
index 515832a382..237662e6c4 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/bundle/OM.java
@@ -40,10 +40,17 @@ public abstract class OM
private static final String STATE_LOCATION = System.getProperty("org.eclipse.emf.cdo.explorer.stateLocation");
+ private static String stateLocation;
+
private static CDORepositoryManagerImpl repositoryManager;
private static CDOCheckoutManagerImpl checkoutManager;
+ public static String getStateLocation()
+ {
+ return stateLocation;
+ }
+
public static void initializeManagers(File stateLocation)
{
disposeManagers();
@@ -95,7 +102,7 @@ public abstract class OM
{
super.doStart();
- String stateLocation = STATE_LOCATION != null ? STATE_LOCATION : BUNDLE.getStateLocation();
+ stateLocation = STATE_LOCATION != null ? STATE_LOCATION : BUNDLE.getStateLocation();
initializeManagers(new File(stateLocation));
}
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java
index ba4f519832..b28d3d6d50 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java
@@ -38,6 +38,7 @@ import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.UUIDGenerator;
import org.eclipse.net4j.util.container.ContainerEvent;
import org.eclipse.net4j.util.container.IContainerEvent;
@@ -48,12 +49,18 @@ import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
import org.eclipse.net4j.util.security.IPasswordCredentials;
+import org.eclipse.net4j.util.security.PasswordCredentials;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.provider.IProviderHints;
+
import java.io.File;
+import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -176,11 +183,53 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe
public IPasswordCredentials getCredentials(String realm)
{
+ try
+ {
+ ISecurePreferences securePreferences = getSecurePreferences();
+ if (securePreferences != null)
+ {
+ String path = getSecurePath(securePreferences);
+ if (securePreferences.nodeExists(path))
+ {
+ ISecurePreferences node = securePreferences.node(path);
+ String userID = node.get("username", null);
+
+ if (!StringUtil.isEmpty(userID))
+ {
+ String password = node.get("password", null);
+ return new PasswordCredentials(userID, password);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+
return null;
}
public void setCredentials(IPasswordCredentials credentials)
{
+ try
+ {
+ ISecurePreferences securePreferences = getSecurePreferences();
+ if (securePreferences != null)
+ {
+ String path = getSecurePath(securePreferences);
+ ISecurePreferences node = securePreferences.node(path);
+
+ node.put("uri", getURI(), false);
+ node.put("username", credentials.getUserID(), false);
+ node.put("password", new String(credentials.getPassword()), true);
+ node.flush();
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
}
public boolean isInteractive()
@@ -671,4 +720,20 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe
{
session.close();
}
+
+ private String getSecurePath(ISecurePreferences securePreferences)
+ {
+ String stateLocation = OM.getStateLocation().replace('/', '\\');
+ String id = getID().replace('/', '_');
+
+ return "CDO/" + stateLocation + "/" + id;
+ }
+
+ private static ISecurePreferences getSecurePreferences() throws IOException
+ {
+ Map<Object, Object> options = new HashMap<Object, Object>();
+ options.put(IProviderHints.PROMPT_USER, Boolean.FALSE);
+
+ return SecurePreferencesFactory.open(null, options);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java
index 3eaeb6e794..7edcb61fdc 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.internal.explorer.AbstractManager;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.security.IPasswordCredentials;
import java.io.File;
import java.util.Map;
@@ -25,7 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* @author Eike Stepper
*/
-public class CDORepositoryManagerImpl extends AbstractManager<CDORepository>implements CDORepositoryManager
+public class CDORepositoryManagerImpl extends AbstractManager<CDORepository> implements CDORepositoryManager
{
public static final String SECURE_STORE_PATH = "/CDO/repositories";
@@ -66,7 +67,18 @@ public class CDORepositoryManagerImpl extends AbstractManager<CDORepository>impl
public CDORepository addRepository(Properties properties)
{
- return newElement(properties);
+ return addRepository(properties, null);
+ }
+
+ public CDORepository addRepository(Properties properties, IPasswordCredentials credentials)
+ {
+ CDORepository repository = newElement(properties);
+ if (repository != null && credentials != null)
+ {
+ repository.setCredentials(credentials);
+ }
+
+ return repository;
}
public void disconnectUnusedRepositories()

Back to the top