use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificateServiceTest method findByUuid_ReturnsCertificateWithMatchingUuidAndPersistsAuditEntry.
@Test
public void findByUuid_ReturnsCertificateWithMatchingUuidAndPersistsAuditEntry() {
when(permissionCheckingService.hasPermission(actor, credentialName, PermissionOperation.READ)).thenReturn(true);
CertificateCredentialVersion certificate = subject.findByCredentialUuid(credentialUuid, auditRecordParameters);
assertThat(certificate, not(nullValue()));
assertThat(auditRecordParameters.size(), equalTo(1));
EventAuditRecordParameters auditRecord = this.auditRecordParameters.get(0);
assertThat(auditRecord.getAuditingOperationCode(), equalTo(AuditingOperationCode.CREDENTIAL_ACCESS));
assertThat(auditRecord.getCredentialName(), equalTo(credentialName));
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class PermissionedCertificateService method updateTransitionalVersion.
public List<CredentialVersion> updateTransitionalVersion(UUID certificateUuid, UUID newTransitionalVersionUuid, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_UPDATE, null);
auditRecordParameters.add(eventAuditRecordParameters);
Credential credential = findCertificateCredential(certificateUuid);
String name = credential.getName();
eventAuditRecordParameters.setCredentialName(name);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), name, PermissionOperation.WRITE)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
certificateVersionDataService.unsetTransitionalVerison(certificateUuid);
if (newTransitionalVersionUuid != null) {
CertificateCredentialVersion version = certificateVersionDataService.findVersion(newTransitionalVersionUuid);
if (versionDoesNotBelongToCertificate(credential, version)) {
throw new ParameterizedValidationException("error.credential.mismatched_credential_and_version");
}
certificateVersionDataService.setTransitionalVersion(newTransitionalVersionUuid);
}
return certificateVersionDataService.findActiveWithTransitional(name);
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificateCredentialRegeneratable method createGenerateRequest.
@Override
public BaseCredentialGenerateRequest createGenerateRequest(CredentialVersion credentialVersion, List<EventAuditRecordParameters> auditRecordParameters) {
CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) credentialVersion;
CertificateReader reader = certificateCredential.getParsedCertificate();
if (!reader.isValid() || (isEmpty(certificateCredential.getCaName()) && !reader.isSelfSigned())) {
auditRecordParameters.add(new EventAuditRecordParameters(CREDENTIAL_UPDATE, credentialVersion.getName()));
throw new ParameterizedValidationException("error.cannot_regenerate_non_generated_certificate");
}
CertificateGenerationParameters certificateGenerationParameters = new CertificateGenerationParameters(reader, certificateCredential.getCaName());
CertificateGenerateRequest generateRequest = new CertificateGenerateRequest();
generateRequest.setName(certificateCredential.getName());
generateRequest.setType(certificateCredential.getCredentialType());
generateRequest.setCertificateGenerationParameters(certificateGenerationParameters);
generateRequest.setOverwrite(true);
return generateRequest;
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleRegenerate.
public CredentialView handleRegenerate(String credentialUuid, List<EventAuditRecordParameters> auditRecordParameters, CertificateRegenerateRequest request) {
CertificateCredentialVersion existingCredentialVersion = certificateService.findByCredentialUuid(credentialUuid, auditRecordParameters);
BaseCredentialGenerateRequest generateRequest = generationRequestGenerator.createGenerateRequest(existingCredentialVersion, existingCredentialVersion.getName(), auditRecordParameters);
CertificateCredentialValue credentialValue = (CertificateCredentialValue) credentialGenerator.generate(generateRequest);
credentialValue.setTransitional(request.isTransitional());
final CertificateCredentialVersion credentialVersion = (CertificateCredentialVersion) permissionedCertificateService.save(existingCredentialVersion, credentialValue, generateRequest, auditRecordParameters);
return new CertificateView(credentialVersion);
}
use of org.cloudfoundry.credhub.domain.CertificateCredentialVersion in project credhub by cloudfoundry-incubator.
the class CertificatesHandler method handleCreateVersionsRequest.
public CertificateView handleCreateVersionsRequest(String certificateId, CreateVersionRequest requestBody, List<EventAuditRecordParameters> auditRecordParameters) {
CertificateCredentialValue certificateCredentialValue = requestBody.getValue();
certificateCredentialValue.setTransitional(requestBody.isTransitional());
final CertificateCredentialVersion credentialVersion = permissionedCertificateService.set(UUID.fromString(certificateId), certificateCredentialValue, auditRecordParameters);
return new CertificateView(credentialVersion);
}
Aggregations