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