577e1d4ac70d1752f824d49ddc0afdb01cf743e0
FAQ/Field-Level-Security-Integration.md
| ... | ... | @@ -1,4 +1,69 @@ |
| 1 | -#Field Level Security Integration |
|
| 1 | +#Security Levels |
|
| 2 | + |
|
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##About |
|
| 6 | + |
|
| 7 | +Izenda offers many various methods of implementing security over the scope of your reports. It is highly customizable and can be controlled through the global.asax file. Here we will provide various security samples for different levels of access. You may modify these to suit your own organization's needs. |
|
| 8 | + |
|
| 9 | +##Basic security sample |
|
| 10 | + |
|
| 11 | +Here we demonstrate what basic security settings might look like in your application. Note that the code below would exist inside the ``InitializeReporting()`` method. In this case, initialization would be performed while confirming the user's identity. You may also call the ``InitializeReporting()`` method after the user has been authenticated. |
|
| 12 | + |
|
| 13 | +```csharp |
|
| 14 | +AdHocSettings.LicenseKey = "INSERT_LICENSE_KEY_HERE"; |
|
| 15 | +AdHocSettings.SqlServerConnectionString = "..."; |
|
| 16 | +AdHocSettings.CurrentUserName = GetUserName(); |
|
| 17 | +AdHocSettings.CurrentUserTenantId = GetTenantID(); |
|
| 18 | +string role = GetUserRoleFromApp() |
|
| 19 | +if(role == "Admin") |
|
| 20 | +{ |
|
| 21 | + Izenda.AdHoc.AdHocSettings.VisibleDataSources = |
|
| 22 | + new string[] { "Purchasing.Vendor", "Products", "Orders", "Order Details", "Customers" }; |
|
| 23 | +} |
|
| 24 | +else |
|
| 25 | +{ |
|
| 26 | + Izenda.AdHoc.AdHocSettings.VisibleDataSources = new string[] { "Products", "Orders", "Customers" }; |
|
| 27 | + Izenda.AdHoc.AdHocSettings.CurrentUserIsAdmin = false; |
|
| 28 | + Izenda.AdHoc.AdHocSettings.ShowSettingsButton = false; |
|
| 29 | + Izenda.AdHoc.AdHocSettings.ShowSqlOutputIcon = false; |
|
| 30 | + Izenda.AdHoc.AdHocSettings.HiddenFilters["ShipCountry"]= GetUserCountry(); |
|
| 31 | +} |
|
| 32 | +``` |
|
| 33 | + |
|
| 34 | +You could also use more complex logic. For example, you could filter all queries for the particular user or user group. |
|
| 35 | + |
|
| 36 | +```csharp |
|
| 37 | +public override void PreExecuteReportSet(ReportSet reportSet) |
|
| 38 | +{ |
|
| 39 | + bool isLocalManager = false; |
|
| 40 | + foreach (string role in AdHocSettings.CurrentUserRoles) |
|
| 41 | + if (role == "Local Manager") |
|
| 42 | + isLocalManager = true; |
|
| 43 | + if (!AdHocSettings.CurrentUserIsAdmin || isLocalManager) |
|
| 44 | + { |
|
| 45 | + Filter filter = new Filter(); |
|
| 46 | + filter.Column = "ShipCity"; |
|
| 47 | + filter.SqlOverride = "ShipCity IN (SELECT ShipCity FROM [dbo].[Orders] WHERE ShipCountry = 'USA')"; |
|
| 48 | + reportSet.Filters.AddHidden(filter); |
|
| 49 | + } |
|
| 50 | +} |
|
| 51 | +``` |
|
| 52 | + |
|
| 53 | +##Data Source Level Security |
|
| 54 | + |
|
| 55 | +**Table and View Access** |
|
| 56 | + |
|
| 57 | +To limit what data sources a user can see, apply the [[VisibleDataSources|/API/CodeSamples/VisibleDataSources]] setting. Its argument is an array of strings. Izenda recommends creating database views to simplify the user experience. Izenda Reports will only show views if you set [[ViewsOnly|/API/CodeSamples/ViewsOnly]] to _true_. Here is an example: |
|
| 58 | + |
|
| 59 | +```csharp |
|
| 60 | +//set access to which tables and views are visible |
|
| 61 | + |
|
| 62 | +if(!AdHocSettings.CurrentUserIsAdmin) |
|
| 63 | + Izenda.AdHoc.AdHocSettings.VisibleDataSources = new string[]{ "Products", "Categories" }; |
|
| 64 | +else |
|
| 65 | + Izenda.AdHoc.AdHocSettings.VisibleDataSources = new string[] {"AdminData", "Employees", "Products", "Categories"}; |
|
| 66 | +``` |
|
| 2 | 67 | |
| 3 | 68 | ##Field Level Access |
| 4 | 69 |