You can add multiple conditions to IQueryable dynamically. So you can do something like:
[PrincipalPermission(SecurityAction.Demand, Role="DepartmentManager")] public IEnumerable<Employee> GetManagedEmployees() {
And your AddDepartmentPermissions will look like this:
private IQueryable<Employee> AddDepartmentPermission(IQueryable<Employee> query) { int departmentId = GetAllowedDepartmentSomewhere(); return query.Where(e => e.Department.Id == departmentId); }
This is an example where PrincipalPermission does not allow GetManagedEmployees to be called for non-manager roles, and AddDepartmentPermission adds part of the request to select employees only from the allowed department.
The main thing is that you can wrap IQueryable<T> in methods that will modify the query. I believe that even the ability to add interception (aspects) can even be directly to the properties that display the ObjectSet , and dynamically add request elements related to security.
source share