Search in sources :

Example 26 with ScimUser

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

the class ScimUserEndpointsMockMvcTests method testCreateUserInOtherZoneIsUnauthorized.

@Test
void testCreateUserInOtherZoneIsUnauthorized() throws Exception {
    String subdomain = generator.generate();
    MockMvcUtils.createOtherIdentityZone(subdomain, mockMvc, webApplicationContext, IdentityZoneHolder.getCurrentZoneId());
    String otherSubdomain = generator.generate();
    MockMvcUtils.createOtherIdentityZone(otherSubdomain, mockMvc, webApplicationContext, IdentityZoneHolder.getCurrentZoneId());
    String zoneAdminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "admin-secret", "scim.write", subdomain);
    ScimUser user = getScimUser();
    byte[] requestBody = JsonUtils.writeValueAsBytes(user);
    MockHttpServletRequestBuilder post = post("/Users").with(new SetServerNameRequestPostProcessor(otherSubdomain + ".localhost")).header("Authorization", "Bearer " + zoneAdminToken).contentType(APPLICATION_JSON).content(requestBody);
    mockMvc.perform(post).andExpect(status().isUnauthorized());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) SetServerNameRequestPostProcessor(org.cloudfoundry.identity.uaa.util.SetServerNameRequestPostProcessor) Test(org.junit.jupiter.api.Test)

Example 27 with ScimUser

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

the class ScimUserEndpointsMockMvcTests method testForcePasswordExpireAccountInvalid.

@Test
void testForcePasswordExpireAccountInvalid() throws Exception {
    ScimUser user = createUser(uaaAdminToken);
    UserAccountStatus alteredAccountStatus = new UserAccountStatus();
    alteredAccountStatus.setPasswordChangeRequired(false);
    updateAccountStatus(user, alteredAccountStatus).andExpect(status().isBadRequest());
    assertFalse(usersRepository.checkPasswordChangeIndividuallyRequired(user.getId(), IdentityZoneHolder.get().getId()));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) UserAccountStatus(org.cloudfoundry.identity.uaa.account.UserAccountStatus) Test(org.junit.jupiter.api.Test)

Example 28 with ScimUser

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

the class ScimUserEndpointsMockMvcTests method updateUser.

private ScimUser updateUser(String token, int status) throws Exception {
    ScimUserProvisioning usersRepository = webApplicationContext.getBean(ScimUserProvisioning.class);
    String email = "otheruser@" + generator.generate().toLowerCase() + ".com";
    ScimUser user = new ScimUser(null, email, "Other", "User");
    user.addEmail(email);
    user = usersRepository.createUser(user, "pas5Word", IdentityZoneHolder.get().getId());
    if (status == HttpStatus.BAD_REQUEST.value()) {
        user.setUserName(null);
    } else {
        String username2 = "ou" + generator.generate().toLowerCase();
        user.setUserName(username2);
    }
    user.setName(new ScimUser.Name("Joe", "Smith"));
    return updateUser(token, status, user);
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ScimUserProvisioning(org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning)

Example 29 with ScimUser

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

the class ScimUserEndpointsMockMvcTests method verification_link_secured_with_scimcreate.

@Test
void verification_link_secured_with_scimcreate() throws Exception {
    ScimUser joel = setUpScimUser();
    MockHttpServletRequestBuilder get = setUpVerificationLinkRequest(joel, scimReadWriteToken);
    mockMvc.perform(get).andExpect(status().isForbidden());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 30 with ScimUser

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

the class ScimUserEndpointsMockMvcTests method createUser.

private ScimUser createUser(ScimUser user, String token, String subdomain, String switchZone) throws Exception {
    String password = hasText(user.getPassword()) ? user.getPassword() : "pas5word";
    user.setPassword(password);
    MvcResult result = createUserAndReturnResult(user, token, subdomain, switchZone).andExpect(status().isCreated()).andExpect(header().string("ETag", "\"0\"")).andExpect(jsonPath("$.userName").value(user.getUserName())).andExpect(jsonPath("$.emails[0].value").value(user.getUserName())).andExpect(jsonPath("$.name.familyName").value(user.getFamilyName())).andExpect(jsonPath("$.name.givenName").value(user.getGivenName())).andReturn();
    user = JsonUtils.readValue(result.getResponse().getContentAsString(), ScimUser.class);
    user.setPassword(password);
    return user;
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MvcResult(org.springframework.test.web.servlet.MvcResult)

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