1. Home
  2. Docs
  3. Advanced Topics
  4. Applying Logged in User Security or Claims to Data using Global Filters

Applying Logged in User Security or Claims to Data using Global Filters

Often times you need to apply data restrictions to the report data that your user can see. For example, you need to restrict the currently logged in user to only the Vendors or Distributors they have access to.

Let’s say for example we want to restrict the currently logged in user to only see data for 3 Distributors they have access to. So let’s assume in a database table picked in the report, the Distributor Id column is named “DistributorID”, and current user can only access DistributorID 1, 2 and 3.

So to automatically apply this filter, at initialization in ReportController’s GetSettings method, you can add the following :

    settings.DataFilters = new { DistributorId = "1,2,3" };

and then your sql statement should return WHERE … AND [TableName].[DistributorId] IN (1,2,3)

‘1,2,3’ here is obviously just an example. In a real scenario, you would not hard code the value, but probably pick this value from the claims for the logged in user.  

Also, if you would like to explicitly provide a table name along with the column to filter on, you can provide it in the property name by separating the table and column name by __ (2 underscores), for example:

    settings.DataFilters = new { Distributors__DistributorId = "1,2,3" };

You can add as many global filters here as you need. So for example, you can add:

      settings.DataFilters = new { DistributorId = "1,2,3", VendorId = "15,16" };

Was this article helpful to you? Yes No 1

How can we help?