[Aglets-users] Fwd: Urgent need help! Problem with file access permissions-Aglets
Status: Beta
Brought to you by:
cat4hire
From: Thomas H. <max...@us...> - 2012-03-31 18:58:08
|
(Forgot to send this to the list) ---------- Forwarded message ---------- From: Thomas Herlea <max...@us...> Date: Sat, Mar 31, 2012 at 19:23 Subject: Re: Urgent need help! Problem with file access permissions-Aglets To: shruti nagani <shr...@gm...> Dear Shruti, The security exception you got does not mean the aglet is prevented from accessing the file, but that it is prevented from finding out what the current directory is. That is what the 'user.dir' property stores. See http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html for a list of system properties. Perhaps you are using a relative path to your file in your code and therefore at some point the method for accessing the file has to first look up the current directory, at which point it throws the exception. You can use the AccessControlException messages to guide you in adding the required permission to the 'aglets.policy' file. It mentions the missing permission type, 'java.util.PropertyPermission', so you should look it up to see how it is granted (http://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html#PropertyPermission). You will discover the parameters available when granting it. These parameters are specific to the permission type, so you really need to look in yhe documentation. For PropertyPermission you specify a pattern to match one or more properties, in your case 'user.dir' or something with wildcards which covers 'user.dir', too. Then you provide in the grant of a PropertyPermission an action about the property or properties matching the first parameter. In your case 'read' is needed, but you also can grant a 'write' permission or both, using the list syntax specified in the documentation. I think it is an interesting problem to determine during development which permissions an aglet may need. Does anyone know a more automated method than looking up in the API documentation which AccessControlExceptions every method call might throw? The guide linked to above does have a section "Methods and the Permissions They Require", but if the method listed there is called internally by another standard library method which you call, I don't know if it is easy to determine what exceptions may be thrown indirectly like that. Good luck! Thomas On Sat, Mar 31, 2012 at 16:28, shruti nagani <shr...@gm...> wrote: > > Hi, > > I am accessing a file on my system from an aglet whose code is also on my system > I am getting the following exception: > > java.security.AccessControlException:access denied ("java.util.PropertyPermission" "user.dir" "read") > > at java.security...etc etc > > > I edited the aglets.policy in $HOME/.aglets/security and appended the following line > > permission java.io.FilePermission "C:\\Users\\new\\Documents\\arffs\\bayes_labeled.arff", "read"; > > to all 3 sections, (atp, http and file) > > bayes_labeled.arff is the file I need to read > > I am still getting the same exception. Please someone tell what am I doing wrong here? > > I'll be very grateful! Have been stuck on this for the past week. > > Thanks a tonne in advance!! > > Shruti |