mirror of https://github.com/apache/jclouds.git
Replace EncryptedPassword with a plain old String
This commit is contained in:
parent
7ea0e8629f
commit
5dbaf0ceb2
|
@ -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<EncryptedPassword> {
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<EncryptedPassword> getEncryptedPasswordForVirtualMachine(@QueryParam("id") long id);
|
||||
ListenableFuture<String> getEncryptedPasswordForVirtualMachine(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#changeServiceForVirtualMachine
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue