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;
}
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));
}
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);
}
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;
}
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);
}
Aggregations