use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointWithoutEnforcementTest method POST_whenTheUserHasPermissionToWritePermissions_updatesPermissions.
@Test
public void POST_whenTheUserHasPermissionToWritePermissions_updatesPermissions() throws Exception {
Long initialCount = eventAuditRecordRepository.count();
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read", "delete");
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read", "write");
// 2 from initialPost, 2 from updatePost
assertThat(eventAuditRecordRepository.count(), equalTo(4L + initialCount));
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.READ, "dan"), new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.WRITE, "dan")));
PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(permissions.getPermissions(), hasSize(2));
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, PermissionOperation.WRITE, PermissionOperation.DELETE)))));
}
use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointWithoutEnforcementTest method POST_whenTheUserHasPermissionToWritePermissions_returnsPermissions.
@Test
public void POST_whenTheUserHasPermissionToWritePermissions_returnsPermissions() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read", "write");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.READ, "dan"), new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.WRITE, "dan")));
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "isobel", "delete");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.DELETE, "isobel")));
PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(permissions.getPermissions(), hasSize(3));
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, PermissionOperation.WRITE))), samePropertyValuesAs(new PermissionEntry("isobel", asList(PermissionOperation.DELETE)))));
}
use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionDataService method createViewFor.
private PermissionEntry createViewFor(PermissionData data) {
if (data == null) {
return null;
}
PermissionEntry entry = new PermissionEntry();
List<PermissionOperation> operations = data.generateAccessControlOperations();
entry.setAllowedOperations(operations);
entry.setActor(data.getActor());
return entry;
}
use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionDataServiceTest method setAccessControlEntries_whenGivenANewAce_returnsTheAcl.
@Test
public void setAccessControlEntries_whenGivenANewAce_returnsTheAcl() {
final ValueCredentialVersionData valueCredentialData2 = new ValueCredentialVersionData("lightsaber2");
final Credential credential2 = valueCredentialData2.getCredential();
credentialDataService.save(credential2);
aces = singletonList(new PermissionEntry(LUKE, singletonList(READ)));
subject.savePermissions(credential2, aces);
List<PermissionEntry> response = subject.getPermissions(credential2);
final PermissionEntry permissionEntry = response.get(0);
assertThat(response, hasSize(1));
assertThat(permissionEntry.getActor(), equalTo(LUKE));
assertThat(permissionEntry.getAllowedOperations(), hasSize(1));
assertThat(permissionEntry.getAllowedOperations(), hasItem(READ));
}
use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionsControllerAuditLogTest method setUp.
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).apply(springSecurity()).build();
PermissionEntry ace = new PermissionEntry(UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, Arrays.asList(READ_ACL));
when(permissionDataService.getPermissions(eq(CRED1.getCredential()))).thenReturn(Arrays.asList(ace));
when(permissionCheckingService.hasPermission(any(), anyString(), eq(READ_ACL))).thenReturn(true);
when(permissionedCredentialService.findMostRecent(CRED1.getName())).thenReturn(CRED1);
reset(eventAuditRecordDataService);
}
Aggregations