in scim-server/src/main/java/org/apache/directory/scim/server/rest/AttributeUtil.java [92:136]
public <T extends ScimResource> T setAttributesForDisplay(T resource, Set<AttributeReference> attributes) throws AttributeException {
if (attributes.isEmpty()) {
return setAttributesForDisplay(resource);
} else {
T copy = cloneScimResource(resource);
String resourceType = copy.getResourceType();
Schema schema = schemaRegistry.getBaseSchemaOfResourceType(resourceType);
// return always and specified attributes, exclude never
Set<Attribute> attributesToKeep = resolveAttributeReferences(attributes, true);
Set<String> extensionsToRemove = new HashSet<>();
removeAttributesOfType(copy, schema, Returned.DEFAULT, attributesToKeep);
removeAttributesOfType(copy, schema, Returned.REQUEST, attributesToKeep);
removeAttributesOfType(copy, schema, Returned.NEVER);
for (Entry<String, ScimExtension> extensionEntry : copy.getExtensions().entrySet()) {
String extensionUrn = extensionEntry.getKey();
ScimExtension scimExtension = extensionEntry.getValue();
boolean removeExtension = true;
for (Attribute attributeToKeep : attributesToKeep) {
if (extensionUrn.equalsIgnoreCase(attributeToKeep.getSchemaUrn())) {
removeExtension = false;
break;
}
}
if (removeExtension) {
extensionsToRemove.add(extensionUrn);
continue;
}
Schema extensionSchema = schemaRegistry.getSchema(extensionUrn);
removeAttributesOfType(scimExtension, extensionSchema, Returned.DEFAULT, attributesToKeep);
removeAttributesOfType(scimExtension, extensionSchema, Returned.REQUEST, attributesToKeep);
removeAttributesOfType(scimExtension, extensionSchema, Returned.NEVER);
}
for (String extensionUrn : extensionsToRemove) {
copy.removeExtension(extensionUrn);
}
return copy;
}
}