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 usingownerId
as the default field name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Ensures 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 theownerField
equals the current user ID.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface nl.datasteel.crudcraft.annotations.security.RowSecurityHandler
rowFilterPredicate
-
Constructor Details
-
OwnerBasedRowSecurity
Creates a handler usingownerId
as 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 theownerField
equals the current user ID.- Specified by:
rowFilter
in 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:
apply
in interfaceRowSecurityHandler<T>
- Parameters:
entity
- the entity to secure- Throws:
IllegalStateException
- if reflection failsAccessDeniedException
- if the current user is not allowed to mutate this entity
-