1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Bug #839: Add support in java oca for auth tokens with protocol

(cherry picked from commit 9ee34a8b87)
This commit is contained in:
Carlos Martín 2011-09-28 12:35:12 +02:00
parent 69933ac673
commit 16f173fd44

View File

@ -158,31 +158,38 @@ public class Client{
String[] token = oneSecret.split(":");
if(token.length != 2 )
if ( token.length > 2 )
{
oneAuth = oneSecret;
}
else if ( token.lenght == 2 )
{
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] digest = md.digest(token[1].getBytes());
String hash = "";
for(byte aux : digest)
{
int b = aux & 0xff;
if (Integer.toHexString(b).length() == 1)
{
hash += "0";
}
hash += Integer.toHexString(b);
}
oneAuth = token[0] + ":" + hash;
}
else
{
throw new ClientConfigurationException(
"Wrong format for authorization string: "
+ oneSecret + "\nFormat expected is user:password");
}
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] digest = md.digest(token[1].getBytes());
String hash = "";
for(byte aux : digest)
{
int b = aux & 0xff;
if (Integer.toHexString(b).length() == 1)
{
hash += "0";
}
hash += Integer.toHexString(b);
}
oneAuth = token[0] + ":" + hash;
}
catch (FileNotFoundException e)
{