Class RequestUtils
- java.lang.Object
-
- de.captaingoldfish.scim.sdk.server.utils.RequestUtils
-
public final class RequestUtils extends Object
author Pascal Knueppel
created at: 12.10.2019 - 20:08
this class will add some helper methods that can be used to validate or modify request based attributes based on the SCIM specification RFC7643 and RFC7644
-
-
Constructor Summary
Constructors Constructor Description RequestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<SchemaAttribute>getAttributes(ResourceType resourceType, String attributes)this method will parse either the attributes parameter or the excludedAttributes parameter into a list ofSchemaAttributes.static List<String>getAttributes(String attributes)this method will parse either the attributes parameter or the excludedAttributes parameter into a list.static intgetEffectiveCount(ServiceProvider serviceProvider, Integer count)Will get the effective count value as described in RFC7644:
Non-negative integer.static intgetEffectiveFailOnErrors(BulkRequest bulkRequest)will check the failOnErrors attribute in a bulk request and return a sanitized value.
RFC7644 chapter 3.7.3 defines the minimum value of failOnErrors as 1static longgetEffectiveStartIndex(Long startIndex)The 1-based index of the first query result.static Map<String,String>getQueryParameters(String query)gets the query parameter from the given URLstatic SchemaAttributegetSchemaAttributeByAttributeName(ResourceType resourceType, String attributeName)gets theSchemaAttributefrom the givenResourceTypestatic SchemaAttributegetSchemaAttributeForFilter(ResourceType resourceType, FilterAttributeName attributeName)gets theSchemaAttributefrom the givenResourceTypestatic FilterNodeparseFilter(ResourceType resourceType, String filter)parsed the filter of a list requeststatic AttributePathRootparsePatchPath(ResourceType resourceType, String path)parses a value path context for patch path expressionsstatic voidvalidateAttributesAndExcludedAttributes(String attributes, String excludedAttributes)From RFC7644 chapter 3.9:
-
-
-
Method Detail
-
getAttributes
public static List<String> getAttributes(String attributes)
this method will parse either the attributes parameter or the excludedAttributes parameter into a list. The expected form of the attributes list is: form (e.g., userName, name, emails)- Parameters:
attributes- the comma separated string of scim attribute names- Returns:
- the list of attributes
-
getAttributes
public static List<SchemaAttribute> getAttributes(ResourceType resourceType, String attributes)
this method will parse either the attributes parameter or the excludedAttributes parameter into a list ofSchemaAttributes. The expected form of the attributes list is: form (e.g., userName, name, emails)- Parameters:
attributes- the comma separated string of scim attribute names- Returns:
- the list of attributes
-
validateAttributesAndExcludedAttributes
public static void validateAttributesAndExcludedAttributes(String attributes, String excludedAttributes)
From RFC7644 chapter 3.9:
Clients MAY request a partial resource representation on any operation that returns a resource within the response by specifying either of the mutually exclusive URL query parameters "attributes" or "excludedAttributes"so only one these parameters are allowed to be specified in a request- Parameters:
attributes- the required attributes that should be present in the responseexcludedAttributes- the attributes that should not be returned in the response
-
parseFilter
public static FilterNode parseFilter(ResourceType resourceType, String filter)
parsed the filter of a list request- Parameters:
resourceType- the resource type that describes the endpoint on which the filter is used so that the filter expression can be correctly resolvedfilter- the filter expression that must apply to the given resource type- Returns:
- The parsed filter expression as resolvable tree structure that might be used to resolve them to jpa predicates for example
-
parsePatchPath
public static AttributePathRoot parsePatchPath(ResourceType resourceType, String path)
parses a value path context for patch path expressions- Parameters:
resourceType- the resource type that describes the endpoint on which the path expression is usedpath- the path expression that must apply to the given resource type- Returns:
- The parsed path expression as resolvable tree structure to find matching attributes within a single resource
-
getEffectiveStartIndex
public static long getEffectiveStartIndex(Long startIndex)
The 1-based index of the first query result. A value less than 1 SHALL be interpreted as 1.- Parameters:
startIndex- the index to start with to list the resources- Returns:
- number "1" or greater
-
getEffectiveCount
public static int getEffectiveCount(ServiceProvider serviceProvider, Integer count)
Will get the effective count value as described in RFC7644:
Non-negative integer. Specifies the desired maximum number of query results per page, e.g., 10. A negative value SHALL be interpreted as "0". A value of "0" indicates that no resource results are to be returned except for "totalResults".
DEFAULT: None
When specified, the service provider MUST NOT return more results than specified, although it MAY return fewer results. If unspecified, the maximum number of results is set by the service provider.
-
getSchemaAttributeByAttributeName
public static SchemaAttribute getSchemaAttributeByAttributeName(ResourceType resourceType, String attributeName)
gets theSchemaAttributefrom the givenResourceType- Parameters:
resourceType- the resource type from which the attribute definition should be extractedattributeName- this instance holds the attribute name to extract theSchemaAttributefrom theResourceType- Returns:
- the found
SchemaAttributedefinition - Throws:
BadRequestException- if noSchemaAttributewas found for the given name attribute
-
getSchemaAttributeForFilter
public static SchemaAttribute getSchemaAttributeForFilter(ResourceType resourceType, FilterAttributeName attributeName)
gets theSchemaAttributefrom the givenResourceType- Parameters:
resourceType- the resource type from which the attribute definition should be extractedattributeName- this instance holds the attribute name to extract theSchemaAttributefrom theResourceType- Returns:
- the found
SchemaAttributedefinition - Throws:
InvalidFilterException- if noSchemaAttributewas found for the given name attribute
-
getQueryParameters
public static Map<String,String> getQueryParameters(String query)
gets the query parameter from the given URL- Parameters:
query- the query string- Returns:
- the query parameters as a map
-
getEffectiveFailOnErrors
public static int getEffectiveFailOnErrors(BulkRequest bulkRequest)
will check the failOnErrors attribute in a bulk request and return a sanitized value.
RFC7644 chapter 3.7.3 defines the minimum value of failOnErrors as 1The "failOnErrors" attribute is set to '1', indicating that the service provider will stop processing and return results after one error
- Parameters:
bulkRequest- the bulk request- Returns:
- a failOnErrors value that has been validated and sanitized
-
-