use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificateAuthorityService method findActiveVersion.
public CertificateCredentialValue findActiveVersion(String caName) {
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), caName, PermissionOperation.READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
CredentialVersion mostRecent = certificateVersionDataService.findActive(caName);
if (mostRecent == null) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
if (!(mostRecent instanceof CertificateCredentialVersion)) {
throw new ParameterizedValidationException("error.not_a_ca_name");
}
CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) mostRecent;
if (!certificateCredential.getParsedCertificate().isCa()) {
throw new ParameterizedValidationException("error.cert_not_ca");
}
return new CertificateCredentialValue(null, certificateCredential.getCertificate(), certificateCredential.getPrivateKey(), null, certificateCredential.isVersionTransitional());
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificateVersionDataService method findActiveWithTransitional.
public List<CredentialVersion> findActiveWithTransitional(String certificateName) {
ArrayList<CredentialVersion> result = new ArrayList<>();
Credential credential = credentialDataService.find(certificateName);
UUID uuid = credential.getUuid();
if (credential == null) {
return null;
} else {
CredentialVersionData active = credentialVersionRepository.findLatestNonTransitionalCertificateVersion(uuid);
if (active != null) {
result.add(credentialFactory.makeCredentialFromEntity(active));
}
CredentialVersionData transitional = credentialVersionRepository.findTransitionalCertificateVersion(uuid);
if (transitional != null) {
result.add(credentialFactory.makeCredentialFromEntity(transitional));
}
return result;
}
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method getVersions_returnsListWithVersions.
@Test
public void getVersions_returnsListWithVersions() throws Exception {
CredentialVersion myCredential = mock(CredentialVersion.class);
when(myCredential.getName()).thenReturn("my-credential");
CredentialVersion secondVersion = mock(CredentialVersion.class);
when(secondVersion.getName()).thenReturn("my-credential");
List<CredentialVersion> versions = newArrayList(myCredential, secondVersion);
UserContext userContext = mock(UserContext.class);
when(userContextHolder.getUserContext()).thenReturn(userContext);
String user = "my-user";
when(userContext.getActor()).thenReturn(user);
when(permissionCheckingService.hasPermission(user, "my-credential", PermissionOperation.READ)).thenReturn(true);
uuid = UUID.randomUUID();
when(certificateVersionDataService.findAllVersions(uuid)).thenReturn(versions);
final List<CredentialVersion> certificates = subject.getVersions(uuid, false, newArrayList());
assertThat(certificates, equalTo(versions));
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateServiceTest method getVersions_returnsAnError_whenUserDoesntHavePermission.
@Test(expected = EntryNotFoundException.class)
public void getVersions_returnsAnError_whenUserDoesntHavePermission() throws Exception {
CredentialVersion myCredential = mock(CredentialVersion.class);
when(myCredential.getName()).thenReturn("my-credential");
CredentialVersion secondVersion = mock(CredentialVersion.class);
when(secondVersion.getName()).thenReturn("my-credential");
List<CredentialVersion> versions = newArrayList(myCredential, secondVersion);
UserContext userContext = mock(UserContext.class);
when(userContextHolder.getUserContext()).thenReturn(userContext);
String user = "my-user";
when(userContext.getActor()).thenReturn(user);
when(permissionCheckingService.hasPermission(user, "my-credential", PermissionOperation.READ)).thenReturn(false);
when(certificateVersionDataService.findAllVersions(uuid)).thenReturn(versions);
subject.getVersions(uuid, false, newArrayList());
}
use of org.cloudfoundry.credhub.domain.CredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCredentialServiceTest method getCredentialVersion_whenTheVersionExists_setsCorrectAuditingParametersAndReturnsTheCredential.
@Test
public void getCredentialVersion_whenTheVersionExists_setsCorrectAuditingParametersAndReturnsTheCredential() {
final CredentialVersion credentialVersionFound = subject.findVersionByUuid(VERSION_UUID_STRING, auditRecordParameters);
assertThat(credentialVersionFound, equalTo(existingCredentialVersion));
assertThat(auditRecordParameters, hasSize(1));
assertThat(auditRecordParameters.get(0).getCredentialName(), equalTo(CREDENTIAL_NAME));
assertThat(auditRecordParameters.get(0).getAuditingOperationCode(), equalTo(CREDENTIAL_ACCESS));
}
Aggregations