aspose file tools*
The moose likes JNLP and Web Start and the fly likes AccessControlException with a custom ClassLoader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JNLP and Web Start
Bookmark "AccessControlException with a custom ClassLoader" Watch "AccessControlException with a custom ClassLoader" New topic
Author

AccessControlException with a custom ClassLoader

Michael Remijan
Author
Ranch Hand

Joined: May 29, 2002
Posts: 110

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.


Java EE Evangelist — Author, EJB 3 in Action 2nd Edition — Java Community Process Member
Stijn Luyten
Greenhorn

Joined: Feb 07, 2003
Posts: 4
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

Joined: May 29, 2002
Posts: 110

!!!EXCELLENT!!!
That worked!
Sudeep Agrawal
Ranch Hand

Joined: May 31, 2006
Posts: 34
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

Joined: May 31, 2006
Posts: 34
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: AccessControlException with a custom ClassLoader
 
Similar Threads
AccessControlException
AccessControlException using custom ClassLoader with WebStart
AccessControlException
AccessControlException
AccessControlException