| author | Pierrick MARIE | 2012-07-04 09:27:18 (EDT) |
|---|---|---|
| committer | Benjamin Cabé | 2012-07-04 09:27:18 (EDT) |
| commit | 235a0508eb3ea2bf4a560edc1418e762ab757b5d (patch) (side-by-side diff) | |
| tree | 7518a369c0eae32c547f95a9856d4126105ec2f4 | |
| parent | 71ee8d22f72a0a7d971375ac0ffd0d99f0f29e0e (diff) | |
| download | org.eclipse.koneki.protocols-235a0508eb3ea2bf4a560edc1418e762ab757b5d.zip org.eclipse.koneki.protocols-235a0508eb3ea2bf4a560edc1418e762ab757b5d.tar.gz org.eclipse.koneki.protocols-235a0508eb3ea2bf4a560edc1418e762ab757b5d.tar.bz2 | |
A best version of the md5 authentication
| -rw-r--r-- | omadm/bundles/org.eclipse.koneki.protocols.omadm.client/src/org/eclipse/koneki/protocols/omadm/client/basic/DMBasicSession.java | 139 |
1 files changed, 58 insertions, 81 deletions
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 fddf383..bd395ce 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 @@ -195,77 +195,59 @@ final class DMBasicSession implements Runnable { private void writeAuthentication(final XMLStreamWriter writer) throws XMLStreamException { - switch (authentication.getAuthenticationType()) { - case BASIC: - /* - * 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("Cred"); //$NON-NLS-1$ - 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("Meta"); //$NON-NLS-1$ - writer.writeStartElement("Data"); //$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(); - /* - * Create a Base64 code with the user name and user password values - */ - String userAuth = authentication.getUser() + ":" + authentication.getPassword(); //$NON-NLS-1$ - byte[] B64Auth = Base64.encodeBase64(userAuth.getBytes()); + writer.writeStartElement("Type"); //$NON-NLS-1$ + writer.writeAttribute("xmlns", "syncml:metinf"); //$NON-NLS-1$ //$NON-NLS-2$ - writer.writeCharacters(new String(B64Auth)); - writer.writeEndElement(); + switch (authentication.getAuthenticationType()) { + /* + * Add basic authentication + */ + case BASIC: + writer.writeCharacters("syncml:auth-basic"); //$NON-NLS-1$ + writer.writeEndElement(); - } writer.writeEndElement(); - /* - * End authentication - */ + + writer.writeStartElement("Data"); //$NON-NLS-1$ + + writer.writeCharacters(computeBasicAuthentication()); break; /* * Add md5 authentication */ case MD5: - 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-md5"); //$NON-NLS-1$ - writer.writeEndElement(); - } - writer.writeEndElement(); + writer.writeCharacters("syncml:auth-md5"); //$NON-NLS-1$ + writer.writeEndElement(); - writer.writeStartElement("Data"); //$NON-NLS-1$ + writer.writeEndElement(); - writer.writeCharacters(computeMd5Authentication()); + writer.writeStartElement("Data"); //$NON-NLS-1$ - writer.writeEndElement(); + writer.writeCharacters(computeMd5Authentication()); - } - writer.writeEndElement(); - /* - * End authentication - */ break; } + + writer.writeEndElement(); + + writer.writeEndElement(); + } + + private String computeBasicAuthentication() { + String userAuth = authentication.getUser() + ":" + authentication.getPassword(); //$NON-NLS-1$ + byte[] B64Auth = Base64.encodeBase64(userAuth.getBytes()); + + return new String(B64Auth); } private String computeMd5Authentication() { @@ -646,9 +628,7 @@ final class DMBasicSession implements Runnable { reader.next(); - // String test = reader.getLocalName(); jumpToStartTag(reader, "SyncHdr"); //$NON-NLS-1$ - // test = reader.getLocalName(); readSyncHdr(reader); reader.nextTag(); @@ -660,11 +640,8 @@ final class DMBasicSession implements Runnable { } private void readSyncHdr(final XMLStreamReader reader) throws XMLStreamException { - // String test = reader.getLocalName(); jumpToStartTag(reader, "MsgID"); //$NON-NLS-1$ - // test = reader.getLocalName(); - this.currentServerMsgID = reader.getElementText(); jumpToStartTag(reader, "RespURI"); //$NON-NLS-1$ @@ -777,25 +754,17 @@ final class DMBasicSession implements Runnable { } private void readStatus(final XMLStreamReader reader) throws XMLStreamException { - // String test; - // test = reader.getLocalName(); - jumpToStartTag(reader, "CmdRef"); //$NON-NLS-1$ - // test = reader.getLocalName(); - // CmdRef final String cmdRef = reader.getElementText(); - // test = reader.getLocalName(); - reader.nextTag(); // Cmd final String cmd = reader.getElementText(); jumpToStartTag(reader, "Data"); //$NON-NLS-1$ - // jumpToStartTagBefore(reader, "Data", "Status"); final int data = Integer.parseInt(reader.getElementText()); jumpToEndTag(reader, "Status"); //$NON-NLS-1$ @@ -1269,11 +1238,16 @@ final class DMBasicSession implements Runnable { } } - private static void findNode(final XMLStreamReader reader, final String tag) throws XMLStreamException { + private static void jumpToStartTag(final XMLStreamReader reader, final String tag) throws XMLStreamException { + while (true) { if (reader.hasName()) { - if (reader.getLocalName().equals(tag)) { - break; + + if (reader.isStartElement()) { + + if (reader.getLocalName().equals(tag)) { + break; + } } } @@ -1285,22 +1259,25 @@ final class DMBasicSession implements Runnable { } } - private static void jumpToStartTag(final XMLStreamReader reader, final String tag) throws XMLStreamException { - - findNode(reader, tag); + private static void jumpToEndTag(final XMLStreamReader reader, final String tag) throws XMLStreamException { - // while (reader.next() != XMLStreamReader.START_ELEMENT && !reader.getLocalName().equals(tag)) { - // continue; - // } - } + while (true) { + if (reader.hasName()) { - private static void jumpToEndTag(final XMLStreamReader reader, final String tag) throws XMLStreamException { + if (reader.isEndElement()) { - findNode(reader, tag); + if (reader.getLocalName().equals(tag)) { + break; + } + } + } - // while (reader.next() != XMLStreamReader.END_ELEMENT && !reader.getLocalName().equals(tag)) { - // continue; - // } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } } private void fireSessionBegin(final String sessionID) { |

