Attribute Validation
A common requirement from channels is the ability to validate and/or allow certain fields on API calls. This involves the need to define a set of allowed values or a specific pattern against certain fields for certain paths. To address this, we have added a new plugin called the PayloadValidationPlugin, which can be activated by setting the global configuration.
impl.com.ukheshe.arch.conductor.aaa.PayloadValidationProvider=com.ukheshe.eclipse.conductor.aaa.EclipsePayloadValidationProvider
This plugin will validate only the POST and PUT request attributes. The attributes that need to be validated for each API can be configured, so no code changes are required. This configuration can be set at the global level, institution level, and tenant level. Additionally, the configuration can be overridden at the desired level, with the highest precedence being at the tenant level, followed by the institution level, and then the global level.
For example, if we want to validate a certain set of values for the industrial classification while creating an organization for a specific tenant, we can configure the property as follows:
request.payload.validation.rules.<tenantId>=rest/v1/tenants/(?<tenantId>\d+)/organisations=$.industrialClassification=(?i)(Manufacturing|Construction)
The key in this configuration is request.payload.validation.rules.tenantId, where tenantId can be replaced with your tenantId, institution name, or "global."
The value for this configuration rest/v1/tenants/(?\d+)/organisations=$.industrialClassification=(?i)(Manufacturing|Construction) is defined with a separation of the "=" sign. The left-hand side contains the path pattern, and the right-hand side contains the attribute name and validation rule separated by the "=" sign.
We can also define multiple attributes by comma-delimiting them. For example:
rest/v1/tenants/(?<tenantId>\d+)/organisations=$.industrialClassification=(?i)(Manufacturing|Construction),$.phone1=^\d{10}$
Multiple paths can be defined by adding them on new lines. To illustrate, let's say we want to validate the POST organization with an industrial classification set of values [Manufacturing|Construction] and a phone1 field with a 10-digit numerical value. Additionally, we want to validate the POST document with base64EncodedDocument non-empty value for institution DTB then we need to set the following config:
Key: request.payload.validation.rules.DTB
Value:
rest/v1/tenants/(?<tenantId>\d+)/organisations=$.industrialClassification=(?i)(Manufacturing|Construction),$.phone1=^\d{10}$
rest/v1/tenants/(?<tenantId>\d+)/organisations/(?<organisationId>\d+)/documents=$.base64EncodedDocument=^\s*$
Note
It is important to note that after configuring the path and attribute for payload validation, the plugin will automatically apply null and empty checks by default. If a validatable attribute is defined in the request and is either null, empty or not present, the plugin will throw an error indicating that the request is invalid.
Updated 8 months ago