fixed up the static sid to byte and string methods a bit, switched away from byte buffer since it was unneeded
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/sandbox/trunk@2181 7e9141cc-0065-0410-87d8-b60c137991c4
diff --git a/jetty-spnego/src/main/java/org/eclipse/jetty/spengo/LdapIdentityService.java b/jetty-spnego/src/main/java/org/eclipse/jetty/spengo/LdapIdentityService.java
index 2dc76e0..80e4b75 100644
--- a/jetty-spnego/src/main/java/org/eclipse/jetty/spengo/LdapIdentityService.java
+++ b/jetty-spnego/src/main/java/org/eclipse/jetty/spengo/LdapIdentityService.java
@@ -348,6 +348,7 @@
return b;
}
+
/**
* Converts a binary SID to a string SID
*
@@ -372,6 +373,7 @@
{
tmpBuilder.append(Integer.toHexString(sidBytes[i] & 0xFF));
}
+
sidString.append(Long.parseLong(tmpBuilder.toString(), 16)); // '-' is in the subauth loop
// the number of subAuthorities we need to attach
@@ -400,13 +402,14 @@
int subAuthorityCount = sidTokens.length - 3; // S-Rev-IdAuth-
- ByteBuffer sidByteBuffer = ByteBuffer.allocateDirect(1 + 1 + 6 + (4 * subAuthorityCount));
+ int byteCount = 0;
+ byte[] sidBytes = new byte[1 + 1 + 6 + (4 * subAuthorityCount)];
// the revision byte
- sidByteBuffer.put((byte)Integer.parseInt(sidTokens[1]));
+ sidBytes[byteCount++] = (byte)Integer.parseInt(sidTokens[1]);
// the # of sub authorities byte
- sidByteBuffer.put((byte)subAuthorityCount);
+ sidBytes[byteCount++] = (byte)subAuthorityCount;
// the certAuthority
String hexStr = Long.toHexString(Long.parseLong(sidTokens[2]));
@@ -415,12 +418,14 @@
{
hexStr = "0" + hexStr;
}
-
+
+ // place the certAuthority 6 bytes
for ( int i = 0 ; i < hexStr.length(); i = i + 2)
{
- sidByteBuffer.put((byte)Integer.parseInt(hexStr.substring(0 + i, 2 + i),16));
+ sidBytes[byteCount++] = (byte)Integer.parseInt(hexStr.substring(i, i + 2),16);
}
+
for ( int i = 3; i <=7 ; ++i)
{
hexStr = Long.toHexString(Long.parseLong(sidTokens[i]));
@@ -430,16 +435,13 @@
hexStr = "0" + hexStr;
}
+ // place the inverted sub authorities, 4 bytes each
for ( int j = hexStr.length(); j > 0; j = j - 2)
{
- sidByteBuffer.put((byte)Integer.parseInt(hexStr.substring(0 + i, 2 + i),16));
+ sidBytes[byteCount++] = (byte)Integer.parseInt(hexStr.substring(j-2, j),16);
}
}
-
- byte[] sidBytes = new byte[sidByteBuffer.capacity()];
- sidByteBuffer.position(0);
- sidByteBuffer.get(sidBytes,0, sidBytes.length);
-
+
return sidBytes;
}
diff --git a/jetty-spnego/src/test/java/org/eclipse/jetty/spnego/LdapIdentityServiceTest.java b/jetty-spnego/src/test/java/org/eclipse/jetty/spnego/LdapIdentityServiceTest.java
index 8409f3e..9cd6bb9 100644
--- a/jetty-spnego/src/test/java/org/eclipse/jetty/spnego/LdapIdentityServiceTest.java
+++ b/jetty-spnego/src/test/java/org/eclipse/jetty/spnego/LdapIdentityServiceTest.java
@@ -1,5 +1,7 @@
package org.eclipse.jetty.spnego;
+import java.util.Arrays;
+
import junit.framework.Assert;
import org.eclipse.jetty.spengo.LdapIdentityService;
@@ -16,8 +18,9 @@
String sid = "S-1-5-21-3623811015-3361044348-30300820-1013";
byte[] sidBytes = LdapIdentityService.sidStringToBytes(sid);
-
+
Assert.assertEquals(sid, LdapIdentityService.sidBytesToString(sidBytes));
+
}
}
\ No newline at end of file