Hello. I want to add at runtime a new RuntimePermission to the set of already existing permissions (java.policy) file. Here is my code:
ProtectionDomain domain = MyClass.class.getProtectionDomain();
final PermissionCollection domainPerms = domain.getPermissions();
Enumeration<Permission> oldPerms = domainPerms.elements();
PermissionCollection newPerms = new Permissions();
//add the old permissions to
while (oldPerms.hasMoreElements()) {
newPerms.add(oldPerms.nextElement());
}
//add my new permission
RuntimePermission rtPermission = new RuntimePermission("accessDeclaredMembers");
newPerms.add(rtPermission);
..
But how do I use the newPerms
object ?
Also I've tried to add the new permission to the oldPerms
but since oldPerms
is read only, I get a nice SecurityException.
Thank you!