How set policy.provider to be your class?
I have made a class EJBPolicy that extends java.security.Policy (i'm using jdk1.4), and overrides the abstract methods. Then in my java.home folder, I changed the file "java.security" so the property "policy.provider" now reads "EJBPolicy". I also changed the "java.security" file in my installation folder (just to be sure). I do not have that file in "user.home". I also added the EJBPolicy to the classpath (added both the folder it is in, as well as the file itself). Then I ran my application like this:
java -classpath D:\JAAS;D:\JAAS\M -Djava.security.manager -Djava.security.auth.login.config=jaas.conf -Djava.security.policy=jaasazn.policy JaasAzn
The "jaasazn.policy" file gives me the ability to get/set the Policy. I added a method to my policy class called getName(), which returns "EJBPolicy". However, when I do this in my app:
System.out.println(((EJBPolicy)thePolicy).getName());
it results in the error:
java.lang.ClassCastException: sun.security.provider.PolicyFile
If I call Policy.setPolicy() and set it to my class EJBPolicy, then it works. But I thought I was able to make my class the default polciy class. What am I doing wrong?
[1204 byte] By [
6tr6tr] at [2007-9-26 1:25:43]

Hello,
the policy class must be on the boostrap classpath (included in your rt.jar) for this work.
If the custom policy class can not be found, the system calls back to using the default "sun.security.provider.PolicyFile". This is a known bug !
Use the VM-Option -Xbootclasspath
cu jens
P.S: can you send me your example ?
Hello,
at first you should save your origninal rt.jar in jre\lib\.....
You have two way to use you own class:
way a.)
you can create you own jar-file
for a example, my class-files are in e:\....\classes\com\myfile\security :
jar cf myrt.jar com\myfile\security\*.class<-- the new jar file is myrt.jar
I use JBUILDER4-Foundation , in his VM-Option I use the parameter:
-Xbootclasspath:E:\JBuilder4\myproject\MyTest\Classes\myrt.jar;E:\JBuilder4\jdk1.3\jre\lib\rt.jar
This means, myrt.jar will load at first, then the rt.jar
Jbuilder4 call it so:
E:\JBuilder4\jdk1.3\bin\javaw -classpath "E:\JBuilder4\myproject\MyTest\classes;E:\JBuilder4\jdk1.3\demo\jfc\Java2D\Java2Demo.jar;E:\JBuilder4\jdk1.3\jre\lib\i18n.jar;E:\JBuilder4\jdk1.3\jre\lib\jaws.jar;E:\JBuilder4\jdk1.3\jre\lib\rt.jar;E:\JBuilder4\jdk1.3\jre\lib\sunrsasign.jar;E:\JBuilder4\jdk1.3\lib\dt.jar;E:\JBuilder4\jdk1.3\lib\tools.jar" -Xbootclasspath:E:\JBuilder4\myproject\MyTest\Classes\myrt.jar;E:\JBuilder4\jdk1.3\jre\lib\rt.jar mytest.App
way b.)
if you want to insert your class file in the big rt.jar-file:
jar uf rt.jar com\myfile\security\*.class
so, then you don't need the VM-Option -Xbootclasspath .
If you want to check which Policy-class is loaded:
System.out.println("Es wird folgende Policy classe verwendet");//which policy class is used ?
System.out.println(Policy.getPolicy());// print the policy class
System.out.println("ende der Policy classe info"); // end of policy info
Here is a example of my java.security-file:
#policy.provider=sun.security.provider.PolicyFile
policy.provider=com.myfile.security.MyPolicyFile
# this is my own policy-class
I hope, I could help you,
greetings, jens
reichert.jens@gmx.de
thanks. I did put my class into rt.jar, but the problem is that I get IllegalAccessException whenever I try to access any method on it.
The error goes away when I take the class out of rt.jar.
Any ideas why?
Also, the exception says it's on accessing MyPolicy.<init> but there was no init method, and then when i added the init method, i still got the same error.