use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException in project credhub by cloudfoundry-incubator.
the class PermissionedCredentialService method findVersionByUuid.
public CredentialVersion findVersionByUuid(String credentialUUID, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
auditRecordParameters.add(eventAuditRecordParameters);
CredentialVersion credentialVersion = credentialVersionDataService.findByUuid(credentialUUID);
if (credentialVersion == null) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
String credentialName = credentialVersion.getName();
eventAuditRecordParameters.setCredentialName(credentialName);
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credentialName, READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return credentialVersionDataService.findByUuid(credentialUUID);
}
use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException 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.exceptions.EntryNotFoundException 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);
}
use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException 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.exceptions.EntryNotFoundException in project credhub by cloudfoundry-incubator.
the class PermissionedCredentialService method findByUuid.
public Credential findByUuid(UUID credentialUUID, List<EventAuditRecordParameters> auditRecordParameters) {
EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
auditRecordParameters.add(eventAuditRecordParameters);
Credential credential = credentialDataService.findByUUID(credentialUUID);
if (credential == null) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
eventAuditRecordParameters.setCredentialName(credential.getName());
if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credential.getName(), READ)) {
throw new EntryNotFoundException("error.credential.invalid_access");
}
return credential;
}
Aggregations