I am building a distributed system where class files are downloaded from remote machines and executed locally. I use a custom ClassLoader implementation to retrieve necessary classes.
However, I want to ensure that the remote code which is executed locally is not allowed to use files, invoke System.exit()... etc. In other words, I want to ensure that the remote code is executed in a sandbox.
Also, I need t ensure that the rest of the application is not affected by these limitations.
If I am to use a SecurityManager and a policy file, how can I ensure that only the code remotely loaded by my class loader is limited from permissions ?
Any suggestions to solve this issue is greatly appreciated.
I looked into the code, but found some methods are deprecated now, and I couldn't find an alternative way to get the code working without those methods (JavaDoc says to use checkPermission but I couldn't find out how that could be helpful to find which classloader loaded the class).
Finally, I got it working using policy files.
Here's what I did:
In my ClassLoader, I used the "http://my.remote.loaded.code.base" as the CodeSource when I defined my classes.
Code Base "file:/-" matches with rest of the classes, which are loaded from the file system.
So this way, I got my remote code running in a sandbox. [ August 01, 2008: Message edited by: Yohan Liyanage ]