I have ParentItem
s on which security trimming should be applied.
So there is a SecurityTrimmingExpressionFactory
which will build up an Expression<Func<ParentItem, bool>>
for the parent Element:
SecurityTrimmingExpressionFactory
public static Expression<Func<ParentItem, bool>> CreateTrimming(currentUser)
{
return parentItem => parentItem.OwnerId == currentUser.Id;
}
In my WebAPI Controller I want to receive child items of a parent element. The normal way I would write it like this
WebAPI Controller (Get)
return Entities.ChildItems.Where(c => c.parentId == <some id>);
no problem at all but no security trimming.
If I want to apply my security trimming here (Currently I am using LinqKit to build the expression tree with the parent item)
WebAPI Controller (Get) with trimming
var expr = TrimmingExpressionsFactory.CreateParentTrimming(this.CurrentUser);
return Entities.ChildItems
.AsExpandable()
.Where(childItem => expr.Invoke(childItem.ParentItem)
.Where(c => c.parentId == <some id>)
);
everything is working fine.
Now the problem is that external libraries (like LinqKit) are forbidden in the current environment (In my opinion: bad decision ;) ). Is there another way without an external library to expand or invoke query expression with dependend Entities?
Already tried to solve this problem by using .AsEnumerable()
(often found this as a workaround in the web) but this is not an acceptable solution for large data sets.