Search in sources :

Example 6 with EntryNotFoundException

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);
}
Also used : EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 7 with EntryNotFoundException

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;
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 8 with EntryNotFoundException

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);
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 9 with EntryNotFoundException

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;
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) InvalidQueryParameterException(org.cloudfoundry.credhub.exceptions.InvalidQueryParameterException) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 10 with EntryNotFoundException

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;
}
Also used : Credential(org.cloudfoundry.credhub.entity.Credential) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters)

Aggregations

EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)14 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)9 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)8 Credential (org.cloudfoundry.credhub.entity.Credential)7 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)6 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)4 List (java.util.List)2 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)2 PermissionEntry (org.cloudfoundry.credhub.request.PermissionEntry)2 Test (org.junit.Test)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 AuditingOperationCode (org.cloudfoundry.credhub.audit.AuditingOperationCode)1 JsonCredentialVersion (org.cloudfoundry.credhub.domain.JsonCredentialVersion)1 InvalidPermissionOperationException (org.cloudfoundry.credhub.exceptions.InvalidPermissionOperationException)1 InvalidQueryParameterException (org.cloudfoundry.credhub.exceptions.InvalidQueryParameterException)1 BaseCredentialGenerateRequest (org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest)1