|
37 | 37 | import javax.inject.Inject; |
38 | 38 | import javax.naming.ConfigurationException; |
39 | 39 |
|
40 | | -import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd; |
41 | | -import org.apache.commons.codec.binary.Base64; |
42 | | -import org.apache.log4j.Logger; |
43 | 40 | import org.apache.cloudstack.acl.ControlledEntity; |
44 | 41 | import org.apache.cloudstack.affinity.AffinityGroupProcessor; |
45 | 42 | import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; |
|
408 | 405 | import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd; |
409 | 406 | import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd; |
410 | 407 | import org.apache.cloudstack.api.command.user.snapshot.RevertSnapshotCmd; |
| 408 | +import org.apache.cloudstack.api.command.user.snapshot.UpdateSnapshotPolicyCmd; |
411 | 409 | import org.apache.cloudstack.api.command.user.ssh.CreateSSHKeyPairCmd; |
412 | 410 | import org.apache.cloudstack.api.command.user.ssh.DeleteSSHKeyPairCmd; |
413 | 411 | import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd; |
|
511 | 509 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
512 | 510 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
513 | 511 | import org.apache.cloudstack.utils.identity.ManagementServerNode; |
| 512 | +import org.apache.commons.codec.binary.Base64; |
| 513 | +import org.apache.log4j.Logger; |
514 | 514 |
|
515 | 515 | import com.cloud.agent.AgentManager; |
516 | 516 | import com.cloud.agent.api.GetVncPortAnswer; |
@@ -3616,9 +3616,14 @@ public SSHKeyPair registerSSHKeyPair(RegisterSSHKeyPairCmd cmd) { |
3616 | 3616 |
|
3617 | 3617 | Account owner = _accountMgr.finalizeOwner(caller, cmd.getAccountName(), cmd.getDomainId(), cmd.getProjectId()); |
3618 | 3618 |
|
3619 | | - SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName()); |
3620 | | - if (s != null) { |
3621 | | - throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists."); |
| 3619 | + SSHKeyPairVO existingPair = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName()); |
| 3620 | + if (existingPair != null) { |
| 3621 | + throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists for this account."); |
| 3622 | + } |
| 3623 | + |
| 3624 | + existingPair = _sshKeyPairDao.findByPublicKey(owner.getAccountId(), owner.getDomainId(), cmd.getPublicKey()); |
| 3625 | + if (existingPair != null) { |
| 3626 | + throw new InvalidParameterValueException("A key pair with name '" + cmd.getPublicKey() + "' already exists for this account."); |
3622 | 3627 | } |
3623 | 3628 |
|
3624 | 3629 | String name = cmd.getName(); |
|
0 commit comments