Search in sources :

Example 6 with PermissionEntry

use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.

the class PermissionsEndpointTest method GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions.

@Test
public void GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions() throws Exception {
    RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read");
    PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialNameWithoutLeadingSlash, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    assertThat(permissions.getCredentialName(), equalTo(credentialName));
    assertThat(permissions.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", asList(PermissionOperation.READ)))));
    verifyAudit(ACL_ACCESS, credentialName, 200);
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with PermissionEntry

use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.

the class PermissionsEndpointWithoutEnforcementTest method GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions.

@Test
public void GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions() throws Exception {
    RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "test-actor", "read");
    PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    assertThat(permissions.getCredentialName(), equalTo(credentialName));
    assertThat(permissions.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("test-actor", asList(PermissionOperation.READ)))));
    verifyAudit(AuditingOperationCode.ACL_ACCESS, credentialName, 200);
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with PermissionEntry

use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.

the class PermissionsHandler method getPermissions.

public PermissionsView getPermissions(String name, List<EventAuditRecordParameters> auditRecordParameters) {
    CredentialVersion credentialVersion = permissionedCredentialService.findMostRecent(name);
    final List<PermissionEntry> permissions = permissionService.getPermissions(credentialVersion, auditRecordParameters, name);
    return new PermissionsView(credentialVersion.getName(), permissions);
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion)

Example 9 with PermissionEntry

use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.

the class PermissionService method savePermissions.

public void savePermissions(CredentialVersion credentialVersion, List<PermissionEntry> permissionEntryList, List<EventAuditRecordParameters> auditRecordParameters, boolean isNewCredential, String credentialName) {
    auditRecordParameters.addAll(EventAuditRecordParametersFactory.createPermissionsEventAuditParameters(ACL_UPDATE, credentialName, permissionEntryList));
    if (credentialVersion == null) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    for (PermissionEntry permissionEntry : permissionEntryList) {
        if (!permissionCheckingService.userAllowedToOperateOnActor(permissionEntry.getActor())) {
            throw new InvalidPermissionOperationException("error.permission.invalid_update_operation");
        }
    }
    if (isNewCredential) {
        final PermissionEntry permissionEntry = new PermissionEntry(userContextHolder.getUserContext().getActor(), asList(READ, WRITE, DELETE, WRITE_ACL, READ_ACL));
        permissionEntryList.add(permissionEntry);
        auditRecordParameters.addAll(EventAuditRecordParametersFactory.createPermissionsEventAuditParameters(ACL_UPDATE, credentialName, asList(permissionEntry)));
    }
    if (permissionEntryList.size() == 0) {
        return;
    }
    if (!permissionCheckingService.hasPermission(userContextHolder.getUserContext().getActor(), credentialVersion.getName(), WRITE_ACL)) {
        throw new EntryNotFoundException("error.credential.invalid_access");
    }
    permissionDataService.savePermissions(credentialVersion.getCredential(), permissionEntryList);
}
Also used : EntryNotFoundException(org.cloudfoundry.credhub.exceptions.EntryNotFoundException) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) InvalidPermissionOperationException(org.cloudfoundry.credhub.exceptions.InvalidPermissionOperationException)

Example 10 with PermissionEntry

use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.

the class CredentialsControllerTypeSpecificGenerateTest method generatingANewCredential_addsFullPermissionsForCurrentUser.

@Test
public void generatingANewCredential_addsFullPermissionsForCurrentUser() throws Exception {
    MockHttpServletRequestBuilder request = createGenerateNewCredentialRequest();
    mockMvc.perform(request);
    MockHttpServletRequestBuilder getRequest = get("/api/v1/permissions?credential_name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
    MvcResult result = mockMvc.perform(getRequest).andExpect(status().isOk()).andReturn();
    String content = result.getResponse().getContentAsString();
    PermissionsView acl = JsonTestHelper.deserialize(content, PermissionsView.class);
    assertThat(acl.getCredentialName(), equalTo(CREDENTIAL_NAME));
    assertThat(acl.getPermissions(), Matchers.contains(samePropertyValuesAs(new PermissionEntry(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, asList(READ, WRITE, DELETE, READ_ACL, WRITE_ACL)))));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) Matchers.anyString(org.mockito.Matchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

PermissionEntry (org.cloudfoundry.credhub.request.PermissionEntry)33 Test (org.junit.Test)26 PermissionsView (org.cloudfoundry.credhub.view.PermissionsView)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)6 MvcResult (org.springframework.test.web.servlet.MvcResult)5 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)3 InvalidPermissionOperationException (org.cloudfoundry.credhub.exceptions.InvalidPermissionOperationException)3 PermissionOperation (org.cloudfoundry.credhub.request.PermissionOperation)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 DocumentContext (com.jayway.jsonpath.DocumentContext)2 List (java.util.List)2 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)2 Credential (org.cloudfoundry.credhub.entity.Credential)2 ValueCredentialVersionData (org.cloudfoundry.credhub.entity.ValueCredentialVersionData)2 EntryNotFoundException (org.cloudfoundry.credhub.exceptions.EntryNotFoundException)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 ArrayList (java.util.ArrayList)1 PermissionException (org.cloudfoundry.credhub.exceptions.PermissionException)1 PermissionsRequest (org.cloudfoundry.credhub.request.PermissionsRequest)1