use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleUpdateTransitionalVersion.
public List<CertificateView> handleUpdateTransitionalVersion(String certificateId, UpdateTransitionalVersionRequest requestBody, List<EventAuditRecordParameters> auditRecordParameters) {
List<CredentialVersion> credentialList;
UUID versionUUID = null;
if (requestBody.getVersionUuid() != null) {
versionUUID = UUID.fromString(requestBody.getVersionUuid());
}
credentialList = permissionedCertificateService.updateTransitionalVersion(UUID.fromString(certificateId), versionUUID, auditRecordParameters);
List<CertificateView> list = credentialList.stream().map(credential -> new CertificateView((CertificateCredentialVersion) credential)).collect(Collectors.toList());
return list;
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findAllCertificateCredentialsByCaName_isCaseInsensitive.
@Test
public void findAllCertificateCredentialsByCaName_isCaseInsensitive() {
CertificateCredentialVersion caCert = saveCertificate(2000000000123L, "/ca-cert");
CertificateCredentialVersion cert1 = saveCertificateByCa(2000000000125L, "/cert1", "/ca-cert");
CertificateCredentialVersion cert2 = saveCertificateByCa(2000000000126L, "/cert2", "/ca-cert");
List<String> certificates = subject.findAllCertificateCredentialsByCaName("/ca-CERT");
assertThat(certificates, containsInAnyOrder(equalTo("/cert1"), equalTo("/cert2")));
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CredentialVersionDataServiceTest method findAllPaths_returnsCompleteDirectoryStructure.
@Test
public void findAllPaths_returnsCompleteDirectoryStructure() {
String valueOther = "/fubario";
String valueName = "/value/Credential";
String passwordName = "/password/Credential";
String certificateName = "/certif/ic/ateCredential";
ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(valueOther);
ValueCredentialVersion valueCredential = new ValueCredentialVersion(valueCredentialData);
subject.save(valueCredential);
valueCredentialData = new ValueCredentialVersionData(valueName);
valueCredential = new ValueCredentialVersion(valueCredentialData);
subject.save(valueCredential);
PasswordCredentialVersionData passwordCredentialData = new PasswordCredentialVersionData(passwordName);
PasswordCredentialVersion passwordCredential = new PasswordCredentialVersion(passwordCredentialData);
subject.save(passwordCredential);
CertificateCredentialVersionData certificateCredentialData = new CertificateCredentialVersionData(certificateName);
CertificateCredentialVersion certificateCredential = new CertificateCredentialVersion(certificateCredentialData);
subject.save(certificateCredential);
assertThat(subject.findAllPaths(), equalTo(newArrayList("/", "/certif/", "/certif/ic/", "/password/", "/value/")));
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method deleteVersion.
public CertificateCredentialVersion deleteVersion(UUID certificateUuid, UUID versionUuid, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_DELETE, null);
auditRecordParameters.add(eventAuditRecordParameters);
Credential certificate = certificateDataService.findByUuid(certificateUuid);
if (certificate == null || !permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.DELETE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
eventAuditRecordParameters.setCredentialName(certificate.getName());
CertificateCredentialVersion versionToDelete = certificateVersionDataService.findVersion(versionUuid);
if (versionDoesNotBelongToCertificate(certificate, versionToDelete)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
if (certificateHasOnlyOneVersion(certificateUuid)) {
throw new ParameterizedValidationException("error.credential.cannot_delete_last_version");
}
certificateVersionDataService.deleteVersion(versionUuid);
return versionToDelete;
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method set.
public CertificateCredentialVersion set(UUID certificateUuid, CertificateCredentialValue value, List<EventAuditRecordParameters> auditRecordParameters) {
Credential credential = findCertificateCredential(certificateUuid);
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_UPDATE, credential.getName());
auditRecordParameters.add(eventAuditRecordParameters);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credential.getName(), PermissionOperation.WRITE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
if (value.isTransitional()) {
validateNoTransitionalVersionsAlreadyExist(credential.getName(), auditRecordParameters);
}
CertificateCredentialVersion certificateCredentialVersion = certificateCredentialFactory.makeNewCredentialVersion(credential, value);
return credentialVersionDataService.save(certificateCredentialVersion);
}
Aggregations