Class OwnerBasedRowSecurity<T>
java.lang.Object
nl.datasteel.crudcraft.runtime.security.row.OwnerBasedRowSecurity<T>
- Type Parameters:
T- the entity type
- All Implemented Interfaces:
RowSecurityHandler<T>
A row-level security handler that restricts access to entities based on an
ownerId field.
Only entities where the owner field matches the current authenticated user's ID are visible
or mutable.-
Constructor Summary
ConstructorsConstructorDescriptionOwnerBasedRowSecurity(String ownerField, Supplier<UUID> userIdSupplier) Creates a handler using a custom field name.OwnerBasedRowSecurity(Supplier<UUID> userIdSupplier) Creates a handler usingownerIdas the default field name. -
Method Summary
Modifier and TypeMethodDescriptionvoidEnsures that the entity's owner matches the current user, or sets it if not yet assigned.org.springframework.data.jpa.domain.Specification<T> Builds a row-level specification that only allows access to entities where theownerFieldequals the current user ID.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface nl.datasteel.crudcraft.annotations.security.RowSecurityHandler
rowFilterPredicate
-
Constructor Details
-
OwnerBasedRowSecurity
Creates a handler usingownerIdas the default field name. -
OwnerBasedRowSecurity
Creates a handler using a custom field name.- Parameters:
ownerField- the name of the field representing the owner
-
-
Method Details
-
rowFilter
Builds a row-level specification that only allows access to entities where theownerFieldequals the current user ID.- Specified by:
rowFilterin interfaceRowSecurityHandler<T>- Returns:
- the row-level security filter
-
apply
Ensures that the entity's owner matches the current user, or sets it if not yet assigned.- Specified by:
applyin interfaceRowSecurityHandler<T>- Parameters:
entity- the entity to secure- Throws:
IllegalStateException- if reflection failsAccessDeniedException- if the current user is not allowed to mutate this entity
-