use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataService method findActiveByName.
public List<CredentialVersion> findActiveByName(String name) {
Credential credential = credentialDataService.find(name);
CredentialVersionData credentialVersionData;
ArrayList<CredentialVersion> result = newArrayList();
if (credential != null) {
credentialVersionData = credentialVersionRepository.findFirstByCredentialUuidOrderByVersionCreatedAtDesc(credential.getUuid());
if (credentialVersionData.getCredentialType().equals(CertificateCredentialVersionData.CREDENTIAL_TYPE)) {
return certificateVersionDataService.findActiveWithTransitional(name);
}
result.add(credentialFactory.makeCredentialFromEntity(credentialVersionData));
return result;
} else {
return newArrayList();
}
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive.
@Test
public void delete_givenACredentialNameCasedDifferentlyFromTheActual_shouldBeCaseInsensitive() {
Credential credentialName = credentialDataService.save(new Credential("/my-credential"));
PasswordCredentialVersionData credential = new PasswordCredentialVersionData();
credential.setCredential(credentialName);
credential.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("credential-password".getBytes()).setNonce(new byte[] {}));
subject.save(credential);
credential = new PasswordCredentialVersionData();
credential.setCredential(credentialName);
credential.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(activeCanaryUuid).setEncryptedValue("another password".getBytes()).setNonce(new byte[] {}));
subject.save(credential);
assertThat(subject.findAllByName("/my-credential"), hasSize(2));
subject.delete("/MY-CREDENTIAL");
assertThat(subject.findAllByName("/my-credential"), empty());
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method delete_onAnExistingCredential_returnsTrue.
@Test
public void delete_onAnExistingCredential_returnsTrue() {
credentialDataService.save(new Credential("/my-credential"));
assertThat(subject.delete("/my-credential"), equalTo(true));
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method savePassword.
private PasswordCredentialVersion savePassword(long timeMillis, String name, UUID canaryUuid) {
fakeTimeSetter.accept(timeMillis);
Credential credential = credentialDataService.find(name);
if (credential == null) {
credential = credentialDataService.save(new Credential(name));
}
PasswordCredentialVersionData credentialObject = new PasswordCredentialVersionData();
credentialObject.setCredential(credential);
credentialObject.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(canaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
return subject.save(credentialObject);
}
use of org.cloudfoundry.credhub.entity.Credential in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method saveCertificate.
private CertificateCredentialVersion saveCertificate(long timeMillis, String name, String caName, UUID canaryUuid, boolean transitional) {
fakeTimeSetter.accept(timeMillis);
Credential credential = credentialDataService.find(name);
if (credential == null) {
credential = credentialDataService.save(new Credential(name));
}
CertificateCredentialVersionData credentialObject = new CertificateCredentialVersionData();
credentialObject.setCredential(credential);
credentialObject.setEncryptedValueData(new EncryptedValue().setEncryptionKeyUuid(canaryUuid).setEncryptedValue(new byte[] {}).setNonce(new byte[] {}));
if (caName != null) {
credentialObject.setCaName(caName);
}
credentialObject.setTransitional(transitional);
return subject.save(credentialObject);
}
Aggregations