title: Limiting file access in Java
body: <p><strong>Problem:</strong><br>
  In my Java application (not an applet) I wish to limit certain file operations to all classes except a list/group/package of classes that should not be restricted.</p>
  
  <p>Specifically, I would like to limit...</p>
  
  <ul>
  <li>File reads</li>
  <li>File writes</li>
  <li>File creation</li>
  <li>File deletion</li>
  </ul>
  
  <p>...such that they can only be done within the current working directory for all but the unrestricted classes.</p>
  
  <p><strong>SecurityManager attempt:</strong><br>
  I have tried to implement a subclass of the SecurityManager class that implements this behaviour, however it seems that when checks are made the <em>file</em> information provided does not give more than just the filename (unless I am missing something?).</p>
  
  <p>Also, I don't quite understand how in this case I could find out the class which the call is being made from, to allow me to determine whether to allow the operation or throw an exception. Is there any way I could get all the information I need for this approach to work?</p>
  
  <p><strong>Policy-based attempt:</strong><br>
  I am also aware that Java policies are intended for restricting the actions of classes, including things such as file operations. However, I've really struggled to find a good resource to learn how I could go about solving my problems using a <em>.policy</em> file.</p>
  
  <p><strong>Summarisation of question:</strong>  </p>
  
  <p><strong>1)</strong> Are there any alternative approaches that may be preferable to those I've mentioned?</p>
  
  <p><strong>2)</strong> Is this possible using a SecurityManager? Am I missing out on how I should actually be implementing such an approach?  </p>
  
  <p><strong>3)</strong> Is this possible using a policy file? Are there any good resources I've missed on this front?</p>
  
  <p><em>I'm really not adversed to any amount of hard work I need to invest in achieving this- I'm just unsure as to how I should approach it properly. I'm also sorely lacking in good resources to teach me enough about the two possible approaches I've mentioned, to allow me to implement it myself. Above all, I'm not afraid of significant reading where required!</em></p>
  
  <p><strong>Thanks</strong> for any help you can give, in advance.</p>