summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierrick MARIE2012-06-18 05:32:20 (EDT)
committerBenjamin Cabé2012-06-18 05:32:20 (EDT)
commit4eaf4cb53b6847b97dca20b8c57664e6c605cabd (patch)
treeb039d32be86526468a358db5482035253949de24
parent4d259a2eac3bd22c28c09d1d2f46b929c9420db0 (diff)
downloadorg.eclipse.koneki.simulators-4eaf4cb53b6847b97dca20b8c57664e6c605cabd.zip
org.eclipse.koneki.simulators-4eaf4cb53b6847b97dca20b8c57664e6c605cabd.tar.gz
org.eclipse.koneki.simulators-4eaf4cb53b6847b97dca20b8c57664e6c605cabd.tar.bz2
Provide the 'none' and basic authentication choice
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/internal/dashboard/ConnectSelection.java2
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/DMSimulator.java24
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulation.java44
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulator.java12
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/internal/DMBasicSimulatorComponent.java5
5 files changed, 77 insertions, 10 deletions
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/internal/dashboard/ConnectSelection.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/internal/dashboard/ConnectSelection.java
index 222753e..8ce7d4a 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/internal/dashboard/ConnectSelection.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/internal/dashboard/ConnectSelection.java
@@ -93,7 +93,7 @@ class ConnectSelection extends SelectionAdapter {
updateServerURI(editor);
// Connect
- dmSimulator.simulate(server, page.getEditor().getOMADMSimulation().getDevice().getTree(), page.getEditor().getOMADMSimulation().getDevice()
+ dmSimulator.simulate(server, page.getEditor().getOMADMSimulation().getDevice().getTree(), editor.getOMADMSimulation().getDevice()
.getAuthentication(), page.getEditor().getEditingDomain(), new ConnectCommandHandler(page),
new ProtocolListener[] { new ConnectProtocolListener(page) }, genericAlerts.toArray(new DMGenericAlert[] {}));
if (monitor.isCanceled()) {
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/DMSimulator.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/DMSimulator.java
index 4a94c1f..53d7bf3 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/DMSimulator.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/DMSimulator.java
@@ -16,6 +16,7 @@ import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.koneki.protocols.omadm.CommandHandler;
import org.eclipse.koneki.protocols.omadm.DMGenericAlert;
import org.eclipse.koneki.protocols.omadm.ProtocolListener;
+import org.eclipse.koneki.simulators.omadm.model.AuthenticationType;
import org.eclipse.koneki.simulators.omadm.model.Node;
/**
@@ -99,4 +100,27 @@ public interface DMSimulator {
void simulate(final URI server, final Node tree, final EditingDomain editingDomain, final CommandHandler commandHandler,
final ProtocolListener[] protocolListeners, final DMGenericAlert[] genericAlerts);
+ /**
+ * Simulate the given tree with commands received from the server.
+ *
+ * @param server
+ * the DM server
+ * @param tree
+ * the tree to simulate
+ * @param auhtentication
+ * the authentication type to use for the connection
+ * @param editingDomain
+ * the editing domain for modify the tree
+ * @param commandHandler
+ * the command handler for node with is in manual management mode
+ * @param protocolListeners
+ * objects want listen protocol event
+ * @param genericAlerts
+ * generic alerts must be send to server at the beginning of the DM session
+ * @throws NullPointerException
+ * if {@code server}, {@code tree}, {@code editingDomain}, {@code commandHandler}, {@code protocolListeners} or {@code genericAlerts}
+ * are {@code null}
+ */
+ void simulate(final URI server, final Node tree, final AuthenticationType authentication, final EditingDomain editingDomain,
+ final CommandHandler commandHandler, final ProtocolListener[] protocolListeners, final DMGenericAlert[] genericAlerts);
}
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulation.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulation.java
index 198d2d7..1cb05ff 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulation.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulation.java
@@ -18,6 +18,7 @@ import java.util.List;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.koneki.protocols.omadm.CommandHandler;
+import org.eclipse.koneki.protocols.omadm.DMAuthentication;
import org.eclipse.koneki.protocols.omadm.DMGenericAlert;
import org.eclipse.koneki.protocols.omadm.DMNode;
import org.eclipse.koneki.protocols.omadm.ProtocolListener;
@@ -25,6 +26,7 @@ import org.eclipse.koneki.protocols.omadm.Status;
import org.eclipse.koneki.protocols.omadm.StatusCode;
import org.eclipse.koneki.simulators.omadm.DMSimulatorException;
import org.eclipse.koneki.simulators.omadm.internal.Activator;
+import org.eclipse.koneki.simulators.omadm.model.AuthenticationType;
import org.eclipse.koneki.simulators.omadm.model.Node;
import org.eclipse.koneki.simulators.omadm.model.NodeFormat;
import org.eclipse.koneki.simulators.omadm.model.util.NodeHelpers;
@@ -43,12 +45,27 @@ final class DMBasicSimulation implements Runnable, CommandHandler {
private final CommandHandler commandHandler;
private final ProtocolListener[] protocolListeners;
private final DMGenericAlert[] genericAlerts;
+ private final AuthenticationType authentication;
public DMBasicSimulation(final DMBasicSimulator dmSimulator, final URI server, final Node tree, final EditingDomain editingDomain,
final CommandHandler commandHandler, final ProtocolListener[] protocolListeners, final DMGenericAlert[] genericAlerts) {
this.dmSimulator = dmSimulator;
this.server = server;
this.tree = tree;
+ this.authentication = AuthenticationType.NONE;
+ this.editingDomain = editingDomain;
+ this.commandHandler = commandHandler;
+ this.protocolListeners = protocolListeners;
+ this.genericAlerts = genericAlerts;
+ }
+
+ public DMBasicSimulation(final DMBasicSimulator dmSimulator, final URI server, final Node tree, final AuthenticationType authentication,
+ final EditingDomain editingDomain, final CommandHandler commandHandler, final ProtocolListener[] protocolListeners,
+ final DMGenericAlert[] genericAlerts) {
+ this.dmSimulator = dmSimulator;
+ this.server = server;
+ this.tree = tree;
+ this.authentication = authentication;
this.editingDomain = editingDomain;
this.commandHandler = commandHandler;
this.protocolListeners = protocolListeners;
@@ -86,16 +103,25 @@ final class DMBasicSimulation implements Runnable, CommandHandler {
});
- /*
- * Create a Base64 code with the user name and user password value
- */
- String userName = NodeHelpers.findFirstNode(NodeHelpers.getNode(tree, APP_AUTH), AUTH_NAME).getData();
- String userPassword = NodeHelpers.findFirstNode(NodeHelpers.getNode(tree, APP_AUTH), AUTH_SECRET).getData();
- String userAuth = userName + ":" + userPassword; //$NON-NLS-1$
- byte[] encoded = Base64.encodeBase64(userAuth.getBytes());
+ DMAuthentication dmAuth = null;
+
+ switch (authentication.getValue()) {
+ case (AuthenticationType.NONE_VALUE):
+ dmAuth = new DMAuthentication();
+ break;
+ case (AuthenticationType.BASIC_VALUE):
+ /*
+ * Create a Base64 code with the user name and user password value
+ */
+ String userName = NodeHelpers.findFirstNode(NodeHelpers.getNode(tree, APP_AUTH), AUTH_NAME).getData();
+ String userPassword = NodeHelpers.findFirstNode(NodeHelpers.getNode(tree, APP_AUTH), AUTH_SECRET).getData();
+ String userAuth = userName + ":" + userPassword; //$NON-NLS-1$
+ dmAuth = new DMAuthentication(Base64.encodeBase64(userAuth.getBytes()));
+ break;
+ }
- this.dmSimulator.getDMClient().initiateManagementSession(this.server, new String(encoded), client, devInfoNodes.toArray(new DMNode[0]),
- this, this.protocolListeners, this.genericAlerts);
+ this.dmSimulator.getDMClient().initiateManagementSession(this.server, dmAuth, client, devInfoNodes.toArray(new DMNode[0]), this,
+ this.protocolListeners, this.genericAlerts);
} catch (final DMSimulatorException e) {
Activator.logError("Problem while initializing management session", e); //$NON-NLS-1$
}
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulator.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulator.java
index 45e1cb1..5e52438 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulator.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/basic/DMBasicSimulator.java
@@ -26,6 +26,7 @@ import org.eclipse.koneki.protocols.omadm.Status;
import org.eclipse.koneki.protocols.omadm.StatusCode;
import org.eclipse.koneki.protocols.omadm.client.DMClient;
import org.eclipse.koneki.simulators.omadm.DMSimulator;
+import org.eclipse.koneki.simulators.omadm.model.AuthenticationType;
import org.eclipse.koneki.simulators.omadm.model.Node;
/**
@@ -178,6 +179,17 @@ public class DMBasicSimulator implements DMSimulator {
this.executorService.execute(new DMBasicSimulation(this, server, tree, editingDomain, commandHandler, protocolListeners, genericAlerts));
}
+ @Override
+ public void simulate(final URI server, final Node tree, final AuthenticationType authentication, final EditingDomain editingDomain,
+ final CommandHandler commandHandler, final ProtocolListener[] protocolListeners, final DMGenericAlert[] genericAlerts) {
+ if (server == null || tree == null || authentication == null || editingDomain == null || commandHandler == null || protocolListeners == null
+ || genericAlerts == null) {
+ throw new NullPointerException();
+ }
+ this.executorService.execute(new DMBasicSimulation(this, server, tree, authentication, editingDomain, commandHandler, protocolListeners,
+ genericAlerts));
+ }
+
final DMClient getDMClient() {
return this.dmClient;
}
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/internal/DMBasicSimulatorComponent.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/internal/DMBasicSimulatorComponent.java
index 4e4d891..c7ee9f1 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/internal/DMBasicSimulatorComponent.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm/src/org/eclipse/koneki/simulators/omadm/internal/DMBasicSimulatorComponent.java
@@ -22,6 +22,7 @@ import org.eclipse.koneki.protocols.omadm.client.DMClient;
import org.eclipse.koneki.simulators.omadm.DMSimulator;
import org.eclipse.koneki.simulators.omadm.basic.DMBasicSimulator;
import org.eclipse.koneki.simulators.omadm.basic.DMExecHandler;
+import org.eclipse.koneki.simulators.omadm.model.AuthenticationType;
import org.eclipse.koneki.simulators.omadm.model.Node;
import org.osgi.service.component.ComponentContext;
@@ -81,4 +82,8 @@ public class DMBasicSimulatorComponent implements DMSimulator {
this.simulator.simulate(server, tree, editingDomain, commandHandler, protocolListeners, genericAlerts);
}
+ public void simulate(final URI server, final Node tree, final AuthenticationType authentication, final EditingDomain editingDomain,
+ final CommandHandler commandHandler, final ProtocolListener[] protocolListeners, final DMGenericAlert[] genericAlerts) {
+ this.simulator.simulate(server, tree, authentication, editingDomain, commandHandler, protocolListeners, genericAlerts);
+ }
}