title: Java security policy: granting access depending on classloader
body: <p>I have an application that loads plugins (plain jar files) and runs code from them. The plugins are loaded using an URLClassLoader. I would like to prevent those plugings from accessing files and other resources, while retaining all permissions for my own code.</p>
  
  <p>Here are the two features by which plugin code is distinct from my own application and its libraries:
  1) It is loaded by a URLClassLoader created for this purpose.
  2) Its jar files are copied to a specific directory, from which the URLClassLoader takes them.</p>
  
  <p>But I don't see how I can use either feature to formulate a policy rule. The classloader can't be used at all in a policy rule (understandable, it's created at runtime). The directory can be used to grant specific permissions but not to take them away. There doesn't seem to be a syntax for "code from anywhere EXCEPT this directory" either.</p>
  
  <p>Are there any other options?</p>