Search in sources :

Example 11 with EntryNotFoundException

use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException in project credhub by cloudfoundry-incubator.

the class CertificateService method findByCredentialUuid.

public CertificateCredentialVersion findByCredentialUuid(String uuid, List<EventAuditRecordParameters> auditRecordParameters) {
    EventAuditRecordParameters eventAuditRecordParameters = new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS);
    auditRecordParameters.add(eventAuditRecordParameters);
    CredentialVersion credentialVersion = this.certificateVersionDataService.findByCredentialUUID(uuid);
    if (credentialVersion == null || !(credentialVersion instanceof CertificateCredentialVersion)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    eventAuditRecordParameters.setCredentialName(credentialVersion.getName());
    CertificateCredentialVersion certificate = (CertificateCredentialVersion) credentialVersion;
    if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), certificate.getName(), PermissionOperation.READ)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    return certificate;
}
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) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion)

Example 12 with EntryNotFoundException

use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException in project credhub by cloudfoundry-incubator.

the class PermissionServiceTest method saveAccessControlEntries_whenUserCantWrite_throws.

@Test
public void saveAccessControlEntries_whenUserCantWrite_throws() {
    when(permissionCheckingService.userAllowedToOperateOnActor(eq(USER_NAME))).thenReturn(true);
    when(permissionCheckingService.hasPermission(USER_NAME, CREDENTIAL_NAME, PermissionOperation.WRITE_ACL)).thenReturn(false);
    ArrayList<PermissionEntry> expectedEntries = newArrayList(new PermissionEntry(USER_NAME, PermissionOperation.READ));
    try {
        subject.savePermissions(expectedCredentialVersion, expectedEntries, auditRecordParameters, false, CREDENTIAL_NAME);
        fail("expected exception");
    } catch (EntryNotFoundException e) {
        assertThat(e.getMessage(), IsEqual.equalTo("error.credential.invalid_access"));
    }
}
Also used : PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) Test(org.junit.Test)

Example 13 with EntryNotFoundException

use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException in project credhub by cloudfoundry-incubator.

the class CertificatesHandler method handleGetAllVersionsRequest.

public List<CertificateView> handleGetAllVersionsRequest(String uuidString, List<EventAuditRecordParameters> auditRecordParameters, boolean current) {
    UUID uuid;
    try {
        uuid = UUID.fromString(uuidString);
    } catch (IllegalArgumentException e) {
        auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_ACCESS, null));
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    final List<CredentialVersion> credentialList = permissionedCertificateService.getVersions(uuid, current, auditRecordParameters);
    List<CertificateView> list = credentialList.stream().map(credential -> new CertificateView((CertificateCredentialVersion) credential)).collect(Collectors.toList());
    return list;
}
Also used : CredentialView(org.cloudfoundry.credhub.view.CredentialView) PermissionedCertificateService(org.cloudfoundry.credhub.service.PermissionedCertificateService) BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) CertificateCredentialsView(org.cloudfoundry.credhub.view.CertificateCredentialsView) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CreateVersionRequest(org.cloudfoundry.credhub.request.CreateVersionRequest) UUID(java.util.UUID) CertificateView(org.cloudfoundry.credhub.view.CertificateView) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Collectors(java.util.stream.Collectors) CertificateCredentialView(org.cloudfoundry.credhub.view.CertificateCredentialView) CertificateRegenerateRequest(org.cloudfoundry.credhub.request.CertificateRegenerateRequest) UpdateTransitionalVersionRequest(org.cloudfoundry.credhub.request.UpdateTransitionalVersionRequest) List(java.util.List) Credential(org.cloudfoundry.credhub.entity.Credential) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) AuditingOperationCode(org.cloudfoundry.credhub.audit.AuditingOperationCode) Service(org.springframework.stereotype.Service) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) CertificateService(org.cloudfoundry.credhub.service.CertificateService) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) UUID(java.util.UUID) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) CertificateView(org.cloudfoundry.credhub.view.CertificateView)

Example 14 with EntryNotFoundException

use of org.cloudfoundry.credhub.exceptions.EntryNotFoundException in project credhub by cloudfoundry-incubator.

the class PermissionsControllerTest method DELETE_whenTheCredentialDoesNotExist_logsAnEvent.

@Test
public void DELETE_whenTheCredentialDoesNotExist_logsAnEvent() throws Exception {
    when(permissionDataService.getAllowedOperations("/incorrect-name", "test-actor")).thenReturn(Collections.emptyList());
    Mockito.doThrow(new EntryNotFoundException("error.credential.invalid_access")).when(permissionsHandler).deletePermissionEntry(eq("/incorrect-name"), eq("test-actor"), any(List.class));
    expectStatusWhenDeletingPermissions(mockMvc, 404, "incorrect-name", "test-actor", UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    verify(permissionsHandler, times(1)).deletePermissionEntry(eq("/incorrect-name"), eq("test-actor"), any(List.class));
}
Also used : EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

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