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()));
}
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);
}
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));
}
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;
}
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));
}
Aggregations