Search in sources :

Example 1 with InvalidQueryParameterException

use of org.cloudfoundry.credhub.exceptions.InvalidQueryParameterException 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)

Aggregations

EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)1 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)1 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)1 Credential (org.cloudfoundry.credhub.entity.Credential)1 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)1 InvalidQueryParameterException (org.cloudfoundry.credhub.exceptions.InvalidQueryParameterException)1