When performing CRUD operations on AdminUser
, they are first validated by their own ContextValidators
, such as AdminUserContextValidator
when performing operations on AdminUser
.
If the validations done by the ContextValidators
are successful, they will then be validated by their EntityValidators
, such as AdminUserValidator
.
After successful validation done by the context validators, the entity’s EntityValidator
will then validate the end state of the entity (after updates are applied but before the entity is persisted).
These validations include checking against missing or invalid fields, or invalid references to other entities.
For example, missing name is not allowed for AdminUser
.
Validating Context
When a user is authenticated, the Authentication
in the Spring Security Context is populated with various information about them, including what tenant/application access they have.
This allows us to determine whether a CRUD operation in the requested ContextRequest
is permitted by the authenticated user.
When the authenticated user is in an invalid context, they should not be allowed to perform any CRUD operations on any entities.
Similarly, when the user is in a valid context, they should not be allowed to perform any CRUD operations on entities outside that context.
For example, the authenticated user cannot modify another user, role, or permission in another tenant, since entities should not be accessible in different tenants, unless the user is in a global context.
Furthermore, this logic applies to the referenced entities as well.
To learn more about global vs. tenant context, please check out the Multi-Tenant Features Documentation
AdminUserContextValidator
The context validator that validates the context for the AdminUser
entities.
Since the AdminUser
entity can belong to a specific application, this validator also validates against invalid context for addition or removal of applications from a user.
For example, the authenticated user must be in a tenant or global context to add/remove a user from an application.
Besides context validations, it validates against insufficient privileges for the currently authenticated user as well; the existing state of the entity must not already be less restrictive than the authenticated user.
The restrictiveness check is based on their restrictions at the very least, if the entity’s restrictions are already less restrictive than the authenticated user’s restrictions prior the operation, the operation is not permitted.
Privileges Escalation Validation
To prevent privileges escalation for certain users, the AdminUser
entity has the AdminUser#grantAnyAuthorityAllowed
flag to determine whether the restrictiveness validation should also check against their overall privileges as well.
The restrictiveness check based on privileges will be skipped if the grantAnyAuthorityAllowed
flag is true
, since that means the authenticated user can grant any privileges it wants no matter what privileges it has.
Otherwise, this validator will also make sure that the existing state of the entity is not already less restrictive than the authenticated user based on their overall privileges, which include all of their flat permissions, roles, restrictions, restricted roles, and restricted permissions.
Validating Entities
AdminUserValidator
After successful validations done by AdminUserContextValidator
, this validator will then check the proposed AdminUser
entity for creation or modification against invalid fields, invalid roles, and invalid permissions references.
Similar to AdminUserContextValidator
, this validator also validates against insufficient privileges for the currently authenticated user based on restrictions, and their overall privileges (depends on the AdminUser#grantAnyAuthorityAllowed
flag).
The privileges escalation validation logic is the same, except for the state of the entities it validates against.
The AdminUserContextValidator
validates the privileges of the existing state of the entity, but this validator validates the privileges of the end state of the entity (after updates are applied but before the entity is persisted).