PermissionExpressionBuilder implements CheckInstantiator { public <A extends Annotation> Expression buildAnyFieldExpressions(final PersistentResource resource, final Class<A> annotationClass, final ChangeSpec changeSpec) { Class<?> resourceClass = resource.getResourceClass(); if (!entityDictionary.entityHasChecksForPermission(resourceClass, annotationClass)) { return SUCCESSFUL_EXPRESSION; } final Function<Check, Expression> leafBuilderFn = leafBuilder(resource, changeSpec); final Function<Function<Check, Expression>, Expression> expressionFunction = (checkFn) -> buildAnyFieldExpression( PermissionCondition.create(annotationClass, resource, (String) null, changeSpec), checkFn, (RequestScope) resource.getRequestScope() ); return expressionFunction.apply(leafBuilderFn); } PermissionExpressionBuilder(ExpressionResultCache cache, EntityDictionary dictionary); Expression buildSpecificFieldExpressions(final PersistentResource resource,
                                                                           final Class<A> annotationClass,
                                                                           final String field,
                                                                           final ChangeSpec changeSpec); Expression buildAnyFieldExpressions(final PersistentResource resource,
                                                                       final Class<A> annotationClass,
                                                                       final ChangeSpec changeSpec); Expression buildUserCheckFieldExpressions(final Class<?> resourceClass,
                                                                             final RequestScope scope,
                                                                             final Class<A> annotationClass,
                                                                             final String field); Expression buildUserCheckAnyExpression(final Class<?> resourceClass,
                                                                         final Class<A> annotationClass,
                                                                         final RequestScope requestScope); FilterExpression buildAnyFieldFilterExpression(Class<?> forType, RequestScope requestScope); static final Expression FAIL_EXPRESSION; }
@Test public void testAnyFieldExpressionText() { @Entity @Include @ReadPermission(expression = "user has all access AND user has no access") class Model { } dictionary.bindEntity(Model.class); PersistentResource resource = newResource(new Model(), Model.class); Expression expression = builder.buildAnyFieldExpressions( resource, ReadPermission.class, null); assertEquals( "READ PERMISSION WAS INVOKED ON PersistentResource{type=model, id=null} " + "FOR EXPRESSION [(FIELDS(\u001B[31mFAILURE\u001B[m)) OR (ENTITY(((user has all access " + "\u001B[34mWAS UNEVALUATED\u001B[m)) AND ((user has no access " + "\u001B[34mWAS UNEVALUATED\u001B[m))))]", expression.toString()); expression.evaluate(Expression.EvaluationMode.ALL_CHECKS); assertEquals( "READ PERMISSION WAS INVOKED ON PersistentResource{type=model, id=null} " + "FOR EXPRESSION [(FIELDS(\u001B[31mFAILURE\u001B[m)) OR (ENTITY(((user has all access " + "\u001B[32mPASSED\u001B[m)) AND ((user has no access " + "\u001B[31mFAILED\u001B[m))))]", expression.toString()); }