Package io.jmix.security.role.annotation
Annotation Interface PredicateRowLevelPolicy
Annotation must be put on a method of an interface that defines a row level role (see
RowLevelRole
).
Method annotated with PredicateRowLevelPolicy
must meet the following requirements:
- it must be a static or default method
- must return a
RowLevelPredicate
orRowLevelBiPredicate
- must have no arguments
The input parameter of the RowLevelPredicate
must be an instance of the class defined in the entityClass()
attribute of the annotation.
RowLevelBiPredicate
must be used when you need to use Spring beans in the function. The second parameter of the
bi-predicate is ApplicationContext
.
Example:
@RowLevelRole(name = "TestPredicateRoleLevelPolicyRole", code = "TestPredicateRoleLevelPolicyRole") public interface TestPredicateRoleLevelPolicyRole { @PredicateRowLevelPolicy(entityClass = TestOrder.class, actions = {RowLevelPolicyAction.CREATE, RowLevelPolicyAction.UPDATE}) static RowLevelPredicate<TestOrder> numberStartsWithA() { return testOrder -> testOrder.getNumber().startsWith("a"); } @PredicateRowLevelPolicy(entityClass = TestOrder.class, actions = {RowLevelPolicyAction.READ}) default RowLevelBiPredicate<TestOrder, ApplicationContext> numberStartsWithB() { return (testOrder, applicationContext) -> { CurrentAuthentication currentAuthentication = applicationContext.getBean(CurrentAuthentication.class); User currentUser = (User) currentAuthentication.getUser(); return currentUser.equals(testOrder.getManager()); } } }
-
Required Element Summary
Modifier and TypeRequired ElementDescriptionEntity CRUD operations on which the predicate must be testedClass<?>
Entity class on which the predicate must be tested
-
Element Details
-
entityClass
Class<?> entityClassEntity class on which the predicate must be tested -
actions
RowLevelPolicyAction[] actionsEntity CRUD operations on which the predicate must be tested
-