如何将用户限制为 ASP.Net 2.0 中的数据子集?
想象一个 ASP.Net 2.0+ 应用程序,它使用内置的基于角色的安全性来限制用户只能访问某些页面或操作。
进一步假设存在规则,这些规则根据用户的属性将各个用户限制为数据子集(无论这些规则是如何实现的)。例如,经理只能查看自己下属的绩效历史记录。销售经理只能查看他或她自己的销售代表的销售目标完成情况信息。销售代表只能查看自己客户的待处理订单。
这些规则会影响下拉列表和其他多记录显示的填充方式,以及可以在文本框中键入哪些值以进行搜索和查找。还有许多其他可能的功能和屏幕类型可能会受到影响。所以这是一个跨应用程序的问题。
我的问题:什么样的模式或技术可以使在应用程序中实现此类限制变得更容易?
Imagine an ASP.Net 2.0+ app that uses the built-in role-based security to restrict users to certain pages or actions.
Further suppose that rules exist that restrict individual users to subsets of data based on the user's attributes (however those are implemented). For example, a manager can only look at performance history for his or her own subordinates. A sales manager can only look at sales target achievement information for his or her own sales reps. A sales rep can only look at pending orders for his or her own customers.
These rules affect how dropdowns and other multi-record displays are filled, and also what values can be typed in to textboxes for search and lookup purposes. There are many other possible functions and screen types that could potentially be affected. So this is a cross-app concern.
My question: what kind of patterns or techniques would make implementing such restrictions across an application easier?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以实现存储库模式。然后,当您调用它时,您会传入当前用户并限制基于该用户返回的数据,或者在构建存储库时传入用户。
存储库模式
有些喜欢
You could implement the repository pattern. Then when you make calls to it you pass in the current user and restrict data returned based on that user or pass in the user when you construct the repository.
Repository Pattern
Some like
自从OP提出最初的问题以来,很多水已经流到了桥下。当时提供的答案很棒,但它们都需要编码。
从那时起,基于属性的访问控制(abac) NIST提出的访问控制模型已经相当成熟。 ABAC 帮助您将授权逻辑表达为可配置策略,您可以在中央策略决策点外部定义、维护和执行这些策略。
有多种实施 ABAC 的解决方案。我建议您查看维基百科以获取更多信息。
A lot of water has gone under the bridge since the OP's original question. The answers provided were great then but they all require coding.
Since then, attribute-based access control (abac), an access control model put forward by NIST, has matured considerably. ABAC helps you express your authorization logic as configurable policies which you define, maintain, and execute externally in a central policy decision point.
There are several solutions out there that implement ABAC. I recommend you check out Wikipedia for more information.
考虑使用您自己的自定义属性来解决这些横切问题,并可能使用基于声明的身份系统(例如 IClaimsIdentity - Windows Identity Foundation)来实现所需的属性。
由于您在此处根据用户控制数据 - 我还会研究 Web 表单的模型视图演示者模式,因为您正在绑定数据等。
请参阅:http://msdn.microsoft.com/en-us/library/ff647117 .aspx
这使您可以根据您拥有的任何定义的权限更好地测试您的输出,并提供更好的方法来跟踪与组合框等的绑定,而不是在代码中添加一堆垃圾。
Consider using your own custom attribute for these cross cutting concerns and implement possibly with a claims based identity system (ex. IClaimsIdentity - Windows Identity Foundation) for required attributes.
Since you are controlling data here based on users - I would also look into the Model View Presenter pattern for webforms since you are binding data, etc.
See: http://msdn.microsoft.com/en-us/library/ff647117.aspx
This allows you to better test your output based on whatever defined permissions you have and provides a better way to track your bindings to combo boxes, etc. than sticking a bunch of junk in your code behind.