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;
}
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"));
}
}
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;
}
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));
}
Aggregations