Problems with addClassPath() and access control permissions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problems with addClassPath() and access control permissions

Helio Perroni Filho
Straight to the point
---------------------

Hello all. My name is Helio, I use BeanShell a lot,
but I am getting some bugs with the dynamic class
loading mechanism. I can fix them if no one else is
working on it.

Now for the more articulated version
------------------------------------

Hello all,

My name is Helio, and I am a great BeanShell fan.
Besides using it in my own projects, I always take
advantage of its embedding into jEdit to test Java
code fragments and perform complex search-and-replace
tasks. Unfortunately, I have run into two problems
with the dynamic class loading mechanism, which are
limiting my ability to use BeanShell the way I want:

1 - When I invoke the addClassPath() method several
times in a script, only the first invokation works --
the following ones just get ignored;

2 - When running from an unsigned applet,
instantiating the bsh.Interpreter class throws an
AccessControlException, due to insufficient privileges
to call the getContextClassLoader() method (I can send
an exception trace if anyone is interested).

Have these issues been identified before, and is
anyone working on them? Otherwise, I can fix it.

--
Ja mata ne.
Helio Perroni Filho



               
_______________________________________________________
Abra sua conta no Yahoo! Mail: 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz.
http://br.info.mail.yahoo.com/


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-developers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems with addClassPath() and access control permissions

Wade Chandler-6
--- Helio Perroni Filho <[hidden email]> wrote:

> Straight to the point
> ---------------------
>
> Hello all. My name is Helio, I use BeanShell a lot,
> but I am getting some bugs with the dynamic class
> loading mechanism. I can fix them if no one else is
> working on it.
>
> Now for the more articulated version
> ------------------------------------
>
> Hello all,
>
> My name is Helio, and I am a great BeanShell fan.
> Besides using it in my own projects, I always take
> advantage of its embedding into jEdit to test Java
> code fragments and perform complex
> search-and-replace
> tasks. Unfortunately, I have run into two problems
> with the dynamic class loading mechanism, which are
> limiting my ability to use BeanShell the way I want:
>
> 1 - When I invoke the addClassPath() method several
> times in a script, only the first invokation works
> --
> the following ones just get ignored;
Not sure here.  Sounds like a bug the way you describe
it.  Just to aid someone else as I don't know:

Do you mean you are calling like:
addClassPath("somejar.jar");
addClassPath("anotherjar.jar");

and only somejar.jar is being added?

or

addClassPath("somejar.jar");

later

addClassPath("somejar.jar");

and it is not reloading?  If this case then see if
reloadClasses("some.package.name.in.the.jar") will
reload them.  

That might help someone track it down.  Please report
your findings or let the list know which instance or
use case it is.

>
> 2 - When running from an unsigned applet,
> instantiating the bsh.Interpreter class throws an
> AccessControlException, due to insufficient
> privileges
> to call the getContextClassLoader() method (I can
> send
> an exception trace if anyone is interested).
Nothing to fix here I don't imagine.  It should be
getting the context class loader.  There will be other
dynamic class loading sections which will be affected
by security constraints as well.  To get around this
you need to sign your applet as one must sign a web
start application as well.

>
> Have these issues been identified before, and is
> anyone working on them? Otherwise, I can fix it.
>
> --
> Ja mata ne.
> Helio Perroni Filho

Wade


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-developers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems with addClassPath() and access control permissions

Helio Perroni Filho
--- Wade Chandler <[hidden email]>
wrote:

>> 1 - When I invoke the addClassPath() method
>> several times in a script, only the first
>> invokation works  -- the following ones just get
>> ignored;
>
> Not sure here. Sounds like a bug the way you
> describe it. Just to aid someone else as I don't
> know:
>
> Do you mean you are calling like:
> addClassPath("somejar.jar");
> addClassPath("anotherjar.jar");
>
> and only somejar.jar is being added?

Yes. I've been doing some debugging already, and so
far it seems that BshClassLoader.addURL() is called
only for the first JAR file -- even though, at the
script level, addClassPath() does get called for the
following ones. I'll continue looking into it and see
if I can figure out why.

>> 2 - When running from an unsigned applet,
>> instantiating the bsh.Interpreter class throws an
>> AccessControlException, due to insufficient
>> privileges to call the getContextClassLoader()
>> method (I can send an exception trace if anyone is
>> interested).
>
> Nothing to fix here I don't imagine.

Actually I found a way around this, without signing
the applet. The problem is, when Class.forName() is
given an invalid qualified class name argument (say,
"java.lang.bsh"), the Security Manager, if there is
one, throws an AccessControlException even if the
related class file doesn't even exist in the first
place. No AccessControlException is thrown if the name
is valid but does not relate to a known class, or if
the name relates to a known, correctly named class.

Then why the hell does the exception trace points to a
problem with getContextClassLoader()? No idea, but
"swallowing" the exception -- adding an empty
catch(AccessControlException e) block to the end of
the try..catch block on
BshClassManager.plainClassForName() -- did solve it.
At least, I have done some tests here and it seems to
work just fine.

--
Ja mata ne.
Helio



               
_______________________________________________________
Abra sua conta no Yahoo! Mail: 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz.
http://br.info.mail.yahoo.com/


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-developers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems with addClassPath() and access control permissions

Helio Perroni Filho
--- Helio Perroni Filho <[hidden email]> escreveu:

> > Not sure here. Sounds like a bug the way you
> > describe it. Just to aid someone else as I don't
> > know:
> >
> > Do you mean you are calling like:
> > addClassPath("somejar.jar");
> > addClassPath("anotherjar.jar");
> >
> > and only somejar.jar is being added?
>
> Yes. I've been doing some debugging already, and so
> far it seems that BshClassLoader.addURL() is called
> only for the first JAR file -- even though, at the
> script level, addClassPath() does get called for the
> following ones.

My fault actually. Contrary to what I said,
BshClassLoader.addURL() does get called for all
script-level addClassPath() invokations. The real
problem lies elsewhere.

You see, I am using BeanShell to write build scripts
for a small project of mine. So I was doing something
like:

addClassPath("path_to/tools.jar");
addClassPath("path_to/project_depends1.jar");
addClassPath("path_to/project_depends2.jar");

com.sun.tools.javac.Main.compile(buildArgs);

Which resulted in a lot of "class not found" errors
for the classes contained in the dependency JAR files.
It took me a while to realize that addClassPath()
feeds BeanShell's Base Loader, and that javac never
touches that. Passing the paths to the JAR files as
arguments to javac solved the problem.

Sorry folks, and thanks for your time.

--
Ja mata ne.
Helio



               
_______________________________________________________
Abra sua conta no Yahoo! Mail: 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz.
http://br.info.mail.yahoo.com/


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-developers
Loading...