Search in sources :

Example 51 with UserResource

use of io.jans.scim.model.scim2.user.UserResource 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)

Example 52 with UserResource

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

the class Scim2UserService method buildUserResource.

public UserResource buildUserResource(ScimCustomPerson person, String url) {
    if (externalScimService.isEnabled() && !externalScimService.executeScimGetUserMethods(person)) {
        throw new WebApplicationException("Failed to execute SCIM script successfully", Status.PRECONDITION_FAILED);
    }
    UserResource user = new UserResource();
    transferAttributesToUserResource(person, user, url);
    return user;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) UserResource(io.jans.scim.model.scim2.user.UserResource)

Example 53 with UserResource

use of io.jans.scim.model.scim2.user.UserResource 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)

Example 54 with UserResource

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

the class QueryParamRetrievalTest method multipleRetrieval.

@Test
public void multipleRetrieval() {
    logger.debug("Retrieving test users...");
    String include = "displayName, externalId";
    Response response = client.searchUsers("displayName co \"Test\"", null, null, null, null, include, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    List<UserResource> list = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList());
    // Verify users retrieved contain attributes of interest
    for (UserResource usr : list) {
        assertNotNull(usr.getDisplayName());
        assertTrue(usr.getDisplayName().toLowerCase().contains("test"));
    // assertNotNull(usr.getExternalId());
    }
}
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) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 55 with UserResource

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

the class QueryParamRetrievalTest method multipleRetrievalExcluding.

@Test(dependsOnMethods = "multipleRetrieval")
public void multipleRetrievalExcluding() {
    logger.debug("Retrieving test users...");
    String exclude = "displayName, externalId, name, addresses, emails";
    Response response = client.searchUsers("displayName co \"Test\"", null, null, null, null, null, exclude);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    List<UserResource> list = listResponse.getResources().stream().map(UserResource.class::cast).collect(Collectors.toList());
    // Verify users retrieved do not contain attributes of interest
    for (UserResource usr : list) {
        assertNull(usr.getDisplayName());
        assertNull(usr.getExternalId());
        assertNull(usr.getName());
        assertNull(usr.getAddresses());
        assertNull(usr.getEmails());
        assertNotNull(usr.getSchemas());
        assertNotNull(usr.getId());
    }
    user = list.get(0);
}
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) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

UserResource (io.jans.scim.model.scim2.user.UserResource)49 Response (javax.ws.rs.core.Response)47 Test (org.testng.annotations.Test)37 UserBaseTest (io.jans.scim2.client.UserBaseTest)34 ListResponse (io.jans.scim.model.scim2.ListResponse)21 SearchRequest (io.jans.scim.model.scim2.SearchRequest)14 Parameters (org.testng.annotations.Parameters)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)7 Path (javax.ws.rs.Path)7 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)6 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)6 SkipTest (io.jans.scim2.listener.SkipTest)6 URI (java.net.URI)6 DefaultValue (javax.ws.rs.DefaultValue)6 HeaderParam (javax.ws.rs.HeaderParam)6 Status (javax.ws.rs.core.Response.Status)6 BeforeTest (org.testng.annotations.BeforeTest)6 ScimCustomPerson (io.jans.scim.model.scim.ScimCustomPerson)5 GroupResource (io.jans.scim.model.scim2.group.GroupResource)5 PatchRequest (io.jans.scim.model.scim2.patch.PatchRequest)5