It depends on what you are trying to limit.
In general, a public API is not limited. However, unless you provide the untrusted ReflectPermission("suppressAccessChecks") code ReflectPermission("suppressAccessChecks") , it will not be able to access the non-open API in another package.
If you have a list of packages for which you want to restrict access, there are two steps. Firstly, in the properties, Security includes a limited package in the package.access list . Then enter your trusted RuntimePermission("accessClassInPackage." + pkg) code RuntimePermission("accessClassInPackage." + pkg) .
The usual way to distinguish your untrusted code is to download it from another place and refer to different code bases in the policy file when granting permissions.
The Java security architecture is very powerful, but I know that it is also complex; if you want a more specific example, please describe which calls you want to limit, and I will try to be more explicit.
It would be very difficult, perhaps impossible, to do what you want without modifying the java.policy file and / or the java.security file. java.security.Policy represents information in java.policy but does not provide write access. You can create your own implementation of the Policy and set it at runtime if this allows any existing SecurityManager .
Alternatively, you can specify a custom java.policy file as a command line parameter. If you provide a complete application with a kind of launcher, this can be easily done. It also provides some transparency for your users. A sophisticated user can view the permissions that you would like to grant the application.
erickson Apr 21 '09 at 1:01 2009-04-21 01:01
source share