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