use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserEndpointDocs method test_Get_User.
@Test
void test_Get_User() throws Exception {
ApprovalStore store = webApplicationContext.getBean(ApprovalStore.class);
Approval approval = new Approval().setUserId(user.getId()).setStatus(Approval.ApprovalStatus.APPROVED).setScope("uaa.user").setClientId("identity").setExpiresAt(new Date(System.currentTimeMillis() + 30000)).setLastUpdatedAt(new Date(System.currentTimeMillis() + 30000));
store.addApproval(approval, IdentityZoneHolder.get().getId());
webApplicationContext.getBean(UaaUserDatabase.class).updateLastLogonTime(user.getId());
webApplicationContext.getBean(UaaUserDatabase.class).updateLastLogonTime(user.getId());
mockMvc.perform(RestDocumentationRequestBuilders.get("/Users/{userId}", user.getId()).accept(APPLICATION_JSON).header("Authorization", "Bearer " + scimReadToken).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("If-Match", user.getVersion())).andExpect(status().isOk()).andExpect(jsonPath("$.previousLogonTime").exists()).andExpect(jsonPath("$.lastLogonTime").exists()).andDo(document("{ClassName}/{methodName}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), pathParameters(parameterWithName("userId").description(userIdDescription)), requestHeaders(headerWithName("Authorization").description("Access token with scope `scim.read`, `uaa.admin`, or `zones.uaa.admin` required"), headerWithName("If-Match").optional().description("The version of the SCIM object to be deleted. Optional."), IDENTITY_ZONE_ID_HEADER, IDENTITY_ZONE_SUBDOMAIN_HEADER), responseFields(updateResponse)));
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserEndpointDocs method test_Patch_User.
@Test
void test_Patch_User() throws Exception {
ApprovalStore store = webApplicationContext.getBean(ApprovalStore.class);
Approval approval = new Approval().setUserId(user.getId()).setStatus(Approval.ApprovalStatus.DENIED).setScope("uaa.user").setClientId("identity").setExpiresAt(new Date(System.currentTimeMillis() + 30000)).setLastUpdatedAt(new Date(System.currentTimeMillis() + 30000));
store.addApproval(approval, IdentityZoneHolder.get().getId());
user.setGroups(Collections.emptyList());
mockMvc.perform(RestDocumentationRequestBuilders.patch("/Users/{userId}", user.getId()).accept(APPLICATION_JSON).header("Authorization", "Bearer " + scimWriteToken).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).header("If-Match", user.getVersion()).content(JsonUtils.writeValueAsString(user))).andExpect(status().isOk()).andDo(document("{ClassName}/{methodName}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), pathParameters(parameterWithName("userId").description(userIdDescription)), requestHeaders(headerWithName("Authorization").description(requiredUserUpdateScopes), headerWithName("If-Match").description("The version of the SCIM object to be updated. Wildcard (*) accepted.")), patchFields, responseFields(updateResponse)));
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserEndpointsMockMvcTests method delete_user_clears_approvals.
@Test
void delete_user_clears_approvals() throws Exception {
ApprovalStore store = webApplicationContext.getBean(ApprovalStore.class);
JdbcTemplate template = webApplicationContext.getBean(JdbcTemplate.class);
ScimUser user = setUpScimUser();
Approval approval = new Approval();
approval.setClientId("cf");
approval.setUserId(user.getId());
approval.setScope("openid");
approval.setStatus(Approval.ApprovalStatus.APPROVED);
store.addApproval(approval, IdentityZoneHolder.get().getId());
assertEquals(1, (long) template.queryForObject("select count(*) from authz_approvals where user_id=?", Integer.class, user.getId()));
mockMvc.perform((delete("/Users/" + user.getId())).header("Authorization", "Bearer " + uaaAdminToken).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsBytes(user))).andExpect(status().isOk()).andExpect(jsonPath("$.userName").value(user.getUserName())).andExpect(jsonPath("$.emails[0].value").value(user.getPrimaryEmail())).andExpect(jsonPath("$.name.givenName").value(user.getGivenName())).andExpect(jsonPath("$.name.familyName").value(user.getFamilyName()));
assertEquals(0, (long) template.queryForObject("select count(*) from authz_approvals where user_id=?", Integer.class, user.getId()));
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method approvalsIsSyncedCorrectlyOnCreate.
@Test
void approvalsIsSyncedCorrectlyOnCreate() {
ScimUser user = new ScimUser(null, "vidya", "Vidya", "V");
user.addEmail("vidya@vmware.com");
user.setPassword("password");
Approval mockApproval = mock(Approval.class);
when(mockApproval.isActiveAsOf(any(Date.class))).thenReturn(true);
when(mockApprovalStore.getApprovalsForUser(anyString(), eq(identityZone.getId()))).thenReturn(Collections.singletonList(mockApproval));
user.setApprovals(Collections.singleton(mockApproval));
ScimUser created = scimUserEndpoints.createUser(user, new MockHttpServletRequest(), new MockHttpServletResponse());
assertNotNull(created.getApprovals());
verify(mockApprovalStore).addApproval(mockApproval, identityZone.getId());
assertEquals(1, created.getApprovals().size());
}
use of org.cloudfoundry.identity.uaa.approval.Approval in project uaa by cloudfoundry.
the class ClientAdminEndpointsIntegrationTests method addApprovals.
private Approval[] addApprovals(String token, String clientId) {
Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000);
Date expiresAt = new Date(System.currentTimeMillis() + 60000);
Approval[] approvals = new Approval[] { new Approval().setUserId(null).setClientId(clientId).setScope("cloud_controller.read").setExpiresAt(expiresAt).setStatus(Approval.ApprovalStatus.APPROVED).setLastUpdatedAt(oneMinuteAgo), new Approval().setUserId(null).setClientId(clientId).setScope("openid").setExpiresAt(expiresAt).setStatus(Approval.ApprovalStatus.APPROVED).setLastUpdatedAt(oneMinuteAgo), new Approval().setUserId(null).setClientId(clientId).setScope("password.write").setExpiresAt(expiresAt).setStatus(Approval.ApprovalStatus.APPROVED).setLastUpdatedAt(oneMinuteAgo) };
HttpHeaders headers = getAuthenticatedHeaders(token);
HttpEntity<Approval[]> entity = new HttpEntity<Approval[]>(approvals, headers);
ResponseEntity<Approval[]> response = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/approvals/{clientId}"), HttpMethod.PUT, entity, Approval[].class, clientId);
assertEquals(HttpStatus.OK, response.getStatusCode());
return response.getBody();
}
Aggregations