Search in sources :

Example 11 with UserResource

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

the class GroupAssignUserTest method getDummyPatient.

private UserResource getDummyPatient() {
    UserResource user = new UserResource();
    user.setUserName("test-" + Math.random());
    user.setDisplayName(user.getUserName());
    return user;
}
Also used : UserResource(io.jans.scim.model.scim2.user.UserResource)

Example 12 with UserResource

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

the class PatchGroupTest method patch2.

@Test(dependsOnMethods = "patch1")
public void patch2() throws Exception {
    List<UserResource> users = getTestUsers("aaa");
    assertTrue(users.size() > 0);
    // Define one "add" operation to insert the users retrieved in the created group
    PatchOperation operation = new PatchOperation();
    operation.setOperation("add");
    operation.setPath("members");
    List<Member> memberList = new ArrayList<>();
    users.stream().forEach(u -> {
        Member m = new Member();
        m.setType(ScimResourceUtil.getType(usrClass));
        m.setValue(u.getId());
        m.setDisplay(u.getDisplayName());
        m.setRef("/scim/v2/Users/" + u.getId());
        memberList.add(m);
    });
    operation.setValue(memberList);
    // Apply the patch to the group
    PatchRequest pr = new PatchRequest();
    pr.setOperations(Collections.singletonList(operation));
    Response response = client.patchGroup(pr, group.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    group = response.readEntity(groupCls);
    // Verify the new users are there
    Set<Member> members = group.getMembers();
    assertNotNull(members);
    assertTrue(members.stream().allMatch(m -> m.getDisplay() != null && m.getType() != null && m.getValue() != null && m.getRef() != null));
    // Verify the Ids are the same (both provided and returned)
    Set<String> userIds = users.stream().map(UserResource::getId).collect(Collectors.toSet());
    assertTrue(members.stream().map(Member::getValue).collect(Collectors.toSet()).equals(userIds));
}
Also used : Response(javax.ws.rs.core.Response) Member(io.jans.scim.model.scim2.group.Member) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) Set(java.util.Set) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest) Collectors(java.util.stream.Collectors) ScimResourceUtil(io.jans.scim.model.scim2.util.ScimResourceUtil) ArrayList(java.util.ArrayList) GroupResource(io.jans.scim.model.scim2.group.GroupResource) List(java.util.List) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) Parameters(org.testng.annotations.Parameters) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) io.jans.scim.model.scim2(io.jans.scim.model.scim2) Collections(java.util.Collections) Status(javax.ws.rs.core.Response.Status) UserResource(io.jans.scim.model.scim2.user.UserResource) PatchOperation(io.jans.scim.model.scim2.patch.PatchOperation) ArrayList(java.util.ArrayList) PatchRequest(io.jans.scim.model.scim2.patch.PatchRequest) Member(io.jans.scim.model.scim2.group.Member) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest)

Example 13 with UserResource

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

the class PatchUserExtTest method patchJson.

@Parameters({ "user_patch_ext" })
@Test(dependsOnMethods = "create")
public void patchJson(String patchRequest) {
    Response response = client.patchUser(patchRequest, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    // For help on usage of io.jans.scim.model.scim2.CustomAttributes class, read its api docs (oxtrust-scim maven project)
    CustomAttributes custAttrs = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify new items appeared in scimCustomSecond
    List<Date> scimCustomSecond = custAttrs.getValues("scimCustomSecond", Date.class);
    assertEquals(scimCustomSecond.size(), 6);
    // Verify change in value of scimCustomThird
    int scimCustomThird = custAttrs.getValue("scimCustomThird", Integer.class);
    assertEquals(1, scimCustomThird);
    // Verify scimCustomFirst disappeared
    assertNull(custAttrs.getValue("scimCustomFirst", String.class));
    // Verify some others disappeared too
    assertNull(other.getAddresses().get(0).getType());
    assertNull(other.getName().getGivenName());
    Stream<String> types = other.getPhoneNumbers().stream().map(PhoneNumber::getType);
    assertTrue(types.map(Optional::ofNullable).noneMatch(Optional::isPresent));
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) UserResource(io.jans.scim.model.scim2.user.UserResource) PhoneNumber(io.jans.scim.model.scim2.user.PhoneNumber) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Example 14 with UserResource

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

the class ComplexSearchUserTest method searchSortByExternalId.

@Test
public void searchSortByExternalId() {
    Response response = client.searchUsers(null, null, null, "externalId", "descending", "externalId", null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    ListResponse listResponse = response.readEntity(ListResponse.class);
    UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
    assertEquals(listResponse.getStartIndex(), 1);
    assertEquals(listResponse.getItemsPerPage(), users.length);
    assertEquals(listResponse.getResources().size(), users.length);
    for (int i = 1; i < users.length; i++) {
        String exId1 = users[i - 1].getExternalId();
        String exId2 = users[i].getExternalId();
        if (exId2 != null)
            assertNotNull(exId1);
        if (exId1 == null)
            assertNull(exId2);
        if (// In descending order exId1 must be higher than exId2
        exId1 != null && exId2 != null)
            assertFalse(exId1.compareTo(exId2) < 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)

Example 15 with UserResource

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

the class SampleTest method smallerClient.

// This tests assumes client_secret_basic for token endpoint authentication
@Test
@Parameters({ "domainURL", "OIDCMetadataUrl", "clientId", "clientSecret" })
public void smallerClient(String domainURL, String OIDCMetadataUrl, String clientId, String clientSecret) throws Exception {
    IUserWebService myclient = ScimClientFactory.getClient(IUserWebService.class, domainURL, OIDCMetadataUrl, clientId, clientSecret, false);
    SearchRequest sr = new SearchRequest();
    sr.setFilter("userName eq \"admin\"");
    Response response = myclient.searchUsersPost(sr);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource u = (UserResource) response.readEntity(ListResponse.class).getResources().get(0);
    logger.debug("Hello {}!", u.getDisplayName());
}
Also used : Response(javax.ws.rs.core.Response) IUserWebService(io.jans.scim.ws.rs.scim2.IUserWebService) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) 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