Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AccessControlException with a custom ClassLoader

 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a very basic database brower application. To provide the most fexibility, I allow users to enter the connection string and choose the *.jar file that contains the JDBC drivers for their database. Each JDBC driver is loaded using a custom ClassLoader that I created. The allows the user to connect to an Oracle, PostgreSql, MySQL, databases all at the same time and, by specifying the *.jar files themselves, I do not have to distribute dozens of jars with my application.
When I start the application via WebStart, the the signed jar files successfully all <AllPermission>. However, when my custom ClassLoader tries to read the jar file that a user specifies, I get an AccessControlException. Specifically, the exception is being thrown when my code hits the File.isDirectory() method (The custom ClassLoader I created can be given a directory and it will pickup every *.jar file in that directory).
Does anyone have any idea why my custom ClassLoader would not be able to access the jar file a user specifies? Do I have to register my custom ClassLoader with the SecurityManager in some way?
Thanks,
Michael.
 
Stijn Luyten
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've come accross something similar when loading dynamically loading jboss classes from webstart
Apparently the allProperties tag only applies to the webstart classloader, not custom classloaders (these use the java.policy file)
The following code fixed it
Policy.setPolicy( new Policy() {
public PermissionCollection
getPermissions(CodeSource codesource) {
Permissions perms = new Permissions();
perms.add(new AllPermission());
return(perms);
}
public void refresh(){
}
});
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
!!!EXCELLENT!!!
That worked!
 
Sudeep Agrawal
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a similar problem.
I need to get a connection from the connection pool
from a Weblogic Server. I need weblogic.jar in my classpath.
The application runs fine from console.
When I deploy it as a WebStart Application i get the following error. Please help.



Originally posted by Stijn Luyten:
I've come accross something similar when loading dynamically loading jboss classes from webstart

Apparently the allProperties tag only applies to the webstart classloader, not custom classloaders (these use the java.policy file)

The following code fixed it

Policy.setPolicy( new Policy() {
public PermissionCollection
getPermissions(CodeSource codesource) {
Permissions perms = new Permissions();
perms.add(new AllPermission());
return(perms);
}
public void refresh(){
}
});



[ May 31, 2006: Message edited by: Sudeep Agrawal ]
 
Sudeep Agrawal
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silly me , Stijn Luyten had given the solution. Use the piece of code Stijn Luyten suggested , put it in a static block in the Main class that has the main method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic