use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findNByName_whenAskedForTooManyVersions_returnsAllVersions.
@Test
public void findNByName_whenAskedForTooManyVersions_returnsAllVersions() {
PasswordCredentialVersion credential1 = savePassword(2000000000123L, "/secret1");
List<CredentialVersion> credentialVersions = subject.findNByName("/Secret1", 2);
assertThat(credentialVersions.size(), equalTo(1));
assertThat(credentialVersions.get(0).getUuid(), equalTo(credential1.getUuid()));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method save_givenANewCredential_savesTheCredential.
@Test
public void save_givenANewCredential_savesTheCredential() {
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData("/my-credential");
passwordCredentialData.setEncryptedValueData(new EncryptedValue(activeCanaryUuid, "credential-password", ""));
PasswordCredentialVersion credential = new PasswordCredentialVersion(passwordCredentialData);
credential.setEncryptor(encryptor);
CredentialVersion savedCredentialVersion = subject.save(credential);
assertNotNull(savedCredentialVersion);
PasswordCredentialVersion savedPasswordCredential = (PasswordCredentialVersion) subject.findMostRecent("/my-credential");
CredentialVersionData credentialVersionData = credentialVersionRepository.findOneByUuid(savedCredentialVersion.getUuid());
assertThat(savedPasswordCredential.getName(), equalTo(credential.getName()));
assertThat(savedPasswordCredential.getUuid(), equalTo(credential.getUuid()));
assertThat(credentialVersionData.getCredential().getName(), equalTo("/my-credential"));
assertThat(credentialVersionData.getEncryptedValueData().getEncryptedValue(), equalTo("credential-password".getBytes()));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificateVersionDataServiceTest method findActive_FindsMostRecentNonTransitionalCredentialVersion.
@Test
public void findActive_FindsMostRecentNonTransitionalCredentialVersion() throws Exception {
Credential certificate = mock(Credential.class);
when(dataService.find("/some-ca-name")).thenReturn(certificate);
CredentialVersionData certificateEntity = mock(CredentialVersionData.class);
when(versionRepository.findLatestNonTransitionalCertificateVersion(any())).thenReturn(certificateEntity);
CredentialVersion expectedVersion = mock(CredentialVersion.class);
when(factory.makeCredentialFromEntity(certificateEntity)).thenReturn(expectedVersion);
CredentialVersion activeVersion = subject.findActive("/some-ca-name");
assertThat(activeVersion, equalTo(expectedVersion));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method getVersions.
public List<CredentialVersion> getVersions(UUID uuid, boolean current, List<EventAuditRecordParameters> auditRecordParameters) {
List<CredentialVersion> list;
String name;
try {
if (current) {
Credential credential = findCertificateCredential(uuid);
name = credential.getName();
list = certificateVersionDataService.findActiveWithTransitional(name);
} else {
list = certificateVersionDataService.findAllVersions(uuid);
name = !list.isEmpty() ? list.get(0).getName() : null;
}
} catch (IllegalArgumentException e) {
auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, null));
throw new InvalidQueryParameterException("error.bad_request", "uuid");
}
auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, name));
if (list.isEmpty() || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), name, PermissionOperation.READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return list;
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificateService method findByCredentialUuid.
public CertificateCredentialVersion findByCredentialUuid(String uuid, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
auditRecordParameters.add(eventAuditRecordParameters);
CredentialVersion credentialVersion = this.certificateVersionDataService.findByCredentialUUID(uuid);
if (credentialVersion == null || !(credentialVersion instanceof CertificateCredentialVersion)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
eventAuditRecordParameters.setCredentialName(credentialVersion.getName());
CertificateCredentialVersion certificate = (CertificateCredentialVersion) credentialVersion;
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return certificate;
}
Aggregations