Constraints
Constraints define set of rules that are applied for validation of the Attribute content as input. The Attribute content is validated when the Attribute is created or updated. Validation is controlled consistently by the platform and ensures that the Attribute content is valid and can be used for further processing.
For more information about Attribute types that support constraints, see Attributes.
Constraint properties
Every constraint is extended from the base class of BaseAttributeConstraint which is abstracted from AttributeConstraint.
The constraint has the following properties defined and inherited from the BaseAttributeConstraint:
| Property | Type | Short description | Required |
|---|---|---|---|
description | string | Description of the constraint | No |
errorMessage | string | Error message to be displayed when the constraint is violated | No |
type | AttributeConstraintType | Type of the constraint | Yes |
data | AttributeConstraint | Data to be used for the constraint | Yes |
Supported constraints types
Supported constraint types are defined in the AttributeConstraintType. The following constraint types are available and supported:
AttributeConstraintType | Class | Data |
|---|---|---|
REGEXP | RegexpAttributeConstraint | string |
RANGE | RangeAttributeConstraint | RangeAttributeConstraintData |
DATETIME | DateTimeAttributeConstraint | DateTimeAttributeConstraintData |
JSON_SCHEMA | JsonSchemaAttributeConstraint | string (JSON Schema document) |
Constraint type description and samples
RegExpAttributeConstraint
Use this constraint when the content needs to be validated against a regular expression.
- JSON
- Java
{
"description": "Alphanumeric Regex Constraint",
"errorMessage": "Only alphanumeric characters are allowed",
"type": "RegExp",
"data": "^[a-zA-Z0-9]*$"
}
RegexpAttributeConstraint constraint = new RegexpAttributeConstraint();
constraint.setDescription("Alphanumeric Regex Constraint");
constraint.setErrorMessage("Only alphanumeric characters are allowed");
constraint.setData("^[a-zA-Z0-9]*$");
constraint.setType(AttributeConstraintType.REGEXP);
RangeAttributeConstraint
Use this constraint when the content needs to be validated against a range of integers.
- JSON
- Java
{
"description": "Range Constraint",
"errorMessage": "Value should be between 1 and 10",
"type": "range",
"data": {
"from": 1,
"to": 10
}
}
RangeAttributeConstraintData data = new RangeAttributeConstraintData();
data.setFrom(1);
data.setTo(10);
RangeAttributeConstraint constraint = new RangeAttributeConstraint();
constraint.setDescription("Range Constraint");
constraint.setErrorMessage("Value should be between 1 and 10");
constraint.setData(data);
constraint.setType(AttributeConstraintType.RANGE);
DateTimeAttributeConstraint
Use this constraint when you need to validate date and time.
- JSON
- Java
{
"description": "Date Time Constraint",
"errorMessage": "Value should be between 1 and 10",
"type": "datetime",
"data": {
"from": "2020-01-01T00:00:00.000Z",
"to": "2020-12-31T00:00:00.000Z"
}
}
DateTimeAttributeConstraintData data = new DateTimeAttributeConstraintData();
data.setFrom(LocalDateTime.now());
data.setTo(LocalDateTime.of(2023, Month.JULY, 29, 19, 30, 40));
DateTimeAttributeConstraint constraint = new DateTimeAttributeConstraint();
constraint.setDescription("Date Time Constraint");
constraint.setErrorMessage("Value should be between the provided range");
constraint.setData(data);
constraint.setType(AttributeConstraintType.DATETIME);
JsonSchemaAttributeConstraint
Use this constraint when the content is a JSON document that needs to be validated against a JSON Schema. It applies to attributes with string or text content. Each value is read as JSON and must conform to the schema, so a value that is not well-formed JSON violates the constraint.
The data is the JSON Schema document, written inline as a string:
- the dialect is JSON Schema draft 2020-12; a document that declares another
$schemais rejected; $refmay only point inside the document, remote references are not loaded;- the document is validated when the attribute is created or updated, and an invalid schema is rejected. A default content of the attribute must conform to it as well.
When the value violates the schema, the errorMessage is reported if it is set, otherwise the message of the validator with the location of the violation.
For an attribute that is mapped to a certificate extension, the constraint adds policy over a value written in JER, on top of the ASN.1 module of the extension. See Request Attributes.
- JSON
- Java
{
"description": "Service entitlement tier",
"errorMessage": "Tier must be 1 or 2",
"type": "jsonSchema",
"data": "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"object\",\"properties\":{\"tier\":{\"enum\":[1,2]}}}"
}
JsonSchemaAttributeConstraint constraint = new JsonSchemaAttributeConstraint();
constraint.setDescription("Service entitlement tier");
constraint.setErrorMessage("Tier must be 1 or 2");
constraint.setData("{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"object\",\"properties\":{\"tier\":{\"enum\":[1,2]}}}");
constraint.setType(AttributeConstraintType.JSON_SCHEMA);
Constraint model
The following diagram represents the constraint model inherited from the AttributeConstraint. Details can be found in the Interfaces repository.