1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Bug #847 - #911: Java OCA client does not hash the password, add new driver parameter for one.user.allocate

This commit is contained in:
Carlos Martín 2011-10-17 16:54:56 +02:00
parent 8d356a5841
commit 6b43690216
5 changed files with 27 additions and 72 deletions

View File

@ -22,8 +22,6 @@ import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
@ -112,8 +110,6 @@ public class Client{
msg = ((Integer) result[1]).toString();
}
}
}
catch (XmlRpcException e)
{
@ -134,11 +130,11 @@ public class Client{
private void setOneAuth(String secret) throws ClientConfigurationException
{
String oneSecret = secret;
oneAuth = secret;
try
{
if(oneSecret == null)
if(oneAuth == null)
{
String oneAuthEnv = System.getenv("ONE_AUTH");
File authFile;
@ -152,44 +148,11 @@ public class Client{
authFile = new File(System.getenv("HOME")+"/.one/one_auth");
}
oneSecret =
oneAuth =
(new BufferedReader(new FileReader(authFile))).readLine();
}
String[] token = oneSecret.split(":");
if ( token.length > 2 )
{
oneAuth = oneSecret;
}
else if ( token.length == 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");
}
oneAuth = oneAuth.trim();
}
catch (FileNotFoundException e)
{
@ -202,13 +165,6 @@ public class Client{
// read it
throw new ClientConfigurationException("ONE_AUTH file unreadable");
}
catch (NoSuchAlgorithmException e)
{
// A client application cannot recover if the SHA-1 digest
// algorithm cannot be initialized
throw new RuntimeException(
"Error initializing MessageDigest with SHA-1", e);
}
}
private void setOneEndPoint(String endpoint)

View File

@ -71,7 +71,25 @@ public class User extends PoolElement{
String username,
String password)
{
return client.call(ALLOCATE, username, password);
return allocate(client, username, password, "");
}
/**
* Allocates a new user in OpenNebula.
*
* @param client XML-RPC Client.
* @param username Username for the new user.
* @param password Password for the new user
* @param auth Auth driver for the new user.
* @return If successful the message contains
* the associated id (int uid) generated for this user.
*/
public static OneResponse allocate(Client client,
String username,
String password,
String auth)
{
return client.call(ALLOCATE, username, password, auth);
}
/** Retrieves the information of the given user.

View File

@ -37,25 +37,6 @@ public class SessionTest {
assertNotNull(oneClient);
}
@Test
public void wrong_token()
{
Client oneClient = null;
try
{
// The secret string should be user:password. The url is null, so it
// will be set to default.
oneClient = new Client("wrong_password_token",null);
}
catch (Exception e)
{
// System.out.println(e.getMessage());
}
assertNull("Client should complain about the wrong token", oneClient);
}
@Test
public void wrong_url()
{

View File

@ -63,8 +63,10 @@ public class UserTest
{
res = User.allocate(client, name, password);
int uid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
user = new User(uid, client);
assertTrue( res.getErrorMessage(), !res.isError() );
int uid = Integer.parseInt(res.getMessage());
user = new User(uid, client);
}
/**

View File

@ -136,8 +136,6 @@ public class VirtualNetworkTest
// assertTrue( vnet.xpath("ID").equals("0") );
assertTrue( vnet.xpath("NAME").equals(name) );
assertTrue( vnet.xpath("BRIDGE").equals("vbr0") );
assertTrue( vnet.xpath("TEMPLATE/NETWORK_ADDRESS").equals("192.168.0.0") );
assertTrue( vnet.xpath("TEMPLATE/TYPE").equals("RANGED") );
}
@Test