| author | Pierrick MARIE | 2012-06-18 05:31:26 (EDT) |
|---|---|---|
| committer | Benjamin Cabé | 2012-06-18 05:31:26 (EDT) |
| commit | 8fe1123aa66b266c399fa000889d853c45ed6998 (patch) (side-by-side diff) | |
| tree | 405b0f605acb47eaa5d626ec02080371783170e3 | |
| parent | 90458737a5ae4a84965a92af5b145f17a263c388 (diff) | |
| download | org.eclipse.koneki.protocols-8fe1123aa66b266c399fa000889d853c45ed6998.zip org.eclipse.koneki.protocols-8fe1123aa66b266c399fa000889d853c45ed6998.tar.gz org.eclipse.koneki.protocols-8fe1123aa66b266c399fa000889d853c45ed6998.tar.bz2 | |
Provide the 'none' and basic authentication choice
4 files changed, 83 insertions, 38 deletions
diff --git a/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/DMClient.java b/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/DMClient.java index 9a209cb..c4f4dcc 100644 --- a/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/DMClient.java +++ b/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/DMClient.java @@ -13,6 +13,7 @@ package org.eclipse.koneki.protocols.omadm.client; import java.net.URI; 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; @@ -97,7 +98,7 @@ public interface DMClient { * if {@code server}, {@code client}, {@code devInfoNodes}, {@code commandHandler}, {@code protocolLinsteners} or * {@code genericAlerts} are {@code null} */ - void initiateManagementSession(final URI server, final String userAuth, final URI client, final DMNode[] devInfoNodes, + void initiateManagementSession(final URI server, final DMAuthentication userAuth, final URI client, final DMNode[] devInfoNodes, final CommandHandler commandHandler, final ProtocolListener[] protocolLinsteners, final DMGenericAlert[] genericAlerts); } diff --git a/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicClient.java b/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicClient.java index 2c5427e..7e01aa8 100644 --- a/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicClient.java +++ b/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicClient.java @@ -24,6 +24,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; 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; @@ -49,23 +50,24 @@ public abstract class DMBasicClient implements DMClient { @Override public void initiateManagementSession(final URI server, final URI client, final DMNode[] devInfoNodes, final CommandHandler commandHandler) { - initiateManagementSession(server, "", client, devInfoNodes, commandHandler, new ProtocolListener[] {}, new DMGenericAlert[] {}); //$NON-NLS-1$ + initiateManagementSession(server, new DMAuthentication(), client, devInfoNodes, commandHandler, new ProtocolListener[] {}, + new DMGenericAlert[] {}); //$NON-NLS-1$ } @Override public void initiateManagementSession(final URI server, final URI client, final DMNode[] devInfoNodes, final CommandHandler commandHandler, final ProtocolListener[] protocolLinsteners) { - initiateManagementSession(server, "", client, devInfoNodes, commandHandler, protocolLinsteners, new DMGenericAlert[] {}); //$NON-NLS-1$ + initiateManagementSession(server, new DMAuthentication(), client, devInfoNodes, commandHandler, protocolLinsteners, new DMGenericAlert[] {}); //$NON-NLS-1$ } @Override public void initiateManagementSession(final URI server, final URI client, final DMNode[] devInfoNodes, final CommandHandler commandHandler, final DMGenericAlert[] genericAlerts) { - initiateManagementSession(server, "", client, devInfoNodes, commandHandler, new ProtocolListener[] {}, genericAlerts); //$NON-NLS-1$ + initiateManagementSession(server, new DMAuthentication(), client, devInfoNodes, commandHandler, new ProtocolListener[] {}, genericAlerts); //$NON-NLS-1$ } @Override - public void initiateManagementSession(final URI server, final String userAuth, final URI client, final DMNode[] devInfoNodes, + public void initiateManagementSession(final URI server, final DMAuthentication userAuth, final URI client, final DMNode[] devInfoNodes, final CommandHandler commandHandler, final ProtocolListener[] protocolLinsteners, final DMGenericAlert[] genericAlerts) { if (server == null || client == null || devInfoNodes == null || commandHandler == null || protocolLinsteners == null || genericAlerts == null) { throw new NullPointerException(); diff --git a/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicSession.java b/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicSession.java index 1ae2276..e1b8a21 100644 --- a/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicSession.java +++ b/omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicSession.java @@ -29,6 +29,7 @@ import javax.xml.stream.events.XMLEvent; import org.apache.commons.io.input.TeeInputStream; import org.apache.commons.io.output.TeeOutputStream; 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.DMItem; import org.eclipse.koneki.protocols.omadm.DMMeta; @@ -73,12 +74,12 @@ final class DMBasicSession implements Runnable { private boolean isSetupPhaseFired; private boolean isManagementPhaseFired; private String currentServerMsgID; - private final String userAuth; + private final DMAuthentication authentication; - public DMBasicSession(final DMBasicClient dmClient, final URI server, final String userAuth, final URI client, final String sessionId, + public DMBasicSession(final DMBasicClient dmClient, final URI server, final DMAuthentication userAuth, final URI client, final String sessionId, final DMNode[] devInfoNodes, final CommandHandler commandHandler, final ProtocolListener[] protocolLinsteners, final DMGenericAlert[] genericAlerts) { - this.userAuth = userAuth; + this.authentication = userAuth; this.dmClient = dmClient; this.server = server; this.client = client; @@ -166,6 +167,40 @@ final class DMBasicSession implements Runnable { }); } + private void writeAuthentication(final XMLStreamWriter writer) throws XMLStreamException { + if (!(null == authentication.getAuthentication())) { + + /* + * Add basic authentication + */ + writer.writeStartElement("Cred"); //$NON-NLS-1$ + { + writer.writeStartElement("Meta"); //$NON-NLS-1$ + { + writer.writeStartElement("Format"); //$NON-NLS-1$ + writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ + writer.writeCharacters("b64"); //$NON-NLS-1$ + writer.writeEndElement(); + + writer.writeStartElement("Type"); //$NON-NLS-1$ + writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ + writer.writeCharacters("syncml:auth-basic"); //$NON-NLS-1$ + writer.writeEndElement(); + } + writer.writeEndElement(); + + writer.writeStartElement("Data"); //$NON-NLS-1$ + writer.writeCharacters(new String(authentication.getAuthentication())); + writer.writeEndElement(); + + } + writer.writeEndElement(); + /* + * End authentication + */ + } + } + private void writeMessage(final OutputStream out) throws XMLStreamException { final XMLStreamWriter writer = this.dmClient.createXMLStreamWriter(out, ENCODING); writer.writeStartDocument(ENCODING, "1.0"); //$NON-NLS-1$ @@ -203,34 +238,7 @@ final class DMBasicSession implements Runnable { } writer.writeEndElement(); - /* - * Add basic authentication - */ - writer.writeStartElement("Cred"); //$NON-NLS-1$ - { - writer.writeStartElement("Meta"); //$NON-NLS-1$ - { - writer.writeStartElement("Format"); //$NON-NLS-1$ - writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ - writer.writeCharacters("b64"); //$NON-NLS-1$ - writer.writeEndElement(); - - writer.writeStartElement("Type"); //$NON-NLS-1$ - writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ - writer.writeCharacters("syncml:auth-basic"); //$NON-NLS-1$ - writer.writeEndElement(); - } - writer.writeEndElement(); - - writer.writeStartElement("Data"); //$NON-NLS-1$ - writer.writeCharacters(userAuth); - writer.writeEndElement(); - - } - writer.writeEndElement(); - /* - * End authentication - */ + writeAuthentication(writer); } writer.writeEndElement(); writer.writeStartElement("SyncBody"); //$NON-NLS-1$ @@ -901,10 +909,10 @@ final class DMBasicSession implements Runnable { if (status.getDelayedProcessing() != null) { this.dmClient.execute(this.client, new Runnable() { - @Override + // @Override public void run() { try { - dmClient.initiateManagementSession(server, "", client, devInfoNodes, commandHandler, protocolLinsteners, //$NON-NLS-1$ + dmClient.initiateManagementSession(server, authentication, client, devInfoNodes, commandHandler, protocolLinsteners, //$NON-NLS-1$ new DMGenericAlert[] { status.getDelayedProcessing().call() }); } catch (final Exception e) { Activator.logError("Error while initializing management session", e); //$NON-NLS-1$ diff --git a/omadm/bundles/org.eclipse.koneki.protocols.omadm/src/org/eclipse/koneki/protocols/omadm/DMAuthentication.java b/omadm/bundles/org.eclipse.koneki.protocols.omadm/src/org/eclipse/koneki/protocols/omadm/DMAuthentication.java new file mode 100644 index 0000000..2ba1a0e --- a/dev/null +++ b/omadm/bundles/org.eclipse.koneki.protocols.omadm/src/org/eclipse/koneki/protocols/omadm/DMAuthentication.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2012 Sierra Wireless and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sierra Wireless - initial API and implementation + *******************************************************************************/ +package org.eclipse.koneki.protocols.omadm; + +/** + * TODO Comment this class + */ +public class DMAuthentication { + + private byte[] basicAuthentication; + + public DMAuthentication() { + basicAuthentication = null; + } + + public DMAuthentication(final byte[] basicAuthentication) { + this.basicAuthentication = basicAuthentication; + } + + /** + * @return the basicAuthentication + */ + public byte[] getAuthentication() { + return basicAuthentication; + } +} |

