use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.
the class Scim2UserService method transferExtendedAttributesToPerson.
/**
* Takes all extended attributes found in the SCIM resource and copies them to a
* ScimCustomPerson This method is called after validations take place (see
* associated decorator for User Service), so all inputs are OK and can go
* straight to LDAP with no runtime surprises
*
* @param resource
* A SCIM resource used as origin of data
* @param person
* a ScimCustomPerson used as destination
*/
private void transferExtendedAttributesToPerson(BaseScimResource resource, ScimCustomPerson person) {
try {
// Gets all the extended attributes for this resource
Map<String, Object> extendedAttrs = resource.getCustomAttributes();
// Iterates over all extensions this type of resource might have
for (Extension extension : extService.getResourceExtensions(resource.getClass())) {
Object val = extendedAttrs.get(extension.getUrn());
if (val != null) {
// Obtains the attribute/value(s) pairs in the current extension
Map<String, Object> attrsMap = IntrospectUtil.strObjMap(val);
for (String attribute : attrsMap.keySet()) {
Object value = attrsMap.get(attribute);
if (value == null) {
// Attribute was unassigned in this resource: drop it from destination too
log.debug("transferExtendedAttributesToPerson. Flushing attribute {}", attribute);
person.setAttribute(attribute, (String) null);
} else {
ExtensionField field = extension.getFields().get(attribute);
if (field.isMultiValued()) {
person.setCustomAttribute(attribute, extService.getAttributeValues(field, (Collection) value, ldapBackend));
} else {
person.setCustomAttribute(attribute, extService.getAttributeValue(field, value, ldapBackend));
}
log.debug("transferExtendedAttributesToPerson. Setting attribute '{}' with values {}", attribute, person.getTypedAttribute(attribute).getDisplayValue());
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.
the class Scim2UserService method transferExtendedAttributesToResource.
private void transferExtendedAttributesToResource(ScimCustomPerson person, BaseScimResource resource) {
log.debug("transferExtendedAttributesToResource of type {}", ScimResourceUtil.getType(resource.getClass()));
// Gets the list of extensions associated to the resource passed. In practice,
// this will be at most a singleton list
List<Extension> extensions = extService.getResourceExtensions(resource.getClass());
// resource
for (Extension extension : extensions) {
Map<String, ExtensionField> fields = extension.getFields();
// Create empty map to store the values of the extended attributes found for
// current extension in object person
Map<String, Object> map = new HashMap<>();
log.debug("transferExtendedAttributesToResource. Revising attributes of extension '{}'", extension.getUrn());
// Iterate over every attribute part of this extension
for (String attr : fields.keySet()) {
// Gets the values associated to this attribute that were found in LDAP
String[] values = person.getAttributes(attr);
if (values != null) {
log.debug("transferExtendedAttributesToResource. Copying to resource the value(s) for attribute '{}'", attr);
ExtensionField field = fields.get(attr);
List<Object> convertedValues = extService.convertValues(field, values, ldapBackend);
if (convertedValues.size() > 0) {
map.put(attr, field.isMultiValued() ? convertedValues : convertedValues.get(0));
}
}
}
// Stores all extended attributes (with their values) in the resource object
if (map.size() > 0) {
resource.addCustomAttributes(extension.getUrn(), map);
}
}
for (String urn : resource.getCustomAttributes().keySet()) {
resource.getSchemas().add(urn);
}
}
use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.
the class SearchResourcesWebService method getListResponseTree.
/**
* Returns a JsonNode with the response obtained from sending a POST to a search method given the SearchRequest passed
* @param index Determines the concrete search method to be executed: (0 - user; 1 - group; 2 - fido device)
* @param searchRequest
* @return
*/
private JsonNode getListResponseTree(int index, SearchRequest searchRequest) {
try {
log.debug("getListResponseTree. Resource type is: {}", ScimResourceUtil.getType(resourceClasses[index]));
Response r = null;
switch(index) {
case 0:
r = userWS.searchUsersPost(searchRequest);
break;
case 1:
r = groupWS.searchGroupsPost(searchRequest);
break;
case 2:
r = fidoWS.searchDevicesPost(searchRequest, null);
break;
case 3:
r = fido2WS.searchF2DevicesPost(searchRequest, null);
break;
}
if (r.getStatus() != OK.getStatusCode())
throw new Exception("Intermediate POST search returned " + r.getStatus());
// readEntity does not work here since data is not backed by an input stream, so we just get the raw entity
String jsonStr = r.getEntity().toString();
return mapper.readTree(jsonStr);
} catch (Exception e) {
log.error("Error in getListResponseTree {}", e.getMessage());
log.error(e.getMessage(), e);
return null;
}
}
use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.
the class SimpleSearchUserTest method searchNoMatches.
@Test(dependsOnMethods = "create", groups = "search")
public void searchNoMatches() {
String nowIsoDateTimeString = Instant.ofEpochMilli(System.currentTimeMillis()).toString();
SearchRequest sr = new SearchRequest();
sr.setFilter(String.format("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomThird eq 1 and displayName eq \"%s\" " + "and addresses[postalCode ne null or type eq null] and meta.lastModified gt \"%s\"", "test", nowIsoDateTimeString));
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
assertNull(listResponse.getResources());
}
use of io.jans.scim.model.scim2.AttributeDefinition.Type in project jans by JanssenProject.
the class PatchValueFilterUserTest method objectPatch.
@Test(dependsOnMethods = "patch")
public void objectPatch() {
PatchRequest request = new PatchRequest();
request.setOperations(new ArrayList<>());
PatchOperation del = new PatchOperation();
del.setOperation("remove");
del.setPath("emails[type sw \"hobby\"]");
request.getOperations().add(del);
del = new PatchOperation();
del.setOperation("remove");
del.setPath("phoneNumbers[primary pr or value co \" \"].type");
request.getOperations().add(del);
del = new PatchOperation();
del.setOperation("remove");
del.setPath("addresses[region eq \"somewhere\" and primary ne true].locality");
request.getOperations().add(del);
Response response = client.patchUser(request, user.getId(), null, null);
assertEquals(response.getStatus(), OK.getStatusCode());
user = response.readEntity(usrClass);
assertNull(user.getEmails());
assertTrue(user.getPhoneNumbers().stream().allMatch(ph -> ph.getType() == null));
// No change in addresses
assertEquals(user.getAddresses().size(), 1);
assertNull(user.getAddresses().get(0).getLocality());
}
Aggregations