diff --git a/src/oca/java/src/org/opennebula/client/Client.java b/src/oca/java/src/org/opennebula/client/Client.java index b5386efc19..e7ebb221d9 100644 --- a/src/oca/java/src/org/opennebula/client/Client.java +++ b/src/oca/java/src/org/opennebula/client/Client.java @@ -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) diff --git a/src/oca/java/src/org/opennebula/client/user/User.java b/src/oca/java/src/org/opennebula/client/user/User.java index 1f31f589b8..f2969cfeec 100644 --- a/src/oca/java/src/org/opennebula/client/user/User.java +++ b/src/oca/java/src/org/opennebula/client/user/User.java @@ -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. diff --git a/src/oca/java/test/SessionTest.java b/src/oca/java/test/SessionTest.java index 7d313712c9..9729979157 100644 --- a/src/oca/java/test/SessionTest.java +++ b/src/oca/java/test/SessionTest.java @@ -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() { diff --git a/src/oca/java/test/UserTest.java b/src/oca/java/test/UserTest.java index 4d4f30d96b..eb39adc8e2 100644 --- a/src/oca/java/test/UserTest.java +++ b/src/oca/java/test/UserTest.java @@ -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); } /** diff --git a/src/oca/java/test/VirtualNetworkTest.java b/src/oca/java/test/VirtualNetworkTest.java index 97639137b1..8d97ad1ead 100644 --- a/src/oca/java/test/VirtualNetworkTest.java +++ b/src/oca/java/test/VirtualNetworkTest.java @@ -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