Search in sources :

Example 6 with EventAuditRecordParameters

use of org.cloudfoundry.credhub.audit.EventAuditRecordParameters in project credhub by cloudfoundry-incubator.

the class PermissionAndCredentialTest method auditsTheRequestWithNoNewPermissions.

private void auditsTheRequestWithNoNewPermissions() throws Exception {
    List<EventAuditRecordParameters> auditRecordParameters = newArrayList(new EventAuditRecordParameters(CREDENTIAL_ACCESS, "/test-password"));
    auditingHelper.verifyAuditing(UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID, "/api/v1/data", 200, auditRecordParameters);
}
Also used : EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters)

Example 7 with EventAuditRecordParameters

use of org.cloudfoundry.credhub.audit.EventAuditRecordParameters in project credhub by cloudfoundry-incubator.

the class PermissionsEndpointTest method POST_whenTheLeadingSlashIsMissing_prependsTheSlashCorrectly.

@Test
public void POST_whenTheLeadingSlashIsMissing_prependsTheSlashCorrectly() throws Exception {
    RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read");
    auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(ACL_UPDATE, credentialName, PermissionOperation.READ, "dan")));
    PermissionsView acl = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    assertThat(acl.getCredentialName(), equalTo(credentialName));
    assertThat(acl.getPermissions(), hasSize(2));
    assertThat(acl.getPermissions(), containsInAnyOrder(samePropertyValuesAs(new PermissionEntry(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, asList(PermissionOperation.READ, PermissionOperation.WRITE, PermissionOperation.DELETE, PermissionOperation.READ_ACL, PermissionOperation.WRITE_ACL))), samePropertyValuesAs(new PermissionEntry("dan", singletonList(PermissionOperation.READ)))));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with EventAuditRecordParameters

use of org.cloudfoundry.credhub.audit.EventAuditRecordParameters in project credhub by cloudfoundry-incubator.

the class PermissionsEndpointTest method DELETE_whenTheActorDoesNotHavePermissionToDeletePermissions_returnsNotFound.

@Test
public void DELETE_whenTheActorDoesNotHavePermissionToDeletePermissions_returnsNotFound() throws Exception {
    RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read");
    RequestHelper.expectStatusWhenDeletingPermissions(mockMvc, 404, credentialName, "dan", AuthConstants.UAA_OAUTH2_CLIENT_CREDENTIALS_TOKEN);
    auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID, "/api/v1/permissions", 404, newArrayList(new EventAuditRecordParameters(ACL_DELETE, credentialName, PermissionOperation.READ, "dan")));
    PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    assertThat(permissions.getPermissions(), hasSize(2));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with EventAuditRecordParameters

use of org.cloudfoundry.credhub.audit.EventAuditRecordParameters in project credhub by cloudfoundry-incubator.

the class CertificateServiceTest method findByUuid_ReturnsCertificateWithMatchingUuidAndPersistsAuditEntry.

@Test
public void findByUuid_ReturnsCertificateWithMatchingUuidAndPersistsAuditEntry() {
    when(permissionCheckingService.hasPermission(actor, credentialName, PermissionOperation.READ)).thenReturn(true);
    CertificateCredentialVersion certificate = subject.findByCredentialUuid(credentialUuid, auditRecordParameters);
    assertThat(certificate, not(nullValue()));
    assertThat(auditRecordParameters.size(), equalTo(1));
    EventAuditRecordParameters auditRecord = this.auditRecordParameters.get(0);
    assertThat(auditRecord.getAuditingOperationCode(), equalTo(AuditingOperationCode.CREDENTIAL_ACCESS));
    assertThat(auditRecord.getCredentialName(), equalTo(credentialName));
}
Also used : EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Test(org.junit.Test)

Example 10 with EventAuditRecordParameters

use of org.cloudfoundry.credhub.audit.EventAuditRecordParameters in project credhub by cloudfoundry-incubator.

the class PermissionedCertificateService method getAll.

public List<Credential> getAll(List<EventAuditRecordParameters> auditRecordParameters) {
    auditRecordParameters.add(new EventAuditRecordParameters(AuditingOperationCode.CREDENTIAL_FIND, null));
    final List<Credential> allCertificates = certificateDataService.findAll();
    return allCertificates.stream().filter(credential -> permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credential.getName(), PermissionOperation.READ)).collect(Collectors.toList());
}
Also used : ParameterizedValidationException(org.cloudfoundry.credhub.exceptions.ParameterizedValidationException) BaseCredentialGenerateRequest(org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest) PermissionOperation(org.cloudfoundry.credhub.request.PermissionOperation) CertificateCredentialVersion(org.cloudfoundry.credhub.domain.CertificateCredentialVersion) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) CertificateDataService(org.cloudfoundry.credhub.data.CertificateDataService) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Collectors(java.util.stream.Collectors) UserContextHolder(org.cloudfoundry.credhub.auth.UserContextHolder) List(java.util.List) CertificateVersionDataService(org.cloudfoundry.credhub.data.CertificateVersionDataService) Credential(org.cloudfoundry.credhub.entity.Credential) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) InvalidQueryParameterException(org.cloudfoundry.credhub.exceptions.InvalidQueryParameterException) AuditingOperationCode(org.cloudfoundry.credhub.audit.AuditingOperationCode) CredentialVersionDataService(org.cloudfoundry.credhub.data.CredentialVersionDataService) Service(org.springframework.stereotype.Service) CertificateCredentialValue(org.cloudfoundry.credhub.credential.CertificateCredentialValue) Collections(java.util.Collections) EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) CertificateCredentialFactory(org.cloudfoundry.credhub.domain.CertificateCredentialFactory) Credential(org.cloudfoundry.credhub.entity.Credential) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters)

Aggregations

EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)41 Test (org.junit.Test)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 CertificateCredentialVersion (org.cloudfoundry.credhub.domain.CertificateCredentialVersion)11 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)11 Credential (org.cloudfoundry.credhub.entity.Credential)9 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)7 PermissionsView (org.cloudfoundry.credhub.view.PermissionsView)7 ArrayList (java.util.ArrayList)6 ParameterizedValidationException (org.cloudfoundry.credhub.exceptions.ParameterizedValidationException)6 AuditingOperationCode (org.cloudfoundry.credhub.audit.AuditingOperationCode)5 CertificateCredentialValue (org.cloudfoundry.credhub.credential.CertificateCredentialValue)5 PermissionEntry (org.cloudfoundry.credhub.request.PermissionEntry)5 List (java.util.List)4 UUID (java.util.UUID)4 Collectors (java.util.stream.Collectors)4 StringCredentialValue (org.cloudfoundry.credhub.credential.StringCredentialValue)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 BaseCredentialGenerateRequest (org.cloudfoundry.credhub.request.BaseCredentialGenerateRequest)3 Service (org.springframework.stereotype.Service)3