From 6fb7aa27f2ff0290ce0b1ba32008c11f33279422 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 20 Dec 2012 09:15:39 -0800 Subject: [PATCH] cloudstack doesn't need a strict bouncycastle dep --- .../EncryptedPasswordAndPrivateKey.java | 45 ++++-------- ...dowsLoginCredentialsFromEncryptedData.java | 22 +++++- .../compute/CloudStackExperimentLiveTest.java | 53 +------------- .../VirtualMachineClientExpectTest.java | 6 +- ...LoginCredentialsFromEncryptedDataTest.java | 73 +++++++++++++++++++ 5 files changed, 111 insertions(+), 88 deletions(-) create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedDataTest.java 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 b1f9a76d6b..31c2a5b2d7 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,25 +23,22 @@ import java.beans.ConstructorProperties; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; /** - * Class EncryptedPasswordAndPrivateKey * * @author Andrei Savu */ -public class EncryptedPasswordAndPrivateKey { +public final class EncryptedPasswordAndPrivateKey { - public static Builder builder() { - return new ConcreteBuilder(); + public static Builder builder() { + return new Builder(); } - public Builder toBuilder() { - return new ConcreteBuilder().fromEncryptedPasswordAndPrivateKey(this); + public Builder toBuilder() { + return builder().fromEncryptedPasswordAndPrivateKey(this); } - public static abstract class Builder> { - protected abstract T self(); + public final static class Builder { protected String encryptedPassword; protected String privateKey; @@ -49,44 +46,36 @@ public class EncryptedPasswordAndPrivateKey { /** * @see EncryptedPasswordAndPrivateKey#getEncryptedPassword() */ - public T encryptedPassword(String encryptedPassword) { + public Builder encryptedPassword(String encryptedPassword) { this.encryptedPassword = encryptedPassword; - return self(); + return this; } /** * @see EncryptedPasswordAndPrivateKey#getPrivateKey() */ - public T privateKey(String privateKey) { + public Builder privateKey(String privateKey) { this.privateKey = privateKey; - return self(); + return this; } public EncryptedPasswordAndPrivateKey build() { return new EncryptedPasswordAndPrivateKey(encryptedPassword, privateKey); } - public T fromEncryptedPasswordAndPrivateKey(EncryptedPasswordAndPrivateKey in) { - return this - .encryptedPassword(in.getEncryptedPassword()) + public Builder fromEncryptedPasswordAndPrivateKey(EncryptedPasswordAndPrivateKey in) { + return encryptedPassword(in.getEncryptedPassword()) .privateKey(in.getPrivateKey()); } } - private static class ConcreteBuilder extends Builder { - @Override - protected ConcreteBuilder self() { - return this; - } - } - private final String encryptedPassword; private final String privateKey; @ConstructorProperties({ "encryptedPassword", "privateKey" }) - protected EncryptedPasswordAndPrivateKey(@Nullable String encryptedPassword, @Nullable String privateKey) { + public EncryptedPasswordAndPrivateKey(@Nullable String encryptedPassword, @Nullable String privateKey) { this.encryptedPassword = encryptedPassword; this.privateKey = privateKey; } @@ -121,14 +110,10 @@ public class EncryptedPasswordAndPrivateKey { && Objects.equal(this.privateKey, that.privateKey); } - protected ToStringHelper string() { - return Objects.toStringHelper(this) - .add("encryptedPassword", encryptedPassword).add("privateKey", privateKey); - } - @Override public String toString() { - return string().toString(); + return Objects.toStringHelper(this).omitNullValues() + .add("encryptedPassword", encryptedPassword).add("privateKey", privateKey).toString(); } } diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java index 732a74c507..0a2f0386a7 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/functions/WindowsLoginCredentialsFromEncryptedData.java @@ -1,3 +1,21 @@ +/** + * 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.functions; import java.nio.charset.Charset; @@ -44,7 +62,7 @@ public class WindowsLoginCredentialsFromEncryptedData implements Function sshKey = SshKeys.generate(); - // final String publicKey = sshKey.get("public"); - - String keyPairName = prefix + "-windows-keypair"; - client.getSSHKeyPairClient().deleteSSHKeyPair(keyPairName); - // client.getSSHKeyPairClient().registerSSHKeyPair(keyPairName, publicKey); - - SshKeyPair keyPair = client.getSSHKeyPairClient().createSSHKeyPair(keyPairName); - - String group = prefix + "-windows-test"; - Template template = view.getComputeService().templateBuilder() - .imageId("290").locationId("1") - .options(new CloudStackTemplateOptions().setupStaticNat(false).keyPair(keyPairName)) - .build(); - - NodeMetadata node = null; - try { - node = getOnlyElement(view.getComputeService() - .createNodesInGroup(group, 1, template)); - - String encryptedPassword = client.getVirtualMachineClient() - .getEncryptedPasswordForVirtualMachine(node.getId()); - - Crypto crypto = new BouncyCastleCrypto(); - WindowsLoginCredentialsFromEncryptedData passwordDecrypt = new WindowsLoginCredentialsFromEncryptedData(crypto); - - assertEquals(passwordDecrypt.apply( - EncryptedPasswordAndPrivateKey.builder().encryptedPassword(encryptedPassword).privateKey(keyPair.getPrivateKey()).build()) - .getPassword(), "bX7vvptvw"); - - } finally { - if (node != null) { - view.getComputeService().destroyNode(node.getId()); - } - - } - - } - -} \ No newline at end of file +} 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 e40772083e..b029d8a656 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 @@ -28,8 +28,7 @@ import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.domain.EncryptedPasswordAndPrivateKey; import org.jclouds.cloudstack.functions.WindowsLoginCredentialsFromEncryptedData; import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest; -import org.jclouds.crypto.Crypto; -import org.jclouds.encryption.bouncycastle.BouncyCastleCrypto; +import org.jclouds.encryption.internal.JCECrypto; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.testng.annotations.Test; @@ -79,8 +78,7 @@ public class VirtualMachineClientExpectTest extends BaseCloudStackExpectTest