Java security problem

D

DeMarcus

Hi,

I want to do a simple plugin interface so programmers
can easily write their own plugins to my software.
However, when I use URLClassLoader to load a class
that shall represent the plugin it seems that there
are a lot of security constraints that makes the
plugin limited.

For instance I can't have inner classes in the plugin,
because that gives me an IllegalAccessError. I tried
to avoid that by calling the methods of the plugins
with means of doPrivileged(), but it didn't help.

How can I be back to normal programming again despite
I'm using URLClassLoader?

Thanks
Daniel
 
G

Guest

Hi,

I want to do a simple plugin interface so programmers can easily write
their own plugins to my software. However, when I use URLClassLoader to
load a class that shall represent the plugin it seems that there are a lot
of security constraints that makes the plugin limited.

Most plugins are defined by a certain Interface or extend an abstract
class. It is convenient to place all plugins within a specific directory
(often referenced by a property). You must also somehow tell your program
which plugin(s) to load using a ClassLoader which knows where to look.

Class clazz = Class.forName("com.mycompany.MyPlugin", true, loader);
Plugin plugin = (Plugin) clazz.newInstance();

From there, only access the methods defined in your Plugin interface.

HTH,
La'ie Techie
 
D

DeMarcus

LÄÊ»ie Techie said:
Most plugins are defined by a certain Interface or extend an abstract
class. It is convenient to place all plugins within a specific directory
(often referenced by a property). You must also somehow tell your program
which plugin(s) to load using a ClassLoader which knows where to look.

Class clazz = Class.forName("com.mycompany.MyPlugin", true, loader);
Plugin plugin = (Plugin) clazz.newInstance();

From there, only access the methods defined in your Plugin interface.

HTH,
La'ie Techie

Actually I'm doing exactly as you propose, but instead of
Class.forName() I use clazz = loader.findClass( "MyPlugin" )
where loader is a URLClassLoader.

Is there a difference in Class.forName() and loader.findClass()?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top