Search in sources :

Example 16 with UserResource

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

the class SpecialCharsTest method containabilityAllInGivenName.

@SkipTest(databases = { "spanner", "couchbase" })
@Test
public void containabilityAllInGivenName() {
    String filter = specialFilterLdapChars.stream().reduce("", (partial, next) -> partial + String.format(" and name.givenName co \"%s\"", next));
    SearchRequest sr = new SearchRequest();
    // Drop beginning (namely ' and ')
    sr.setFilter(filter.substring(5));
    sr.setAttributes("name");
    // Search users whose given names contain ALL the chars
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    List<UserResource> resources = response.readEntity(ListResponse.class).getResources().stream().map(UserResource.class::cast).collect(Collectors.toList());
    String givenName = resources.get(0).getName().getGivenName();
    assertEquals(resources.size(), 1);
    assertTrue(Stream.of(SPECIAL_CHARS).allMatch(givenName::contains));
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest) BeforeTest(org.testng.annotations.BeforeTest) SkipTest(io.jans.scim2.listener.SkipTest)

Example 17 with UserResource

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

the class SpecialCharsTest method containabilityAny.

@Test
public void containabilityAny() {
    // Builds a long "or" based clause
    String filter = specialFilterLdapChars.stream().reduce("", (partial, next) -> partial + String.format(" or userName co \"%s\"", next));
    SearchRequest sr = new SearchRequest();
    // Drop beginning (namely ' or ')
    sr.setFilter(filter.substring(4));
    sr.setAttributes("userName");
    // Search users whose usernames contain ANY of the chars
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    List<UserResource> resources = response.readEntity(ListResponse.class).getResources().stream().map(UserResource.class::cast).collect(Collectors.toList());
    assertTrue(resources.size() > 0);
    resources.forEach(user -> assertTrue(specialFilterLdapChars.stream().anyMatch(ch -> user.getUserName().contains(ch))));
    userNames = resources.stream().map(UserResource::getUserName).collect(Collectors.toList());
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 18 with UserResource

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

the class UserBaseTest method createUserFromJson.

public UserResource createUserFromJson(String json) {
    Response response = client.createUser(json, null, null);
    assertEquals(response.getStatus(), CREATED.getStatusCode());
    UserResource user = response.readEntity(usrClass);
    assertNotNull(user.getMeta());
    logger.debug("User created with id {}", user.getId());
    return user;
}
Also used : Response(javax.ws.rs.core.Response) UserResource(io.jans.scim.model.scim2.user.UserResource)

Example 19 with UserResource

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

the class SimpleSearchUserTest method searchSimpleAttrGet.

@Test(dependsOnMethods = "create", groups = "search")
public void searchSimpleAttrGet() {
    String isoDateString = user.getMeta().getCreated();
    String locale = user.getLocale();
    logger.debug("Searching user with attribute locale = {} and created date >= {} using GET verb", locale, isoDateString);
    Response response = client.searchUsers(String.format("locale eq \"%s\" and meta.created ge \"%s\"", locale, isoDateString), null, null, null, null, null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    assertTrue(listResponse.getResources().size() > 0);
    // Retrieve first user in results
    UserResource same = listResponse.getResources().stream().map(usrClass::cast).findFirst().get();
    assertEquals(same.getLocale(), locale);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) ListResponse(io.jans.scim.model.scim2.ListResponse) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 20 with UserResource

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

the class ComplexSearchUserTest method searchExcludedAttributesParam.

@Test
public void searchExcludedAttributesParam() {
    int count = 3;
    List<String> attrList = Arrays.asList("x509Certificates", "entitlements", "roles", "ims", "phoneNumbers", "addresses", "emails", "groups");
    logger.debug("Searching at most {} users using POST verb", count);
    logger.debug("Sorted by displayName ascending");
    logger.debug("Excluding the attributes {}", attrList);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("displayName pr");
    sr.setSortBy("displayName");
    sr.setSortOrder("descending");
    // Generate a string with the attributes to exclude
    sr.setExcludedAttributes(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);
        // Verify attributes were excluded
        for (UserResource u : users) {
            assertNull(u.getX509Certificates());
            assertNull(u.getEntitlements());
            assertNull(u.getRoles());
            assertNull(u.getIms());
            assertNull(u.getPhoneNumbers());
            assertNull(u.getAddresses());
            assertNull(u.getEmails());
        }
        boolean correctSorting = true;
        for (int i = 1; i < users.length && correctSorting; i++) {
            String displayName = users[i - 1].getDisplayName();
            String displayName2 = users[i].getDisplayName();
            // Check if second string is less or equal than first
            correctSorting = displayName.compareTo(displayName2) >= 0;
        }
        if (!correctSorting) {
            // LDAP may ignore case sensitivity, try again using lowercasing
            correctSorting = true;
            for (int i = 1; i < users.length && correctSorting; i++) {
                String displayName = users[i - 1].getDisplayName().toLowerCase();
                String displayName2 = users[i].getDisplayName().toLowerCase();
                // Check if second string is less or equal than first
                correctSorting = displayName.compareTo(displayName2) >= 0;
            }
        }
        assertTrue(correctSorting);
    }
}
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) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) 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