use of org.cloudfoundry.credhub.view.PermissionsView 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.view.PermissionsView 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)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class CredentialsControllerTypeSpecificSetTest method creatingACredential_createsRequestedPermissions_andFullPermissionsForCurrentUser.
@Test
public void creatingACredential_createsRequestedPermissions_andFullPermissionsForCurrentUser() throws Exception {
MockHttpServletRequestBuilder putRequest = put("/api/v1/data").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content("{" + "\"name\":\"" + CREDENTIAL_NAME + "\"," + "\"type\":\"" + parametizer.credentialType + "\"," + "\"value\":" + parametizer.credentialValue + "," + "\"overwrite\":" + false + "," + "\"additional_permissions\": [" + "{\"actor\": \"app1-guid\"," + "\"operations\": [\"read\"]}]" + "}");
MockHttpServletRequestBuilder getRequest = get("/api/v1/permissions?credential_name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
mockMvc.perform(putRequest).andExpect(status().isOk());
String responseContent = mockMvc.perform(getRequest).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
PermissionsView acl = JsonTestHelper.deserialize(responseContent, PermissionsView.class);
assertThat(acl.getCredentialName(), equalTo(CREDENTIAL_NAME));
assertThat(acl.getPermissions(), containsInAnyOrder(samePropertyValuesAs(new PermissionEntry(UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, asList(READ, WRITE, DELETE, READ_ACL, WRITE_ACL))), samePropertyValuesAs(new PermissionEntry("app1-guid", asList(READ)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsControllerTest method GET_whenTheCredentialNameDoesNotHaveALeadingSlash_returnsThePermissionsForTheCredential.
@Test
public void GET_whenTheCredentialNameDoesNotHaveALeadingSlash_returnsThePermissionsForTheCredential() throws Exception {
PermissionsView permissionsView = new PermissionsView("/test_credential_name", newArrayList());
when(permissionsHandler.getPermissions(eq("/test_credential_name"), any(List.class))).thenReturn(permissionsView);
PermissionsView permissions = getPermissions(mockMvc, "test_credential_name", UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(permissions.getCredentialName(), equalTo("/test_credential_name"));
assertThat(permissions.getPermissions(), hasSize(0));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class NoOverwriteTest method whenMultipleThreadsGenerateCredentialWithSameNameAndNoOverwrite_itShouldNotOverwrite.
@Test
public void whenMultipleThreadsGenerateCredentialWithSameNameAndNoOverwrite_itShouldNotOverwrite() throws Exception {
// We need to set the parameters so that we can determine which actor's request won,
// even with authorization enforcement disabled.
runRequestsConcurrently(CREDENTIAL_NAME, ",\"parameters\":{\"exclude_lower\":true,\"exclude_upper\":true}", ",\"parameters\":{\"exclude_number\":true}", () -> post("/api/v1/data"));
MvcResult result1 = responses[0].andDo(print()).andReturn();
final DocumentContext context1 = JsonPath.parse(result1.getResponse().getContentAsString());
MvcResult result2 = responses[1].andDo(print()).andReturn();
final DocumentContext context2 = JsonPath.parse(result2.getResponse().getContentAsString());
assertThat(context1.read("$.value"), equalTo(context2.read("$.value")));
MockHttpServletResponse response1 = mockMvc.perform(get("/api/v1/permissions?credential_name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_TOKEN)).andDo(print()).andReturn().getResponse();
MockHttpServletResponse response2 = mockMvc.perform(get("/api/v1/permissions?credential_name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + UAA_OAUTH2_CLIENT_CREDENTIALS_TOKEN)).andDo(print()).andReturn().getResponse();
String winningPassword = context1.read("$.value");
String winningActor;
String winningResponse;
if (winningPassword.matches("\\d+")) {
winningActor = UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID;
winningResponse = response1.getContentAsString();
} else {
winningActor = UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID;
winningResponse = response2.getContentAsString();
}
PermissionsView acl = JsonTestHelper.deserialize(winningResponse, PermissionsView.class);
assertThat(acl.getPermissions(), containsInAnyOrder(samePropertyValuesAs(new PermissionEntry(winningActor, asList(READ, WRITE, DELETE, READ_ACL, WRITE_ACL))), samePropertyValuesAs(new PermissionEntry("uaa-client:a-different-actor", singletonList(READ)))));
}
Aggregations