Row level securityhttp://forums.asp.net/t/1800212.aspx/1?Row+level+securityTue, 08 May 2012 15:06:41 -040018002124965947http://forums.asp.net/p/1800212/4965947.aspx/1?Row+level+securityRow level security <p>I have a requirement in my dynamic data web application to restrict table rows depending on the user logged in.</p> <p>I have a Clients table with a ClientType field and a Projects table related to it (Projects table contains a ClientID).&nbsp; When users log in they should only see the Projects that relate to their ClientType (each user also has a ClientType).</p> <p>Searching around I can see that lots of people have asked about a solution for row level security, but I can't see an obvious&nbsp;answer.</p> <p>I'm not necessarily looking for a generalised solution.&nbsp; A specific &quot;where&quot; clause added in a Linq query somewhere or something similar would be ok.&nbsp; I'm not sure on the best place to add the query.</p> 2012-05-04T15:50:08-04:004966341http://forums.asp.net/p/1800212/4966341.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi BigA, there are two options at the moment Domain Service DD Project or use QueryExtender, the last is limited as yu can't pre filter dropdown lists etc. however Domain Service does not support Many to Many relationships.</p> 2012-05-04T21:30:53-04:004966520http://forums.asp.net/p/1800212/4966520.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi, BigA, Hi Sjnaughton.</p> <p><span class="hps" style="">It seems to me</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">that this issue</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">had been discussed</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">at the forum <a href="http://forums.asp.net/t/1788200.aspx/1?Data&#43;Filtering">http://forums.asp.net/t/1788200.aspx/1?Data&#43;Filtering</a>.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">And</span><span style=""><span class="Apple-converted-space">&nbsp;<a href="http://forums.asp.net/post/4946450.aspx">http://forums.asp.net/post/4946450.aspx</a></span></span><span class="hps" style=""> is marked as</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">answer.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">Sjnaughton,</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">you can</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">check it</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">on my</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">dd_site,</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">if you</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">will be</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">willing and</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">free time.</span><br style=""> <span style=""></span><span class="hps" style="">Especially for</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">this issue</span><span style="">, I created a</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">data model</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">DD_Forum.</span><br style=""> <span style=""></span><span class="hps" style="">Choose</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">the model</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">from the list of</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">models <span class="hps" style="">by clicking</span><span style=""><span class="Apple-converted-space">&nbsp;&quot;Dynamic Data Site&quot;</span></span><span class="hps" style=""> button</span>.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">Open the</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">&quot;Projects&quot;</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">table.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">You'll see</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">all the</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">rows&nbsp;of the table</span><span style="">.</span><br style=""> <span style=""></span><span class="hps" style="">Then</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">Login as admin.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">In the table</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">&quot;Accounts&quot;</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">add </span><span style=""></span><span class="hps" style="">&quot;Forum_prj2&quot;</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">role <span class="hps" style="">to your</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">line</span>.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">Now in the</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">&quot;Projects&quot;</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">table,</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">you will</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">see <span class="hps" style="">only </span>the</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">&quot;Project</span><span style=""></span><span class="hps" style="">2&quot;</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">line.</span></p> <p><span class="hps" style="">Regards.</span></p> 2012-05-05T05:10:41-04:004966889http://forums.asp.net/p/1800212/4966889.aspx/1?Re+Row+level+securityRe: Row level security <p>Thanks for your help Steve and valZ.</p> <p>I missed your solution ValZ when searching (I thought is was related to filtering in the app).&nbsp; I'll give that a try as it looks to what I'm after.</p> 2012-05-05T10:46:15-04:004966935http://forums.asp.net/p/1800212/4966935.aspx/1?Re+Row+level+securityRe: Row level security <p>I also looked at Domain Service DD from&nbsp;<a href="http://channel9.msdn.com/Events/MIX/MIX09">http://channel9.msdn.com/Events/MIX/MIX09</a></p> <p>This looks like a powerful and tidy way of filtering so will also look at using this. &nbsp;SJNaughton has commented this doesn't support many to many's but that should be ok for me at the moment.</p> 2012-05-05T11:56:46-04:004966937http://forums.asp.net/p/1800212/4966937.aspx/1?Re+Row+level+securityRe: Row level security <p><span class="hps" style=""></span></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>biga</h4> <p></p> <p><span class="hps" style=""></span></p> <p>When users log in they should only see the Projects that relate to their ClientType (each user also has a ClientType).</p> <p><span class="hps" style=""></span></p> <p></p> </blockquote> <p></p> <p><span class="hps" style=""></span><span class="hps" style="">Does this mean</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">that the Projects table</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">should also</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">have a ClietType field?</span></p> 2012-05-05T12:03:30-04:004966974http://forums.asp.net/p/1800212/4966974.aspx/1?Re+Row+level+securityRe: Row level security <p></p> <blockquote><span class="icon-blockquote"></span> <h4>biga</h4> <p></p> <p>I have a requirement in my dynamic data web application to restrict table rows depending on the user logged in.</p> <p>I have a Clients table with a ClientType field and a Projects table related to it (Projects table contains a ClientID).&nbsp; When users log in they should only see the Projects that relate to their ClientType (each user also has a ClientType).</p> <p>Searching around I can see that lots of people have asked about a solution for row level security, but I can't see an obvious&nbsp;answer.</p> <p>I'm not necessarily looking for a generalised solution.&nbsp; A specific &quot;where&quot; clause added in a Linq query somewhere or something similar would be ok.&nbsp; I'm not sure on the best place to add the query.</p> <p></p> </blockquote> <p></p> <p>First, you might want to verify your requirements.&nbsp; As described, if you and I had the same client type we could see each other's projects.&nbsp; The words, &quot;are you sure&quot; come to mind when I see stuff like this.</p> <p>As far as the best place to add the query, it's probably a several way tie for first.&nbsp; I prefer stored procedures, but other techniques are equally valid.</p> <p></p> 2012-05-05T12:53:30-04:004967004http://forums.asp.net/p/1800212/4967004.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi ValZ,</p> <p>Because the Projects table is related to Clients this shouldn't be necessary (at least I'm hoping so :-)</p> <p>Because each Project has a Client I should be able to filter by joining to the Clients table.</p> <p></p> 2012-05-05T13:37:12-04:004967006http://forums.asp.net/p/1800212/4967006.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi Dan,</p> <p>Yes the requirements are correct. &nbsp;People with the same client type need to be able to see other people's projects.</p> <p>The use of stored procedures would be good, but being fairly new to this stuff I'm not sure about:</p> <p>1. &nbsp;How to pass the logged in user's details to the stored procedure, so it can filter the results by the users client type.</p> <p>2. &nbsp;How Dynamic Data can make use of stored procedures. &nbsp;My data source is currently build from the tables in the database, so the user can view, edit and delete rows.</p> <p>Thanks</p> 2012-05-05T13:40:18-04:004967102http://forums.asp.net/p/1800212/4967102.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi, Biga.</p> <p><span class="hps" tabindex="-1" style="">Sorry</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">for my</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">importunity</span><span style="">.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">That is,</span><span style=""><span class="Apple-converted-space">&nbsp;e</span></span><span class="hps" style="">ach</span><span style=""><span class="Apple-converted-space">&nbsp;C</span></span><span class="hps" style="">lient must</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">be able to see</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">projects</span><span style=""><span class="Apple-converted-space">&nbsp;of </span></span><span class="hps" style="">all the Clients who</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">belong to</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">his</span><span style=""><span class="Apple-converted-space">&nbsp;ClietT</span></span><span class="hps" style="">ype.</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">I</span><span style=""><span class="Apple-converted-space">&nbsp;</span></span><span class="hps" style="">understand it correctly</span><span style="">?</span></p> 2012-05-05T15:44:25-04:004967109http://forums.asp.net/p/1800212/4967109.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi BigA, Understand your requirements :) and DD only offers two options as already stated ValZ's option is a good way to go, I will be doing somthing like that shortly filtering rows is relativly easy, the big issue you will always face if users typing in a URL they know will get them access to a Edit/Details of some data they should not have access to this is easily fixed using Domain Service project as all Select statments can be prefiltered. In my opinion this would be the most secure method it all depends on how much security you will need.</p> 2012-05-05T15:50:39-04:004967202http://forums.asp.net/p/1800212/4967202.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi, BigA, Hi, Sjnaughton.</p> <p>FilterByRole attribute is one of my little accomplishments. I apply it in real projects about two years. I am sure that it is able to solve this problem.</p> <p>In this case, that's what I suggest. There are tables <strong>Clients</strong>, <strong>Projects</strong> and <strong>ClientTypes</strong>. <strong>Projects</strong> table must have a foreign key columns <strong>clientId</strong> and <strong>clientTypeId</strong>. To the tables <strong> Clients</strong> and <strong>ClientTypes</strong> you must apply <strong>FilterByRole</strong> attribute. For example<strong> [FilterByRole(&quot;clnt&quot;, &quot;clientId&quot;)]</strong> and <strong>[FilterByRole(&quot;clntType&quot;, &quot;clientTypeId&quot;)]</strong>. Add this roles to a specific client.</p> <p>&nbsp;A small note. Since the FilterByRole attribute deletes the ALL item, you must supply an additional parameter - withAll.</p> <p>Thus, the <strong>Projects</strong> table will have two filters: <strong>Client</strong> (with All), and <strong>ClientType</strong> (without All). As a result, if the Client filter will be selected All, you can see all Projects of your clientType. Otherwise - only your own projects.</p> <p>Regards.</p> 2012-05-05T18:43:02-04:004967241http://forums.asp.net/p/1800212/4967241.aspx/1?Re+Row+level+securityRe: Row level security <p></p> <blockquote><span class="icon-blockquote"></span> <h4>valZ</h4> A small note. Since the FilterByRole attribute deletes the ALL item, you must supply an additional parameter - withAll.</blockquote> Hi ValZ this should be doable (adding an ALL that only shows your own Projects) as I am working on somthing like this for my Cascading Hierachcal Filter :) I will try and remember to post here when its done. <p></p> 2012-05-05T20:05:54-04:004967382http://forums.asp.net/p/1800212/4967382.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi, Sjnaughton.</p> <p>In my view, the Client filter should have two items - All and user`s own ClientId. ClientType filter should have only one item - user`s own clientTypeId. Thus, if the Client filter will be selected All, the user will see all their own and others &nbsp;projects of the same clientType. Is not it?</p> <p>Oh, and one more thing. Although I did not quite understand the place of the cascade filter in this example, I want to express my gratitude and admiration of thy works and in particular of Cascading Hierachca :).</p> 2012-05-06T03:51:40-04:004967536http://forums.asp.net/p/1800212/4967536.aspx/1?Re+Row+level+securityRe: Row level security <p>HI ValZ, the thing I am working on with Cascade Hierachical Filter is take this hierachy</p> <p>Manufacturer-&gt;Model-&gt;Style</p> <p>and lets say you have three Manufacturers</p> <p>VW<br> Audi&nbsp;<br> Ford</p> <p>at the moment if you select a Manufacturer or Model then the filter will not be applied byt with me new version that I am working on if you select say Ford you will get all Ford cars listed in the list page. So the query will essentialy get a list of all Ford car PKs and then do a mult FK filter on them :)</p> 2012-05-06T09:35:33-04:004968581http://forums.asp.net/p/1800212/4968581.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi Steve, ValZ,</p> <p>Thanks for your advice. &nbsp;I am going to try Domain Service because if users can edit the URL and get to data they shouldn't see that will be a problem for me. &nbsp;</p> <p></p> 2012-05-07T08:17:52-04:004968629http://forums.asp.net/p/1800212/4968629.aspx/1?Re+Row+level+securityRe: Row level security <p></p> <p></p> 2012-05-07T08:40:59-04:004969930http://forums.asp.net/p/1800212/4969930.aspx/1?Re+Row+level+securityRe: Row level security <p></p> <blockquote><span class="icon-blockquote"></span> <h4>biga</h4> <p></p> <p>if users can edit the URL and get to data they shouldn't see that will be a problem for me. &nbsp;</p> <p></p> </blockquote> <p></p> <p>I decide this issue in such a way</p> <p>&nbsp;</p> <pre class="prettyprint">protected void Page_Init(object sender, EventArgs e) { if (Request.UrlReferrer == null) Response.Redirect(&quot;~/Default.aspx&quot;); }</pre> <p></p> 2012-05-08T03:53:01-04:004971116http://forums.asp.net/p/1800212/4971116.aspx/1?Re+Row+level+securityRe: Row level security <p>Hi valZ,</p> <p>Thanks, presumably that is a foolproof method and UrlReferrer will always be null if they don't get to the page by linking from a previous one?</p> <p></p> <p></p> <p></p> 2012-05-08T15:06:41-04:00