Search in sources :

Example 21 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser 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 22 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method getUser.

private void getUser(String token, int status) throws Exception {
    ScimUser joel = setUpScimUser();
    getAndReturnUser(status, joel, token);
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser)

Example 23 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method verifyUser.

private void verifyUser(String token) throws Exception {
    ScimUserProvisioning usersRepository = webApplicationContext.getBean(ScimUserProvisioning.class);
    String email = "joe@" + generator.generate().toLowerCase() + ".com";
    ScimUser joel = new ScimUser(null, email, "Joel", "D'sa");
    joel.addEmail(email);
    joel = usersRepository.createUser(joel, "pas5Word", IdentityZoneHolder.get().getId());
    MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/Users/" + joel.getId() + "/verify").header("Authorization", "Bearer " + token).accept(APPLICATION_JSON);
    mockMvc.perform(get).andExpect(status().isOk()).andExpect(header().string("ETag", "\"0\"")).andExpect(jsonPath("$.userName").value(email)).andExpect(jsonPath("$.emails[0].value").value(email)).andExpect(jsonPath("$.name.familyName").value("D'sa")).andExpect(jsonPath("$.name.givenName").value("Joel")).andExpect(jsonPath("$.verified").value(true));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning)

Example 24 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method getScimUser.

private ScimUser getScimUser() {
    String email = "joe@" + generator.generate().toLowerCase() + ".com";
    ScimUser user = new ScimUser();
    user.setUserName(email);
    user.setName(new ScimUser.Name("Joe", "User"));
    user.addEmail(email);
    return user;
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser)

Example 25 with ScimUser

use of org.cloudfoundry.identity.uaa.scim.ScimUser in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method verification_link_in_non_default_zone_using_switch.

@Test
void verification_link_in_non_default_zone_using_switch() throws Exception {
    String subdomain = generator.generate().toLowerCase();
    MockMvcUtils.IdentityZoneCreationResult zoneResult = MockMvcUtils.createOtherIdentityZoneAndReturnResult(subdomain, mockMvc, webApplicationContext, null, IdentityZoneHolder.getCurrentZoneId());
    String zonedClientId = "admin";
    String zonedClientSecret = "adminsecret";
    String zonedScimCreateToken = MockMvcUtils.getClientCredentialsOAuthAccessToken(mockMvc, zonedClientId, zonedClientSecret, "uaa.admin", null);
    ScimUser joel = setUpScimUser(zoneResult.getIdentityZone());
    MockHttpServletRequestBuilder get = MockMvcRequestBuilders.get("/Users/" + joel.getId() + "/verify-link").header("Host", "localhost").header("Authorization", "Bearer " + zonedScimCreateToken).header(IdentityZoneSwitchingFilter.SUBDOMAIN_HEADER, subdomain).param("redirect_uri", HTTP_REDIRECT_EXAMPLE_COM).accept(APPLICATION_JSON);
    MvcResult result = mockMvc.perform(get).andExpect(status().isOk()).andReturn();
    VerificationResponse verificationResponse = JsonUtils.readValue(result.getResponse().getContentAsString(), VerificationResponse.class);
    assertThat(verificationResponse.getVerifyLink().toString(), startsWith("http://" + subdomain + ".localhost/verify_user"));
    String query = verificationResponse.getVerifyLink().getQuery();
    String code = getQueryStringParam(query, "code");
    assertThat(code, is(notNullValue()));
    IdentityZoneHolder.set(zoneResult.getIdentityZone());
    ExpiringCode expiringCode = codeStore.retrieveCode(code, IdentityZoneHolder.get().getId());
    IdentityZoneHolder.clear();
    assertThat(expiringCode.getExpiresAt().getTime(), is(greaterThan(System.currentTimeMillis())));
    assertThat(expiringCode.getIntent(), is(REGISTRATION.name()));
    Map<String, String> data = JsonUtils.readValue(expiringCode.getData(), new TypeReference<Map<String, String>>() {
    });
    assertThat(data.get(USER_ID), is(notNullValue()));
    assertThat(data.get(CLIENT_ID), is("admin"));
    assertThat(data.get(REDIRECT_URI), is(HTTP_REDIRECT_EXAMPLE_COM));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ExpiringCode(org.cloudfoundry.identity.uaa.codestore.ExpiringCode) MockMvcUtils(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)495 Test (org.junit.jupiter.api.Test)301 Matchers.containsString (org.hamcrest.Matchers.containsString)136 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)80 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)75 Test (org.junit.Test)57 ExpiringCode (org.cloudfoundry.identity.uaa.codestore.ExpiringCode)56 MvcResult (org.springframework.test.web.servlet.MvcResult)50 Timestamp (java.sql.Timestamp)49 MockHttpSession (org.springframework.mock.web.MockHttpSession)47 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)43 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)41 HashMap (java.util.HashMap)39 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)35 Map (java.util.Map)34 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)33 RestTemplate (org.springframework.web.client.RestTemplate)30 ScimGroupMember (org.cloudfoundry.identity.uaa.scim.ScimGroupMember)29 List (java.util.List)27