use of io.jans.scim.model.scim2.annotations.Attribute 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.annotations.Attribute 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.annotations.Attribute in project jans by JanssenProject.
the class AverageUserTest method updateWithObject1.
@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject1() throws Exception {
UserResource clone = getDeepCloneUsr(user);
clone.setPreferredLanguage("en_US");
clone.getPhoneNumbers().remove(0);
// Means no change
clone.setAddresses(null);
// Means role will have to disappear
clone.setRoles(new ArrayList<>());
Group group = new Group();
group.setValue("Dummy ID");
// will be ignored: group membership changes MUST be applied via /Groups endpoint
clone.setGroups(Collections.singletonList(group));
logger.debug("Updating user {}", clone.getUserName());
Response response = client.updateUser(clone, clone.getId(), null, "meta");
assertEquals(response.getStatus(), OK.getStatusCode());
user = response.readEntity(usrClass);
assertNotNull(user.getPreferredLanguage());
assertEquals(user.getPreferredLanguage(), clone.getPreferredLanguage());
assertEquals(user.getPhoneNumbers().size(), clone.getPhoneNumbers().size());
assertFalse(user.getAddresses().isEmpty());
assertNull(user.getRoles());
assertNull(user.getGroups());
logger.debug("Updated user {}", user.getName().getGivenName());
// Double check update did take update in the original source (eg. LDAP):
String json = response.readEntity(String.class);
response = client.getUserById(clone.getId(), null, "meta");
// both json contents should be the same since meta attribute was removed and serialization involves UserResource class
assertEquals(json, response.readEntity(String.class));
}
use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class FidoU2fDeviceTest method updateWithObject.
@Test(dependsOnMethods = "updateWithJson")
public void updateWithObject() throws Exception {
logger.debug("Updating device to original attributes");
Response response = client.updateDevice(device, device.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
FidoDeviceResource updated = response.readEntity(fidoClass);
// Naively compare (property-to-property) the original and new object. It's feasible since all of them are strings
for (String path : IntrospectUtil.allAttrs.get(fidoClass)) {
String val = BeanUtils.getProperty(device, path);
// Exclude metas since they diverge and skip if original attribute was null (when passing null for an update, server ignores)
if (!path.startsWith("meta") && val != null)
assertEquals(BeanUtils.getProperty(updated, path), val);
}
// Update an immutable attribute (originally null). Per spec, uninitialized immutable attributes can be set
assertNull(updated.getDeviceData());
updated.setDeviceData("Dummy device data");
response = client.updateDevice(updated, updated.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
updated = response.readEntity(fidoClass);
assertNotNull(updated.getDeviceData());
// NOTE: if you don't see device data attribute for this device in LDAP is because the attribute is marked as being
// ignored upon update (see io.jans.scim.model.fido.GluuCustomFidoDevice)
}
use of io.jans.scim.model.scim2.annotations.Attribute in project jans by JanssenProject.
the class PairwiseIdentifiersTest method queryAndRemoval.
@Test
public void queryAndRemoval() throws Exception {
// Get a list (of at most 1 user) who has a persisted pairwise identifier
Response response = client.searchUsers("pairwiseIdentifiers pr", null, 1, null, null, "pairwiseIdentifiers, id", null);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse lr = response.readEntity(ListResponse.class);
// If the list is empty do nothing (successful test)
if (lr.getItemsPerPage() > 0) {
UserResource user = (UserResource) lr.getResources().get(0);
assertNotNull(user.getPairwiseIdentifiers());
// Prepare the removal of the user's PPIDs
PatchOperation operation = new PatchOperation();
operation.setOperation("remove");
operation.setPath("pairwiseIdentitifers");
PatchRequest pr = new PatchRequest();
pr.setOperations(Collections.singletonList(operation));
response = client.patchUser(pr, user.getId(), "pairwiseIdentifiers", null);
assertEquals(response.getStatus(), OK.getStatusCode());
// Ensure they are not there anymore.
user = response.readEntity(UserResource.class);
assertNull(user.getPairwiseIdentifiers());
// This test does not guarantee the ou=pairwiseIdentifiers sub-branch disappears... only the jsPPID LDAP attribute
}
}
Aggregations