ASP.NET MVC 中基于文档的安全性 [英] Document-Based Security in ASP.NET MVC

查看:24
本文介绍了ASP.NET MVC 中基于文档的安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经了解 ASP.NET MVC 中基于用户和角色的安全性.但现在我需要一些更细化的东西.

I already know about User and Role-based security in ASP.NET MVC. But now I need something a little more granular.

假设我有一个文件列表,其中一些是用户授权的,一些没有.每个文档在数据库的文档表中都有对应的记录.如果用户具有安全访问权限,则可以下载文档以供查看.如果您有角色,也可以添加文档.每个文档都有一个 URL,每个文档列表都有一个 URL.

Let's say I have a list of documents, some of which the user is authorized for, some not. Each document has a corresponding record in a documents table in a database. Documents can be downloaded for viewing, if the user has security access. Documents can also be added, if you have the role. Each document has an URL, and each document list has an URL.

我想对列表进行安全修剪,以便用户只能看到他获得授权的那些文档.但我还需要对这些列表和文档的 URL 请求进行身份验证,因为没有什么可以阻止用户为他们不再访问的文档添加书签,或者只是在浏览器中输入 URL.

I would like to security trim the list so that the user only sees those documents for which he is authorized. But I also need to authenticate the URL requests for these lists and documents, since there is nothing preventing a user from bookmarking a document they no longer have access to, or simply typing the URL into the browser.

内置的基于角色的安全模型是否适合于此,或者我是否需要创建单独的、基于表的安全?我可以将安全性放在我的存储库中,以便返回的记录已经被修剪,还是应该成为控制器的一部分?我需要一个安全属性来验证控制器请求,还是应该将它作为前几行代码放在控制器方法中?

Is the built-in role-based security model suitable for this, or do I need to create separate, table-based security? Can I put the security in my repository, so that the returned records are already trimmed, or should it be part of the controller? Do I need a security attribute to validate the controller request, or should I just put it in the controller method as the first few lines of code?

推荐答案

@Robert,当您说应该修剪它们(在它们到达视图之前)时,我想您已经回答了您自己的问题.因此,在您的业务逻辑中,作为对存储库的偏好,您可能需要执行 lamda 来修剪多余的部分.

@Robert, I think you've already answered your own question when you said you should trim them (before) they reach the view. So in your Business logic, as a preference over the repository, you might want to do a lamda to trim off the excess so to speak.

我认为我永远不会将任何记录返回到不允许用户查看的视图中.为什么要增加风险和流量?

Im my opinion I would never return any records to the view that the user wasn't allowed to see. Why increase risk and traffic?

至于书签,我认为您需要执行一些业务逻辑,以防止它们在访问权限不再存在时转到 url.

As for the bookmarks I think there you're going to need to do some business logic preventing them from going to the url when access no longer exists.

我认为控制器只是为页面提供数据而没有任何逻辑,因此我更喜欢业务层方法,因为它似乎是一项业务规则.

I thought the controller was simply there to service the data to the page and not to have any logic as such so I'd prefer the business layer approach for this one as it does appear to be a business rule.

这可能不是您的想法,但除非有更好的方法,否则我会使用它.

That might not be what you had in mind but unless there is a better approach it's the one I would use.

这篇关于ASP.NET MVC 中基于文档的安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆