Search in sources :

Example 36 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class PatchAddUserTest method jsonPatch.

@Parameters({ "user_patchadd" })
@Test(dependsOnMethods = "createForAdd")
public void jsonPatch(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    assertNotNull(other.getNickName());
    assertNotNull(other.getUserType());
    assertTrue(user.getEmails().size() < other.getEmails().size());
    assertTrue(user.getPhoneNumbers().size() < other.getPhoneNumbers().size());
    assertTrue(other.getIms().size() > 0);
    assertTrue(other.getRoles().size() > 0);
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 37 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class PatchUserExtTest method patchObject.

@Test(dependsOnMethods = "patchJson")
public void patchObject() {
    PatchOperation operation = new PatchOperation();
    operation.setOperation("replace");
    operation.setPath("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomSecond");
    long now = System.currentTimeMillis();
    List<String> someDates = Arrays.asList(now, now + 1000, now + 2000, now + 3000).stream().map(DateUtil::millisToISOString).collect(Collectors.toList());
    operation.setValue(someDates);
    PatchRequest pr = new PatchRequest();
    pr.setOperations(Collections.singletonList(operation));
    Response response = client.patchUser(pr, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    CustomAttributes custAttrs = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify different dates appeared in scimCustomSecond
    List<Date> scimCustomSecond = custAttrs.getValues("scimCustomSecond", Date.class);
    assertEquals(scimCustomSecond.size(), someDates.size());
    assertEquals(now, scimCustomSecond.get(0).getTime());
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 38 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class ComplexSearchUserTest method searchNoAttributesParam.

@Test
public void searchNoAttributesParam() {
    final String ims = "Skype";
    logger.debug("Searching users with attribute nickName existent or ims.value={} using POST verb", ims);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("nickName pr or ims.value eq \"" + ims + "\"");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    if (listResponse.getResources() != null) {
        for (BaseScimResource resource : listResponse.getResources()) {
            UserResource other = (UserResource) resource;
            boolean c1 = other.getNickName() != null;
            boolean c2 = true;
            if (other.getIms() != null)
                c2 = other.getIms().stream().anyMatch(im -> im.getValue().toLowerCase().equals(ims.toLowerCase()));
            assertTrue(c1 || c2);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 39 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class ComplexSearchUserTest method searchAttributesParam.

@Test
public void searchAttributesParam() throws Exception {
    int count = 3;
    List<String> attrList = Arrays.asList("name.familyName", "active");
    logger.debug("Searching at most {} users using POST verb", count);
    logger.debug("Sorted by family name descending");
    logger.debug("Retrieving only the attributes {}", attrList);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("name.familyName pr");
    sr.setSortBy("name.familyName");
    sr.setSortOrder("descending");
    // Generate a string with the attributes desired to be returned separated by comma
    sr.setAttributes(attrList.toString().replaceFirst("\\[", "").replaceFirst("]", ""));
    sr.setCount(count);
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    if (listResponse.getResources().size() < count)
        logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
    else {
        // Obtain an array of results
        UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
        assertEquals(users.length, count);
        // Build a set of all attributes that should not appear in the response
        Set<String> check = new HashSet<>();
        check.addAll(IntrospectUtil.allAttrs.get(usrClass));
        // Remove from the ALL list, those requested plus its "parents"
        for (String attr : attrList) {
            String part = attr;
            for (int i = part.length(); i > 0; i = part.lastIndexOf(".")) {
                part = part.substring(0, i);
                check.remove(part);
            }
        }
        // Remove those that are ALWAYS present (per spec)
        check.removeAll(IntrospectUtil.alwaysCoreAttrs.get(usrClass).keySet());
        // Confirm for every user, those attributes are not there
        for (UserResource user : users) {
            for (String path : check) {
                String val = null;
                try {
                    val = BeanUtils.getProperty(user, path);
                } catch (NestedNullException nne) {
                // Intentionally left empty
                } finally {
                    assertNull(val);
                }
            }
        }
        boolean correctSorting = true;
        for (int i = 1; i < users.length && correctSorting; i++) {
            String familyName = users[i - 1].getName().getFamilyName();
            String familyName2 = users[i].getName().getFamilyName();
            // First string has to be greater than or equal second
            correctSorting = familyName.compareTo(familyName2) >= 0;
        }
        if (!correctSorting) {
            // LDAP may ignore case sensitivity, try again using lowercasing
            correctSorting = true;
            for (int i = 1; i < users.length && correctSorting; i++) {
                String familyName = users[i - 1].getName().getFamilyName().toLowerCase();
                String familyName2 = users[i].getName().getFamilyName().toLowerCase();
                // First string has to be greater than or equal second
                correctSorting = familyName.compareTo(familyName2) >= 0;
            }
        }
        assertTrue(correctSorting);
    }
}
Also used : SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) NestedNullException(org.apache.commons.beanutils.NestedNullException) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 40 with UserResource

use of io.jans.scim.model.scim2.user.UserResource in project jans by JanssenProject.

the class UpdatedUsersTest method creatingUsers.

@Test
public void creatingUsers() throws Exception {
    String isoDate = null;
    // pick a rand number in [0, N-1]
    int i = randInt(N);
    // Create N random users
    logger.info("Creating {} users", N);
    for (int j = 0; j < N; j++) {
        UserResource user = getDummyPatient();
        Response response = client.createUser(user, "meta.created", null);
        assertEquals(response.getStatus(), CREATED.getStatusCode());
        user = response.readEntity(usrClass);
        inums.add(user.getId());
        if (j == i) {
            isoDate = user.getMeta().getCreated();
        // logger.info("{}-indexed user created at '{}'", j, isoDate);
        }
    }
    // See #7
    Thread.sleep(1500);
    logger.info("Querying created users after '{}'", isoDate);
    Response response = client.usersChangedAfter(isoDate, 0, N);
    assertEquals(response.getStatus(), OK.getStatusCode());
    String json = response.readEntity(String.class);
    // Convert response into an opaque map
    Map<String, Object> map = mapper.readValue(json, new TypeReference<Map<String, Object>>() {
    });
    // There should be N - i results
    assertEquals(map.get("total"), N - i);
    Set<String> foundInums = getFoundInums(map);
    for (int j = 0; j < inums.size(); j++) {
        assertEquals(j >= i, foundInums.contains(inums.get(j)));
    }
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Aggregations

UserResource (io.jans.scim.model.scim2.user.UserResource)49 Response (javax.ws.rs.core.Response)47 Test (org.testng.annotations.Test)37 UserBaseTest (io.jans.scim2.client.UserBaseTest)34 ListResponse (io.jans.scim.model.scim2.ListResponse)21 SearchRequest (io.jans.scim.model.scim2.SearchRequest)14 Parameters (org.testng.annotations.Parameters)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Path (javax.ws.rs.Path)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)6 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)6 SkipTest (io.jans.scim2.listener.SkipTest)6 URI (java.net.URI)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Status (javax.ws.rs.core.Response.Status)6 BeforeTest (org.testng.annotations.BeforeTest)6 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)5 GroupResource (io.jans.scim.model.scim2.group.GroupResource)5 PatchRequest (io.jans.scim.model.scim2.patch.PatchRequest)5