Sharepoint 2010 : Business Connectivity Services - Adding Security Trimming to .NET Connectors
First a rights table must be added to the model to support security trimming. Here we have created a CustomerAccessRights table containing the SecurityDescriptor, Rights, and CustomerKey. The SecurityDescriptor is a binary unique value for a particular user. Rights will contain a simple numeric schema representing user rights to a particular row. It also contains creation rights.
Read Allowed
Read / Write / Update / Delete Allowed
No Entry means the user has no rights to this data row represented by the CustomerKey. In a production environment, a different and more fine-grained access rights mapping might be desired, but this should give a good idea about how to implement security trimming that allows multiple users with different access to the same data rows. Given the customer table contains this information, we can create a CustomerAccessRights table containing the security mappings. The SecurityDescriptor should be based on the same method used by the model to trim security. In this example, it is the GetSecurityDescriptor() method displayed in Tables 1 and 2.
| CustomerKey | CompanyName | PhoneNumber | EmailAddress | ContactPerson |
|---|---|---|---|---|
| 2 | Microsoft | 555-xxxxxx1 | mail@microsoft.com John | Doe |
| 5 | SurfRay | 555-xxxxxx2 | mail@surfray.com John | Doe |
| 6 | Apple | 555-xxxxxx3 | mail@apple.com John | Doe |
| 7 | IBM | 555-xxxxxx4 | mail@ibm.com John | Doe |
| Rights | CustomerKey | SecurityDescriptor |
|---|---|---|
| 1 2 | <binary data> | |
| 2 2 | <binary data> | |
| 2 5 | <binary data> | |
| 2 6 | <binary data> | |
| 2 7 | <binary data> |
To add the CustomerAccessRights table to the model, add a new LINQ to SQL Classes item to the project and name it CustomerAccessRights. In the Server Explorer, add a connection to the Customers database if it does not already exist. Then drag the CustomerAccessRights table, and drop it on the CustomerAccessRights.dbml design surface.
Next the required method for computing the SecurityDescriptor is added as in Listing 1. This method can be added to the CustomerService.cs class that also contains the Customer methods. This method computes a security descriptor in the form of a byte array.
Example 1. Implementation of Method for Getting a Security Descriptor
Having the Rights table and the security descriptor method in place, the next step is to modify the Customers methods for updating, reading, etc., such that they are trimmed based on the security descriptor. Here (Listing 2) the Reader methods are updated to apply security trimming during search.
Example 2. Adding Security Trimming to the BDC Method Instances
Using this methodology as a baseline, it is possible to create simple security trimming. When doing security trimming, performance of the trimming mechanism is relevant. Different caching mechanics can be applied with success to increase performance. Also other security descriptor implementations that better fit specific requirements can be implemented using this example as a template for how to approach the topic. Microsoft does provide some resources on this topic.