Search in sources :

Example 31 with SearchRequest

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

the class GroupsBulkTest method getAdminId.

private String getAdminId() {
    // Search the id of the admin user
    SearchRequest sr = new SearchRequest();
    sr.setFilter("userName eq \"admin\"");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), Status.OK.getStatusCode());
    ListResponse lr = response.readEntity(ListResponse.class);
    assertTrue(lr.getResources().size() > 0);
    return lr.getResources().get(0).getId();
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) BulkResponse(io.jans.scim.model.scim2.bulk.BulkResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) ListResponse(io.jans.scim.model.scim2.ListResponse)

Example 32 with SearchRequest

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

the class SimpleSearchUserTest method searchComplexAttrPost.

@Test(dependsOnMethods = "create", groups = "search")
public void searchComplexAttrPost() {
    String givenName = user.getName().getGivenName();
    logger.debug("Searching user with attribute givenName = {} using POST verb", givenName);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("name.givenName eq \"" + givenName + "\"");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    assertTrue(listResponse.getResources().size() > 0);
    // Retrieve first user in results
    UserResource other = listResponse.getResources().stream().map(usrClass::cast).findFirst().get();
    assertEquals(other.getName().getGivenName(), givenName);
}
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)

Example 33 with SearchRequest

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

the class SimpleSearchUserTest method searchComplexMultivaluedPost.

@Test(dependsOnMethods = "create", groups = "search")
public void searchComplexMultivaluedPost() {
    String ghost = user.getEmails().get(0).getValue();
    final String host = ghost.substring(ghost.indexOf("@") + 1);
    logger.debug("Searching user with attribute emails.value like {} or phone numbers with type unassigned or value containing '+' using POST verb", host);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("emails[value ew \"" + host + "\"] or urn:ietf:params:scim:schemas:core:2.0:User:phoneNumbers[value co \"+\" or type eq null]");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    assertTrue(listResponse.getResources().size() > 0);
    // Retrieve first user in results
    UserResource other = listResponse.getResources().stream().map(usrClass::cast).findFirst().get();
    boolean cond1 = false, cond2 = false, cond3 = false;
    if (other.getEmails() != null) {
        cond1 = other.getEmails().stream().anyMatch(mail -> mail.getValue().endsWith(host));
    }
    if (other.getPhoneNumbers() != null) {
        cond2 = other.getPhoneNumbers().stream().anyMatch(phone -> phone.getValue().contains("+"));
        cond3 = other.getPhoneNumbers().stream().anyMatch(phone -> phone.getType() == null);
    }
    assertTrue(cond1 || cond2 || cond3);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) UserBaseTest(io.jans.scim2.client.UserBaseTest) UserResource(io.jans.scim.model.scim2.user.UserResource) SearchRequest(io.jans.scim.model.scim2.SearchRequest) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) ListResponse(io.jans.scim.model.scim2.ListResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) Instant(java.time.Instant) Status(javax.ws.rs.core.Response.Status) 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)

Example 34 with SearchRequest

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

the class PaginationUserSearchTest method search1.

@Test
public void search1() {
    // Issue a default request except for a filter and reducing the attributes returned
    sr = new SearchRequest();
    sr.setFilter("name.familyName co \"Filter\"");
    // Couchbase result set order is not deterministic, requires ORDER BY to workaround it
    sr.setSortBy("id");
    sr.setAttributes("meta.location");
    Response response = client.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // Store for further comparison
    listResponse = response.readEntity(ListResponse.class);
    assertEquals(listResponse.getResources().size(), listResponse.getTotalResults());
}
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) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 35 with SearchRequest

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

the class FullUserTest method searchEscapingChars.

@SkipTest(databases = { "couchbase", "spanner" })
@Test(dependsOnMethods = "updateNonExisting", groups = "lastTests")
public void searchEscapingChars() {
    char quote = '"', backslash = '\\';
    String scapedQuote = String.valueOf(new char[] { backslash, quote });
    String scapedBkSlash = String.valueOf(new char[] { backslash, backslash });
    // Used to generate a random Unicode char
    String rnd = UUID.randomUUID().toString().substring(0, 4);
    String unicodeStr = String.valueOf(Character.toChars(Integer.parseInt(rnd, 16)));
    Name name = user.getName();
    name.setGivenName(String.format("with %cquotes%c", quote, quote));
    name.setMiddleName(String.format("with backslash %c", backslash));
    name.setFamilyName(String.format("%c %c %s", quote, backslash, unicodeStr));
    CustomAttributes attrs = new CustomAttributes(USER_EXT_SCHEMA_ID);
    attrs.setAttribute("scimCustomFirst", String.valueOf(quote));
    user.addCustomAttributes(attrs);
    Response response = client.updateUser(user, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    // => name.givenName co "\""
    String filter = String.format("name.givenName co %c%s%c", quote, scapedQuote, quote);
    // => and name.middleName ew "\\"
    filter += String.format(" and name.middleName ew %c%s%c", quote, scapedBkSlash, quote);
    String compValue = String.format("%s %s %cu%s", scapedQuote, scapedBkSlash, backslash, rnd);
    // => and name.familyName eq ""\ \\ \\uWXYZ"
    filter += String.format(" and name.familyName eq %c%s%c", quote, compValue, quote);
    String customFirst = String.format("%s:%s", USER_EXT_SCHEMA_ID, "scimCustomFirst");
    filter += String.format(" and %s eq %c%s%c", customFirst, quote, scapedQuote, quote);
    SearchRequest sr = new SearchRequest();
    sr.setFilter(filter);
    sr.setCount(1);
    sr.setAttributes("name, " + customFirst);
    response = client.searchUsersPost(sr);
    user = (UserResource) response.readEntity(ListResponse.class).getResources().get(0);
    assertEquals(name.getGivenName(), user.getName().getGivenName());
    assertEquals(name.getMiddleName(), user.getName().getMiddleName());
    assertEquals(name.getFamilyName(), user.getName().getFamilyName());
    // Verify the unicode character is intact
    compValue = user.getName().getFamilyName();
    // pick the last char
    compValue = compValue.substring(compValue.length() - 1);
    assertEquals(unicodeStr, compValue);
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) SearchRequest(io.jans.scim.model.scim2.SearchRequest) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) Name(io.jans.scim.model.scim2.user.Name) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest) SkipTest(io.jans.scim2.listener.SkipTest)

Aggregations

Response (javax.ws.rs.core.Response)31 SearchRequest (io.jans.scim.model.scim2.SearchRequest)23 ListResponse (io.jans.scim.model.scim2.ListResponse)21 Test (org.testng.annotations.Test)15 UserResource (io.jans.scim.model.scim2.user.UserResource)13 UserBaseTest (io.jans.scim2.client.UserBaseTest)13 SearchRequest (com.google.cloud.retail.v2.SearchRequest)7 SearchResponse (com.google.cloud.retail.v2.SearchResponse)7 SearchServiceClient (com.google.cloud.retail.v2.SearchServiceClient)7 URI (java.net.URI)6 SearchRequest (org.gluu.oxtrust.model.scim2.SearchRequest)6 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)5 SkipTest (io.jans.scim2.listener.SkipTest)5 SCIMException (io.jans.scim.model.exception.SCIMException)4 URISyntaxException (java.net.URISyntaxException)4 BeforeTest (org.testng.annotations.BeforeTest)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)2 GroupResource (io.jans.scim.model.scim2.group.GroupResource)2 Annotation (java.lang.annotation.Annotation)2