From 5dbaf0ceb22a6bb8fb9735e098ebac8e4f97c3c0 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Thu, 9 Feb 2012 17:44:12 +0200 Subject: [PATCH] Replace EncryptedPassword with a plain old String --- .../cloudstack/domain/EncryptedPassword.java | 73 ------------------- .../EncryptedPasswordAndPrivateKey.java | 27 ------- .../features/VirtualMachineAsyncClient.java | 5 +- .../features/VirtualMachineClient.java | 3 +- .../compute/CloudStackExperimentLiveTest.java | 9 +-- .../VirtualMachineClientExpectTest.java | 11 ++- 6 files changed, 12 insertions(+), 116 deletions(-) delete mode 100644 apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPassword.java diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPassword.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPassword.java deleted file mode 100644 index 8d9e43214c..0000000000 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPassword.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.cloudstack.domain; - -import com.google.gson.annotations.SerializedName; - -/** - * @author Andrei Savu - */ -public class EncryptedPassword implements Comparable { - - @SerializedName("encryptedpassword") - private String encryptedPassword; - - public EncryptedPassword(String encryptedPassword) { - this.encryptedPassword = encryptedPassword; - } - - EncryptedPassword() { /* for serializer */ } - - /** - * @return the string representation of the encrypted password - */ - public String getEncryptedPassword() { - return encryptedPassword; - } - - @Override - public int hashCode() { - return encryptedPassword.hashCode(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - EncryptedPassword that = (EncryptedPassword) o; - - if (encryptedPassword != null ? !encryptedPassword.equals(that.encryptedPassword) : that.encryptedPassword != null) - return false; - - return true; - } - - @Override - public String toString() { - return "EncryptedPassword{" + - "encryptedPassword='" + encryptedPassword + '\'' + - '}'; - } - - @Override - public int compareTo(EncryptedPassword arg0) { - return encryptedPassword.compareTo(arg0.getEncryptedPassword()); - } -} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java index 51b3a116af..40ecd2a476 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/EncryptedPasswordAndPrivateKey.java @@ -23,33 +23,6 @@ package org.jclouds.cloudstack.domain; */ public class EncryptedPasswordAndPrivateKey { - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String encryptedPassword; - private String privateKey; - - public Builder encryptedPassword(String encryptedPassword) { - this.encryptedPassword = encryptedPassword; - return this; - } - - public Builder encryptedPassword(EncryptedPassword password) { - return encryptedPassword(password.getEncryptedPassword()); - } - - public Builder privateKey(String privateKey) { - this.privateKey = privateKey; - return this; - } - - public EncryptedPasswordAndPrivateKey build() { - return new EncryptedPasswordAndPrivateKey(encryptedPassword, privateKey); - } - } - private final String encryptedPassword; private final String privateKey; diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java index 4809178b53..d44b694dd9 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java @@ -20,7 +20,6 @@ package org.jclouds.cloudstack.features; import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.cloudstack.domain.AsyncCreateResponse; -import org.jclouds.cloudstack.domain.EncryptedPassword; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.filters.AuthenticationFilter; import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; @@ -125,9 +124,9 @@ public interface VirtualMachineAsyncClient { */ @GET @QueryParams(keys = "command", values = "getVMPassword") - @SelectJson("password") + @SelectJson("encryptedpassword") @Consumes(MediaType.APPLICATION_JSON) - ListenableFuture getEncryptedPasswordForVirtualMachine(@QueryParam("id") long id); + ListenableFuture getEncryptedPasswordForVirtualMachine(@QueryParam("id") long id); /** * @see VirtualMachineClient#changeServiceForVirtualMachine diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java index e460ad593d..3414ee062b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java @@ -19,7 +19,6 @@ package org.jclouds.cloudstack.features; import org.jclouds.cloudstack.domain.AsyncCreateResponse; -import org.jclouds.cloudstack.domain.EncryptedPassword; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; @@ -120,7 +119,7 @@ public interface VirtualMachineClient { * the ID of the virtual machine * @return encrypted password */ - EncryptedPassword getEncryptedPasswordForVirtualMachine(long id); + String getEncryptedPasswordForVirtualMachine(long id); /** * Changes the service offering for a virtual machine. The virtual machine diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java index 641b1259c3..923fb916b2 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackExperimentLiveTest.java @@ -19,7 +19,6 @@ package org.jclouds.cloudstack.compute; import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions; -import org.jclouds.cloudstack.domain.EncryptedPassword; import org.jclouds.cloudstack.domain.EncryptedPasswordAndPrivateKey; import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.SshKeyPair; @@ -154,15 +153,15 @@ public class CloudStackExperimentLiveTest extends BaseCloudStackClientLiveTest { node = getOnlyElement(computeContext.getComputeService() .createNodesInGroup(group, 1, template)); - EncryptedPassword password = client.getVirtualMachineClient() + String encryptedPassword = client.getVirtualMachineClient() .getEncryptedPasswordForVirtualMachine(Long.parseLong(node.getId())); Crypto crypto = new BouncyCastleCrypto(); WindowsLoginCredentialsFromEncryptedData passwordDecrypt = new WindowsLoginCredentialsFromEncryptedData(crypto); - assertEquals(passwordDecrypt.apply(EncryptedPasswordAndPrivateKey.builder() - .encryptedPassword(password).privateKey(keyPair.getPrivateKey()).build()) - .getPassword(), "bX7vvptvw"); + assertEquals(passwordDecrypt.apply( + new EncryptedPasswordAndPrivateKey(encryptedPassword, keyPair.getPrivateKey())).getPassword(), + "bX7vvptvw"); } finally { if (node != null) { diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java index cb25ff5787..495a6eb4a8 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientExpectTest.java @@ -20,7 +20,6 @@ package org.jclouds.cloudstack.features; import com.google.common.collect.ImmutableMultimap; import org.jclouds.cloudstack.CloudStackContext; -import org.jclouds.cloudstack.domain.EncryptedPassword; import org.jclouds.cloudstack.domain.EncryptedPasswordAndPrivateKey; import org.jclouds.cloudstack.functions.WindowsLoginCredentialsFromEncryptedData; import org.jclouds.crypto.Crypto; @@ -76,18 +75,18 @@ public class VirtualMachineClientExpectTest extends BaseCloudStackRestClientExpe .payload(payloadFromResource("/getvmpasswordresponse.json")) .build()); - EncryptedPassword actual = client.getEncryptedPasswordForVirtualMachine(1L); - EncryptedPassword expected = new EncryptedPassword("EFOwm8icZ4sEib4y6ntVHUKHZJQrGBdyPkL1L9lpFHYhs3JfAtL5E5bxBP5Er27bJyOZPjKFcInX\r\n" + + String actual = client.getEncryptedPasswordForVirtualMachine(1L); + String expected = "EFOwm8icZ4sEib4y6ntVHUKHZJQrGBdyPkL1L9lpFHYhs3JfAtL5E5bxBP5Er27bJyOZPjKFcInX\r\n" + "pQ0LZlQBZDd5/ac0NSoM6tAX3H30pYxNw4t2f9u8aJ48oOEvufgGxTTHnM9qHXD04lt+Ouql6i2q\r\n" + - "HxBqCxFkMZEla3LFieE=\r\n"); + "HxBqCxFkMZEla3LFieE=\r\n"; assertEquals(actual, expected); Crypto crypto = new BouncyCastleCrypto(); WindowsLoginCredentialsFromEncryptedData passwordDecrypt = new WindowsLoginCredentialsFromEncryptedData(crypto); - assertEquals(passwordDecrypt.apply(EncryptedPasswordAndPrivateKey.builder() - .encryptedPassword(actual).privateKey(privateKey).build()).getPassword(), "bX7vvptvw"); + assertEquals(passwordDecrypt.apply( + new EncryptedPasswordAndPrivateKey(actual, privateKey)).getPassword(), "bX7vvptvw"); } @Override