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