This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes How would you design this?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How would you design this??" Watch "How would you design this??" New topic

How would you design this??

Steve Fording

Joined: Dec 14, 2004
Posts: 4
I have an application which uploads files via a web form, and stores information about the files (size, path info etc.) in a db2 table, and then writes the files to a directory in the file system. Users can download these files via links displayed in a jsp. My problem is how to limit access to the files to only the correct group of users, since the files with technically lie outside the application in a different directory. There is no problem limiting access to the jsps which display the links, but there is nothing to stop a user (who has the right url) from accessing the files directly. Currently the application uses a .htaccess file and leaves it up to the web server to limit access to the files, but this approach is only good for one group of users. We need something more dynamic where different users will have access to different files. Any suggestions are appreciated!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Can you give the users NO access to the actual file directory and download the files through a servlet? That changes the files from static content to dynamic content. Then the servlet could check user roles or permissions against attributes in your file meta-data before downloading.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Steve Fording

Joined: Dec 14, 2004
Posts: 4
Yes that might be a possibility. How would you go about downloading the files using a servlet?
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I think you would set a value in the link and catch that in the doPost, doGet methods. You would then map that 'key' to that actual location, in the file system, of the file.
I agree. Here's the link:
subject: How would you design this??
It's not a secret anymore!