Search in sources :

Example 36 with Attribute

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);
}
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 37 with Attribute

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);
}
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 38 with Attribute

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));
}
Also used : Response(javax.ws.rs.core.Response) Group(io.jans.scim.model.scim2.user.Group) UserResource(io.jans.scim.model.scim2.user.UserResource) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 39 with Attribute

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)
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 40 with Attribute

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
    }
}
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) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Aggregations

Response (javax.ws.rs.core.Response)19 UserResource (io.jans.scim.model.scim2.user.UserResource)13 ListResponse (io.jans.scim.model.scim2.ListResponse)12 Test (org.testng.annotations.Test)12 SCIMException (io.jans.scim.model.exception.SCIMException)11 Attribute (io.jans.scim.model.scim2.annotations.Attribute)11 Field (java.lang.reflect.Field)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)11 Attribute (org.gluu.oxtrust.model.scim2.annotations.Attribute)11 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)10 Extension (io.jans.scim.model.scim2.extensions.Extension)9 UserBaseTest (io.jans.scim2.client.UserBaseTest)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)5 NullType (javax.lang.model.type.NullType)5 Path (javax.ws.rs.Path)5 SearchRequest (io.jans.scim.model.scim2.SearchRequest)4 ProtectedApi (io.jans.scim.service.filter.ProtectedApi)4 RefAdjusted (io.jans.scim.service.scim2.interceptor.RefAdjusted)4 BaseTest (io.jans.scim2.client.BaseTest)4 URI (java.net.URI)4