通过 Web 保护文件:基于细粒度授权的文件访问
我有一个员工可以上传文件的系统。可以通过三种方式
以公开、私有或保护模式上传到我的帐户
以公共、私人或保护模式上传至部门帐户
以公共、私有或受保护模式上传到组织帐户
,其中公共对任何人可见,私有仅对组或个人开放,对组织中的任何人都受保护。
组织的所有文件都存储在文件服务器上的 /files/
文件
+-- 234809
| +img1.jpg
| +doc1.pdf
+-- 808234
| +doc2.pdf
我将文件路径和隐私级别存储在数据库中。因此,我可以控制是否在给定页面上向用户显示文件 URL 的链接。
问题是,我无法控制文件的 URL...因此,如果有人在浏览器的地址栏中输入 img1.jpg 的 URL,则无法知道登录用户是否有资格查看 img1 .jpg。
有什么建议吗?
它是一个Java应用程序。但是,Glassfish 有一个单独的实例充当文件服务器。由于该应用程序尚未发布,因此我们愿意采用更好的文件访问策略。
访问文件的用户可能已登录,也可能未登录。但是,如果我们知道正在访问的文件是私有文件或共享文件,那么我们始终可以通过重定向到登录页面来对用户进行身份验证。
谢谢
尼尚特
I have a system where employees can upload files. There are three ways
Upload to my account in public, private or protected mode
Upload to department account in public, private or protected mode
Upload to organization account in public, private or protected mode
where public is visible to anyone, private to the group or person only and protected to anyone in the organization.
All the files for an organization are stored in a directory say, /files/<organizationId>/, on file server
like
files
+-- 234809
| +img1.jpg
| +doc1.pdf
+-- 808234
| +doc2.pdf
I am storing file-path and privacy level in DB. So, I can control whether to show link to a file URL to an user -- on a given page.
The problem is, I do not have any control over file's URL... so, if some one types the URL to img1.jpg in his browser's address bar, there is no way to know whether a logged in user is eligible to see img1.jpg.
Any suggestion?
Its a Java application. However, there's a separate instance of Glassfish working as file-server. Since the app is not released yet, so we are open to adopt to a better file access strategy.
The user who are accessing the files may or may not be logged in. But we can always, authenticate a user by redirecting to login page if we know that the file that is being accessed, is a private or shared.
Thanks
Nishant
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你提出了一个有趣的问题,你对这个问题的理解是正确的。
根据提供内容的 IIS 版本,如果内容位于您的虚拟目录中,您甚至可能没有访问控制权。
此类场景的典型解决方案是将文件存储在无法通过 Internet 访问的目录中,并使用受保护的 HttpHandler 并将文件流式传输出去。
有多种方法可以实现此目的,最简单的是将 HttpHandler 映射到不存在的目录(例如 /downloads),并从 RequestUri 中解析文件名,设置正确的内容类型并将文件写入 Response。
在这种情况下,您的 HttpHandler 受到保护,使您能够确定访问权限。
You pose an interesting question and your understanding of the problem is correct.
Depending on the version of IIS that is serving the content, you may not even have access control if the content was within your vdir.
A typical solution to this type of scenario is to store the files in a directory that is NOT accessible to the internet and use an HttpHandler that IS protected and stream the files out.
There are several ways to go about this, the simplest being an HttpHandler mapped to a nonexistent directory, say /downloads, and parse the filename out of the RequestUri, set the proper content-type and write the file to Response.
In this case, your HttpHandler IS protected enabling you to determine access.
您可以将文件存储在公共文件夹之外,并使用某种路由来捕获向组织请求文件的任何 URL。然后,您可以以编程方式提供文件,而不是让您的 Web 服务器在没有任何控制的情况下执行此操作。
You could store the files outside of the public folders, and have some sort of route to catch any URL that is requesting a file from an organization. Then you can serve the file programmatically, rather than letting your web server do that without any control.