Class ScimResourceUtil


  • public class ScimResourceUtil
    extends Object
    This class contains methods to facilitate transformation, and manipulation of data inside SCIM resource objects, as well as some miscellaneous routines.
    • Method Detail

      • transferToResourceReplace

        public static BaseScimResource transferToResourceReplace​(BaseScimResource replacementDataSource,
                                                                 BaseScimResource originalDataSource,
                                                                 List<Extension> extensions)
                                                          throws InvalidAttributeValueException
        Returns an object which is the result of incorporating the information found in the replacementDataSource parameter to the information existing in originalDataSource object by doing replacements. The transference of data follows these rules:
        • Ignores changes in readonly attributes
        • Ignores null values (for single-valued attributes) in replacementDataSource
        • Nullifies multi-valued attributes when empty array is passed in replacementDataSource
        • Immutable attributes must match in both input objects or else exception is thrown. However, if the value in originalDataSource is missing (null), the value coming from replacementDataSource is kept
        • When a multi-valued attribute is passed in replacementDataSource, no existing data in the originalDataSource is retained, that is, the replacement is not partial but thorough: it's not an item-by-item replacement
        Parameters:
        replacementDataSource - Object with the information to be incorporated. Only non-null attributes of this object end up being transfered to the result
        originalDataSource - Object (SCIM resource) that provides the original data
        extensions - A list of Extensions associated to parameter originalDataSource. This helps to manipulate the transference of custom attributes values.
        Returns:
        A new object that contains the result of data transference. Neither replacementDataSource nor originalDataSource are changed after a call to this method
        Throws:
        InvalidAttributeValueException - When recursive traversal of replacementDataSource fails or if the rule of immutable attribute was not fulfilled
      • transferToResourceAdd

        public static BaseScimResource transferToResourceAdd​(BaseScimResource replacementDataSource,
                                                             BaseScimResource originalDataSource,
                                                             List<Extension> extensions)
                                                      throws InvalidAttributeValueException
        This method applies the same copying rules of transferToResourceReplace except for the following:
        • When a multi-valued attribute is passed in replacementDataSource, the existing data in the originalDataSource object is retained, and the items in the former object are prepended to the existing collection.
        Parameters:
        replacementDataSource - Object with the information to be incorporated. Only non-null attributes of this object end up being transferred to the result
        originalDataSource - Object (SCIM resource) that provides the original data
        extensions - A list of Extensions associated to parameter originalDataSource. This helps to manipulate the transference of custom attributes values.
        Returns:
        A new object that contains the result of data transference. Neither replacementDataSource nor originalDataSource are changed after a call to this method
        Throws:
        InvalidAttributeValueException - When recursive traversal of replacementDataSource fails or if the rule of immutable attribute was not fulfilled
      • deleteFromResource

        public static BaseScimResource deleteFromResource​(BaseScimResource origin,
                                                          String path,
                                                          List<Extension> extensions)
                                                   throws InvalidAttributeValueException
        Returns a SCIM resource with the same data found in origin object, except for the attribute referenced by path being removed from the output. In other words, this method nullifies an attribute.
        Parameters:
        origin - The resource having the the original data
        path - An attribute path (in dot notation). Examples could be: displayName, emails.type, addresses, meta.lastModified.
        extensions - A list of Extensions associated to origin Object
        Returns:
        The resulting object: data in origin without the attribute referenced by path
        Throws:
        InvalidAttributeValueException - If there is an attempt to remove an attribute annotated as required or read-only
      • getSchemaAnnotation

        public static Schema getSchemaAnnotation​(Class<? extends BaseScimResource> cls)
        Returns the Schema annotation found in the class passed as parameter.
        Parameters:
        cls - A class representing a SCIM resource
        Returns:
        The annotation found or null if there is no such
      • getDefaultSchemaUrn

        public static String getDefaultSchemaUrn​(Class<? extends BaseScimResource> cls)
        Returns the urn associated to the default schema of the SCIM resource whose class is passed as parameter.
        Parameters:
        cls - A class representing a SCIM resource
        Returns:
        The urn (obtained by calling Schema.id() on the appropriate Schema annotation) or null if there is no such annotation in the class cls
      • stripDefaultSchema

        public static String stripDefaultSchema​(Class<? extends BaseScimResource> cls,
                                                String attribute)
        Removes from an attribute path the schema urn that might prefix such path. The urn to remove will correspond to the default schema urn of a SCIM resource type whose class is passed as parameter.
        Parameters:
        cls - A class that represents a SCIM resource type
        attribute - An attribute path (potentially prefixed by a urn)
        Returns:
        The attribute with no prefix. As an example, attribute_name is returned if urn:attribute_name is the value of attribute parameter (as long as urn represent the default urn for this resource)
      • getType

        public static String getType​(Class<? extends BaseScimResource> cls)
        Returns the (human-readable) type of a SCIM resource based on its class. In practice this will be something like "User" or "Group". The type is obtained by calling Schema.name() of the respective class annotation.
        Parameters:
        cls - A class that represents a SCIM resource type
        Returns:
        A string with the proper value, or null if there is no Schema annotation found
      • adjustPrimarySubAttributes

        public static void adjustPrimarySubAttributes​(BaseScimResource resource)
        Takes a SCIM resource and "fixes" inconsistencies in "primary" subattribute: in a multivalued attribute setting, only one of the items in the collection can have "primary" : true. Thus, for every collection involved (e.g. addresses, emails... in UserResource), it switches all occurrences where "primary" is currently true to false, except for the first one found.
        Parameters:
        resource - SCIM resource object