Search in sources :

Example 1 with io.jans.scim.model.scim2

use of io.jans.scim.model.scim2 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 2 with io.jans.scim.model.scim2

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

the class FullUserTest method createFull.

@Parameters("user_full_create")
@Test(dependsOnGroups = "avgTestFinished")
public void createFull(String json) {
    logger.debug("Creating user from json...");
    user = createUserFromJson(json);
    // Confirm extended attrs info is there
    // For help on usage of io.jans.scim.model.scim2.CustomAttributes class, read its api docs (oxtrust-scim maven project)
    CustomAttributes custAttrs = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
    assertNotNull(custAttrs.getValue("scimCustomFirst", String.class));
    assertNotNull(custAttrs.getValues("scimCustomSecond", Date.class));
    assertNotNull(custAttrs.getValue("scimCustomThird", Integer.class));
    assertEquals(custAttrs.getValues("scimCustomSecond", Date.class).size(), 1);
}
Also used : CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest)

Example 3 with io.jans.scim.model.scim2

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

the class ScimResourceUtil method deleteFromResource.

/**
 * Returns a SCIM resource with the same data found in <code>origin</code> object, except for the attribute referenced
 * by <code>path</code> being removed from the output. In other words, this method nullifies an attribute.
 * @param origin The resource having the the original data
 * @param path An attribute path (in dot notation). Examples could be: <code>displayName, emails.type, addresses,
 *             meta.lastModified</code>.
 * @param extensions A list of <code>Extension</code>s associated to <code>origin</code> Object
 * @return The resulting object: data in origin without the attribute referenced by <code>path</code>
 * @throws InvalidAttributeValueException If there is an attempt to remove an attribute annotated as {@link Attribute#isRequired()
 * required} or {@link io.jans.scim.model.scim2.AttributeDefinition.Mutability#READ_ONLY read-only}
 */
public static BaseScimResource deleteFromResource(BaseScimResource origin, String path, List<Extension> extensions) throws InvalidAttributeValueException {
    Field f = IntrospectUtil.findFieldFromPath(origin.getClass(), path);
    if (f != null) {
        Attribute attrAnnot = f.getAnnotation(Attribute.class);
        if (attrAnnot != null && (attrAnnot.mutability().equals(READ_ONLY) || attrAnnot.isRequired()))
            throw new InvalidAttributeValueException("Cannot remove read-only or required attribute " + path);
    }
    Map<String, Object> map = mapper.convertValue(origin, new TypeReference<Map<String, Object>>() {
    });
    traversalClass tclass = new traversalClass(origin.getClass());
    if (// Extensions stuff
    f == null)
        deleteCustomAttribute(map, path, extensions);
    else
        tclass.traverseDelete(map, path);
    return mapper.convertValue(map, origin.getClass());
}
Also used : ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) Field(java.lang.reflect.Field) Attribute(io.jans.scim.model.scim2.annotations.Attribute) InvalidAttributeValueException(javax.management.InvalidAttributeValueException)

Example 4 with io.jans.scim.model.scim2

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

the class QueryParamCreateUpdateTest method update1.

@Test(dependsOnMethods = "create2")
public void update1() throws Exception {
    // Change some attributes existing in user object
    UserResource cheapClone = getDeepCloneUsr(user);
    cheapClone.getName().setGivenName("Bavara");
    cheapClone.setNickName("Cloned");
    String rndString = Double.toString(Math.random());
    // For help on usage of io.jans.scim.model.scim2.CustomAttributes class, read its api docs (oxtrust-scim maven project)
    CustomAttributes custAttrs = cheapClone.getCustomAttributes(USER_EXT_SCHEMA_ID);
    custAttrs.setAttribute("scimCustomFirst", rndString);
    String include = "userName, name.givenName, nickName, urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomFirst";
    Response response = client.updateUser(cheapClone, cheapClone.getId(), include, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    user = response.readEntity(usrClass);
    assertNull(user.getDisplayName());
    assertEquals(user.getName().getGivenName(), cheapClone.getName().getGivenName());
    assertEquals(user.getNickName(), cheapClone.getNickName());
    custAttrs = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
    assertNull(custAttrs.getValues("scimCustomSecond", Date.class));
    assertNull(custAttrs.getValue("scimCustomThird", Integer.class));
    assertEquals(custAttrs.getValue("scimCustomFirst", String.class), rndString);
}
Also used : Response(javax.ws.rs.core.Response) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) UserResource(io.jans.scim.model.scim2.user.UserResource) Date(java.util.Date) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test)

Aggregations

CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)3 UserBaseTest (io.jans.scim2.client.UserBaseTest)3 Test (org.testng.annotations.Test)3 UserResource (io.jans.scim.model.scim2.user.UserResource)2 Response (javax.ws.rs.core.Response)2 Parameters (org.testng.annotations.Parameters)2 Attribute (io.jans.scim.model.scim2.annotations.Attribute)1 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)1 PhoneNumber (io.jans.scim.model.scim2.user.PhoneNumber)1 SkipTest (io.jans.scim2.listener.SkipTest)1 Field (java.lang.reflect.Field)1 Date (java.util.Date)1 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)1