Forum Stats

  • 3,853,722 Users
  • 2,264,259 Discussions
  • 7,905,436 Comments

Discussions

How dynamically add permissions to policy?

843811
843811 Member Posts: 49,851 Green Ribbon
How do I add "grants" to the policy inside my code? I want to add them programatically. So I want the EQUIVALENT of this:
grant Principal "dan" {
   permission javax.security.auth.AuthPermission "modifyPrincipals";
}

Is there a way to do this? I want to do something like:

java.security.policy.add(new MyPrincipal("dan"), new AuthPermission("modifyPrincipals"));

(I know the above code is wrong, it's merely for explanatory purposes)

Comments

  • 843811
    843811 Member Posts: 49,851 Green Ribbon
    ok, for anyone wondering, all you have to do is extend the Policy class. BUT, be careful.

    JDK 1.2
    -----------
    java.security.auth.Policy is the abstract class you extend

    JDK 1.3 / 1.4
    -------------
    java.security.Policy is the abstract class you extend

    They MOVED it. (Why, I have no idea since the interface is basically the same). Also, you will need to open the file <JAVA_HOME>/lib/security/java.security, and set the "policy.provider" property to point to your class.
    (As well, as give the right to set the policy to your runtime environment)
This discussion has been closed.