Is it possible to ristrict folder access through policy file?

Hi,

Application is having download file functionality. I want to make sure that files should be download from only form specific set of folders. Validating folders and path is tedious at application level. Is it possible to set only few folders, which should be used while downloading the file? i.e. downlaod file should not accept any other path or folder not mentioned in policy file.

I am checking the documentation on grant {permission java.io.FilePermission ...}. I am still not clear on this topic

Is it possible with security policy file or is there any other mechanism in java?

Thanks in advance.

vb

[644 byte] By [Vasu.Babu_Pa] at [2007-11-27 0:04:25]
# 1

It is possible. Just grant a FilePermission 'read' to each of the desired folders, specifying the folder/- form if you want to include subfolders, otherwise folder/*. Then in your application catch AccessControlException in appropriate places, i.e. where you open files for download. Note that this is a RuntimeException so the compiler won't make you catch it.

ejpa at 2007-7-11 15:59:27 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 2

Thanks for the information. Including subfolders is useful info.

Unclear part is that by default jvm take all folders? Is there any statements in policy file mention that access all folders by default?

Do i need to disable access all folders once i included my set of allowed folder?

Thank you ejp.

Vasu.Babu_Pa at 2007-7-11 15:59:27 > top of Java-index,Security,Other Security APIs, Tools, and Issues...
# 3

If you don't have a security manager you can do anything. Otherwise you can do hardly anything. You will get a lot of other AccessControlExceptions so you'll find you have to add quite a few permissions. The AccessControlExceptions will tell you which permissions you need!

if (System.getSecurityManager() == null)

System.setSecurityManager(new SecurityManager());

ejpa at 2007-7-11 15:59:27 > top of Java-index,Security,Other Security APIs, Tools, and Issues...