authorization - Achieving property value assignment control using a generic approach for POCO or plain C# entity classes -


i working on .net application & trying achieve following in c#.

let's assume have entity employee class below few public auto implemented properties. assume have created attribute - beforepropertyset & have annotated of entity properties - in class below.

class employee {     [beforepropertyset("some delegate", "some other prop value")]     public string address { get; set; }      public string name { get; set; }      public int age { get; set; } } 

what want can explained of code snippet -

var e = new employee(); e.address = "confidential data";   //this assignment restricted user x //whereas allowed user y e.name = "general data"; 

whenever assign value property, if property annotated special attribute beforepropertyset callback common function standard thing across application. example, if currentuser not expected view value being assigned new value assignment can cancelled.

this approach enables me remove attribute or add new entities easily.

i found this approach can allow me invoke function few changes of invocation in inherited class, auto-generated inherited class & instance needs explicitly created approach.

have tried this? please let me know know how can achieve or please point other resources may know. appreciate help. many thanks.

thanks gave probable answers. posting here sake of completeness. here why & how changed path & still achieved business goal in application.

after discussion team attribute based approach cancelled. main reason have ability change data protection policy dynamically without revisiting code. in mind, ended doing following.

1) defined metadata inside xml & cached it. 2) model conversion/creation - assignments happen in 1 single class per model. 3) added 1 helper method checks in xml if current user has access protected data based on xml config & assigns appropriate value.

xml looks -

 <modeltag name="somemodelname">     <property defaultreturnvalue="0" roles="userrole1, userrole2">propertyname1</property>   </modeltag> 

and new c# code looks -

employee e  = new employee(); e.propertyname1 = (checkaccess(e,"propertyname1") ? "new value2" : null); e.propertyname2 = (checkaccess(e,"propertyname1") ? "new value2" : null);   bool checkaccess(model m, string propname) {     var currentrole = getcurrentrole();  //some method retrive role of current user     //retrieve xml model m cache     //check if xml configuration provides access values of propname currentrole     //return true or false accordingly } 

i hope someone.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -