Search in sources :

Example 6 with Approval

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)));
}
Also used : ApprovalStore(org.cloudfoundry.identity.uaa.approval.ApprovalStore) Approval(org.cloudfoundry.identity.uaa.approval.Approval) UaaUserDatabase(org.cloudfoundry.identity.uaa.user.UaaUserDatabase) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 7 with Approval

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)));
}
Also used : ApprovalStore(org.cloudfoundry.identity.uaa.approval.ApprovalStore) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 8 with Approval

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()));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ApprovalStore(org.cloudfoundry.identity.uaa.approval.ApprovalStore) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Test(org.junit.jupiter.api.Test)

Example 9 with Approval

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());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 10 with Approval

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();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Approval(org.cloudfoundry.identity.uaa.approval.Approval) Date(java.util.Date)

Aggregations

Approval (org.cloudfoundry.identity.uaa.approval.Approval)80 Test (org.junit.jupiter.api.Test)34 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)29 Date (java.util.Date)26 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)21 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)19 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)18 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)17 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)16 Test (org.junit.Test)16 ApprovalStore (org.cloudfoundry.identity.uaa.approval.ApprovalStore)7 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 ClientDetailsModification (org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)5 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)5 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)5 ArrayList (java.util.ArrayList)4 ClientDetailsHelper.arrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.arrayFromString)4 ClientDetailsHelper.clientArrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientArrayFromString)4 ClientDetailsHelper.clientFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientFromString)4