Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Problem loading policy file programmatically  RSS feed

 
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to load a policy file into my application using the following code:
/**
*<p>The routine that starts the entire applications.</p>
*
*@paramargsAn array of arguments passed to this application.
*/
public static void main (String[] args)
{
ResourceBundle myResources = FlightReservationSystem.getMyResources ();
System.setProperty ("java.security.policy", myResources.getString ("java.security.policy.client.uri"));
System.setSecurityManager (new RMISecurityManager ());

ApplicationFrame flightReservationApplicationFrame = new ApplicationFrame ();
}
(where "java.security.policy.client.uri" has a value of "client.policy".)
This code is located in 'client.jar'. This jar file also contains 'client.policy' in the base directory of the jarfile.
When I try to run the client application using the following command:
> java -jar client.jar
loads alright to a certain point and then gives me an AccessControlException it tries to read some properties. The error should never be thrown since the 'client.policy' grants read/write access to the properties in question.
Investigating further, I ran the client application again, this time with some debugging switches thrown on as follows:
> java -Djava.security.debug=policy -jar client.jar
The following dump was produced:
policy: caught exception: java.net.MalformedURLException: no protocol: client.policy
policy: reading file:/H:/j2sdk1.4.1_01/jre/lib/security/java.policy
policy: Adding policy entry:
policy: signedBy null
policy: codeBase file:H:/j2sdk1.4.1_01/jre/lib/ext/*
policy: (java.security.AllPermission <all permissions> <all actions>
policy:
policy: Adding policy entry:
policy: signedBy null
policy: codeBase null
policy: (java.lang.RuntimePermission stopThread)
policy: (java.net.SocketPermission localhost:1024- listen,resolve)
policy: (java.util.PropertyPermission java.version read)
policy: (java.util.PropertyPermission java.vendor read)
policy: (java.util.PropertyPermission java.vendor.url read)
policy: (java.util.PropertyPermission java.class.version read)
policy: (java.util.PropertyPermission os.name read)
policy: (java.util.PropertyPermission os.version read)
policy: (java.util.PropertyPermission os.arch read)
policy: (java.util.PropertyPermission file.separator read)
policy: (java.util.PropertyPermission path.separator read)
policy: (java.util.PropertyPermission line.separator read)
policy: (java.util.PropertyPermission java.specification.version read)
policy: (java.util.PropertyPermission java.specification.vendor read)
policy: (java.util.PropertyPermission java.specification.name read)
policy: (java.util.PropertyPermission java.vm.specification.version read)
policy: (java.util.PropertyPermission java.vm.specification.vendor read)
policy: (java.util.PropertyPermission java.vm.specification.name read)
policy: (java.util.PropertyPermission java.vm.version read)
policy: (java.util.PropertyPermission java.vm.vendor read)
policy: (java.util.PropertyPermission java.vm.name read)
policy:
policy: reading file:/C:/Documents%20and%20Settings/Administrator/.java.policy
policy: error parsing file:/C:/Documents%20and%20Settings/Administrator/.java.policy
What is interesting about the dump is the first line, which states that the application is not able to locate the 'client.policy' file at the top of the jar because the name is not a valid URI since the protocol needed to access the file has not been specified.
Thinking maybe that I could address this problem by changing 'client.policy' to 'file:///client.policy', I ran the application again with debugging on and received another error this time, telling me that the system cannot locate the policy file.
Can anyone tell me what I am doing wrong and why passing the value of 'client.policy' to 'java.security.policy' does not work?
Thanks,
Darryl
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am trying to load a policy file into my application using the following code


The consensus in this group is not to use policy files, security managers, codebase parameters, dynamic downloading, or even classpath parameters. It will make it much easier for you (and for the assessor) if you start your server and client as simple as this:
java -jar server.jar
java -jar client.jar
Eugene.
 
Darryl A. J. Staflund
Ranch Hand
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Yes, I am beginning to appreciate that approach to the matter :-) And I think that will be the approach I will take.
Ciao,
Darryl
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!