Search in sources :

Example 1 with USER_EXT_SCHEMA_ID

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

the class ExtensionService method getResourceExtensions.

public List<Extension> getResourceExtensions(Class<? extends BaseScimResource> cls) {
    List<Extension> list = new ArrayList<>();
    try {
        // Currently support one extension only for User Resource
        if (cls.equals(UserResource.class)) {
            Map<String, ExtensionField> fields = new HashMap<>();
            for (GluuAttribute attribute : attributeService.getSCIMRelatedAttributes()) {
                if (Optional.ofNullable(attribute.getScimCustomAttr()).orElse(false)) {
                    // first non-null check is needed because certain entries do not have the multivalue attribute set
                    ExtensionField field = new ExtensionField();
                    field.setDescription(attribute.getDescription());
                    field.setType(attribute.getDataType());
                    field.setMultiValued(Optional.ofNullable(attribute.getOxMultiValuedAttribute()).orElse(false));
                    field.setName(attribute.getName());
                    fields.put(attribute.getName(), field);
                }
            }
            String uri = appConfiguration.getUserExtensionSchemaURI();
            if (StringUtils.isEmpty(uri)) {
                uri = USER_EXT_SCHEMA_ID;
            }
            Extension ext = new Extension(uri);
            ext.setFields(fields);
            if (uri.equals(USER_EXT_SCHEMA_ID)) {
                ext.setName(USER_EXT_SCHEMA_NAME);
                ext.setDescription(USER_EXT_SCHEMA_DESCRIPTION);
            }
            list.add(ext);
        }
    } catch (Exception e) {
        log.error("An error ocurred when building extension for {}", cls.getName());
        log.error(e.getMessage(), e);
    }
    return list;
}
Also used : Extension(io.jans.scim.model.scim2.extensions.Extension) ExtensionField(io.jans.scim.model.scim2.extensions.ExtensionField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GluuAttribute(io.jans.model.GluuAttribute)

Example 2 with USER_EXT_SCHEMA_ID

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

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

the class SchemasTest method inspectUserExtensionSchema.

@Test(dependsOnMethods = "checkSchemasExistence")
public void inspectUserExtensionSchema() {
    Optional<SchemaResource> userExtSchemaOpt = listResponse.getResources().stream().map(SchemaResource.class::cast).filter(sr -> sr.getId().contains(USER_EXT_SCHEMA_ID)).findFirst();
    if (userExtSchemaOpt.isPresent()) {
        String name = userExtSchemaOpt.get().getName();
        assertNotNull(name);
        logger.info("Found User Schema Extension: {}", name);
        Boolean[] foundAttr = new Boolean[3];
        for (SchemaAttribute attribute : userExtSchemaOpt.get().getAttributes()) {
            switch(attribute.getName()) {
                case "scimCustomFirst":
                    foundAttr[0] = true;
                    logger.info("scimCustomFirst found");
                    assertEquals(attribute.getType(), "string");
                    assertFalse(attribute.isMultiValued());
                    break;
                case "scimCustomSecond":
                    foundAttr[1] = true;
                    logger.info("scimCustomSecond found");
                    assertEquals(attribute.getType(), "dateTime");
                    assertTrue(attribute.isMultiValued());
                    break;
                case "scimCustomThird":
                    foundAttr[2] = true;
                    logger.info("scimCustomThird found");
                    assertEquals(attribute.getType(), "decimal");
                    assertFalse(attribute.isMultiValued());
                    break;
            }
        }
        Arrays.asList(foundAttr).forEach(org.testng.Assert::assertTrue);
    } else
        logger.warn("There is no Schema Resource associated to User Schema Extension ({})", USER_EXT_SCHEMA_ID);
}
Also used : Arrays(java.util.Arrays) UserResource(io.jans.scim.model.scim2.user.UserResource) USER_EXT_SCHEMA_ID(io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource) ScimResourceUtil(io.jans.scim.model.scim2.util.ScimResourceUtil) ArrayList(java.util.ArrayList) GroupResource(io.jans.scim.model.scim2.group.GroupResource) BaseScimResource(io.jans.scim.model.scim2.BaseScimResource) BeforeTest(org.testng.annotations.BeforeTest) List(java.util.List) Fido2DeviceResource(io.jans.scim.model.scim2.fido.Fido2DeviceResource) Response(javax.ws.rs.core.Response) Assert(org.testng.Assert) ListResponse(io.jans.scim.model.scim2.ListResponse) Optional(java.util.Optional) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) FidoDeviceResource(io.jans.scim.model.scim2.fido.FidoDeviceResource) Assert(org.testng.Assert) SchemaAttribute(io.jans.scim.model.scim2.provider.schema.SchemaAttribute) SchemaResource(io.jans.scim.model.scim2.provider.schema.SchemaResource) Test(org.testng.annotations.Test) BaseTest(io.jans.scim2.client.BaseTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with USER_EXT_SCHEMA_ID

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

the class FullUserTest method update.

@Parameters("user_full_update")
@Test(dependsOnMethods = "createFull")
public void update(String json) {
    logger.debug("Updating user {} with json", user.getUserName());
    Response response = client.updateUser(json, user.getId(), null, null);
    assertEquals(response.getStatus(), OK.getStatusCode());
    UserResource other = response.readEntity(usrClass);
    CustomAttributes custAttrs1 = user.getCustomAttributes(USER_EXT_SCHEMA_ID);
    CustomAttributes custAttrs2 = other.getCustomAttributes(USER_EXT_SCHEMA_ID);
    // Verify scimCustomFirst changed
    assertNotEquals(custAttrs1.getValue("scimCustomFirst", String.class), custAttrs2.getValue("scimCustomFirst", String.class));
    // Verify a new scimCustomSecond value
    List<Date> col1 = custAttrs1.getValues("scimCustomSecond", Date.class);
    List<Date> col2 = custAttrs2.getValues("scimCustomSecond", Date.class);
    assertNotEquals(col1.size(), col2.size());
    // Verify scimCustomThird is the same
    assertEquals(custAttrs1.getValue("scimCustomThird", Integer.class), custAttrs2.getValue("scimCustomThird", Integer.class));
    // Verify change in emails, addresses and phoneNumbers
    assertNotEquals(user.getEmails().size(), other.getEmails().size());
    assertNotEquals(user.getAddresses().size(), other.getAddresses().size());
    assertNotEquals(user.getPhoneNumbers().size(), other.getPhoneNumbers().size());
    // Verify x509Certificates disappeared
    assertNull(other.getX509Certificates());
    // Verify no change in user type
    assertEquals(user.getUserType(), other.getUserType());
    user = other;
}
Also used : Response(javax.ws.rs.core.Response) ListResponse(io.jans.scim.model.scim2.ListResponse) CustomAttributes(io.jans.scim.model.scim2.CustomAttributes) UserResource(io.jans.scim.model.scim2.user.UserResource) Parameters(org.testng.annotations.Parameters) UserBaseTest(io.jans.scim2.client.UserBaseTest) Test(org.testng.annotations.Test) SkipTest(io.jans.scim2.listener.SkipTest)

Example 5 with USER_EXT_SCHEMA_ID

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

Aggregations

Test (org.testng.annotations.Test)8 CustomAttributes (io.jans.scim.model.scim2.CustomAttributes)7 UserBaseTest (io.jans.scim2.client.UserBaseTest)7 Response (javax.ws.rs.core.Response)7 UserResource (io.jans.scim.model.scim2.user.UserResource)6 ListResponse (io.jans.scim.model.scim2.ListResponse)3 SkipTest (io.jans.scim2.listener.SkipTest)3 Parameters (org.testng.annotations.Parameters)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Optional (java.util.Optional)2 GluuAttribute (io.jans.model.GluuAttribute)1 BaseScimResource (io.jans.scim.model.scim2.BaseScimResource)1 USER_EXT_SCHEMA_ID (io.jans.scim.model.scim2.Constants.USER_EXT_SCHEMA_ID)1 SearchRequest (io.jans.scim.model.scim2.SearchRequest)1 Extension (io.jans.scim.model.scim2.extensions.Extension)1 ExtensionField (io.jans.scim.model.scim2.extensions.ExtensionField)1 Fido2DeviceResource (io.jans.scim.model.scim2.fido.Fido2DeviceResource)1 FidoDeviceResource (io.jans.scim.model.scim2.fido.FidoDeviceResource)1 GroupResource (io.jans.scim.model.scim2.group.GroupResource)1