AttributeUtil { public <T extends ScimResource> T setExcludedAttributesForDisplay(T resource, Set<AttributeReference> excludedAttributes) throws IllegalArgumentException, IllegalAccessException, AttributeDoesNotExistException, IOException { if (excludedAttributes.isEmpty()) { return setAttributesForDisplay(resource); } else { T copy = cloneScimResource(resource); String resourceType = copy.getResourceType(); Schema schema = registry.getBaseSchemaOfResourceType(resourceType); Set<Attribute> attributesToRemove = resolveAttributeReferences(excludedAttributes, false); removeAttributesOfType(copy, schema, Returned.REQUEST); removeAttributesOfType(copy, schema, Returned.NEVER); removeAttributes(copy, schema, attributesToRemove); for (Entry<String, ScimExtension> extensionEntry : copy.getExtensions().entrySet()) { String extensionUrn = extensionEntry.getKey(); ScimExtension scimExtension = extensionEntry.getValue(); Schema extensionSchema = registry.getSchema(extensionUrn); removeAttributesOfType(scimExtension, extensionSchema, Returned.REQUEST); removeAttributesOfType(scimExtension, extensionSchema, Returned.NEVER); removeAttributes(scimExtension, extensionSchema, attributesToRemove); } return copy; } }  @PostConstruct void init(); T keepAlwaysAttributesForDisplay(T resource); T setAttributesForDisplay(T resource); T setAttributesForDisplay(T resource, Set<AttributeReference> attributes); T setExcludedAttributesForDisplay(T resource, Set<AttributeReference> excludedAttributes); Set<AttributeReference> getAttributeReferences(String s);  }
@Test public void testExcludeAttributes() throws Exception { ScimUser resource = getScimUser(); debugJson(resource); Set<AttributeReference> attributeSet = new HashSet<>(); attributeSet.add(new AttributeReference("userName")); attributeSet.add(new AttributeReference("addresses")); attributeSet.add(new AttributeReference("name")); resource = attributeUtil.setExcludedAttributesForDisplay(resource, attributeSet); debugJson(resource); Assertions.assertThat(resource.getId()).isNotNull(); Assertions.assertThat(resource.getPassword()).isNull(); Assertions.assertThat(resource.getUserName()).isNull(); Assertions.assertThat(resource.getActive()).isNotNull(); Assertions.assertThat(resource.getAddresses()).isNull(); Assertions.assertThat(resource.getName()).isNull(); EnterpriseExtension extension = resource.getExtension(EnterpriseExtension.class); Assertions.assertThat(extension.getCostCenter()).isNotNull(); }
@Test public void testExcludeAttributesWithExtensions() throws Exception { ScimUser resource = getScimUser(); Set<AttributeReference> attributeSet = new HashSet<>(); attributeSet.add(new AttributeReference("userName")); attributeSet.add(new AttributeReference(EnterpriseExtension.URN + ":costCenter")); resource = attributeUtil.setExcludedAttributesForDisplay(resource, attributeSet); Assertions.assertThat(resource.getId()).isNotNull(); Assertions.assertThat(resource.getPassword()).isNull(); Assertions.assertThat(resource.getUserName()).isNull(); Assertions.assertThat(resource.getActive()).isNotNull(); EnterpriseExtension extension = resource.getExtension(EnterpriseExtension.class); Assertions.assertThat(extension.getCostCenter()).isNull(); Assertions.assertThat(extension.getDepartment()).isNotNull(); }