Link to home
Start Free TrialLog in
Avatar of mkaplunov
mkaplunov

asked on

WebLogic and custom ClassLoader. HELP!!!

People,

I'm stuck here... According to what I have read so far (and please correct me if I am wrong), it is impossible to write a custom class loader and force Weblogic to use this class loader instead of its own. It is possible though to load classes explicitly using your own custom class loader by doing something like this (as far as I can tell):

MyCustomClassLoader cl = new MyCustomClassLoader();
Class c = cl.loadClass(name, resolve);
Object obj = c.newInstance();

Is it at least possible to make Weblogic use MyCustomClassLoader for a specific JAR file or a package? I have read something about weblogic-application.xml, but neither sure that it would work nor could I find any examples how to set it up.

PLEASE HELP!!!

P.S. I can add more points if you find my question to be "extremely difficult".
Avatar of Venci75
Venci75

what do you want to load with your custom class loader?
Avatar of mkaplunov

ASKER

Encrypted class files, which my MyCustomClassLoader would have to decrypt.
Avatar of girionis
 Yes you can write and use your own classloader to load classes. Not sure though how you can set up WebLogic to use your own classloader and not the default one. Have you checked the documentation? Does it say anything?
To girionis:
I have already read this focument and couldn't find how to make Weblogic delegate class loading to my own class loader...
 The delegation of the classloading is left up to the parent on the hierarchy. If the child classloader cannot load the class then it asks the parent classloader to do it. If the parent cannot load the class then it asks the "grandparent" to do it etc. So I guess it is only a matter of putting your classloader higher at the classloading hierarchy. At least this is the case how classloaders work in the VM.
If that is the case, then how can I put my classloader higher in the hierarchy?
 Does the section "Declaring the Classloader Hierarchy" not explain it?
I was looking for an example other than that provided by BEA...
And by the way, according to this document a custom classloader first tries to delegate the loading of any requested class to its parents and only when neither one of them can do it, tries do load the class itself.
 Yes true, sorry. The child classloader asks the parent first and if the parent hasn't already loaded the class or can't load the class then the child loads it. Sorry for the misinformation.
 .. so theoretically putting your custom classloader higher in the hierarchy would do since it will have priority over its "children".
Theoretically - yes, but I need to find out if this can be done practically and how to do it (if it is possible at all).
 .. so theoretically putting your custom classloader higher in the hierarchy would do since it will have priority over its "children".
 Sorry for the double post.

>  but I need to find out if this can be done practically and how to do it (if it is possible at all).

  What do you mean how you can do it praactically? If you have written a classloader already can you not run it like: java <your classloader> <class to load> ?
That part is easy. I have written a classloader and made it load the classes I have (via command line). The hard part is to make it work under Weblogic...
 From what I have read from the link above if you edit the weblogic-application.xml file you can define your own classloader. The top-level element includes an optional classloader-structure element. If you do not specify it then the standard classloader is loaded.

  What happens if you specify your own classloader there?
> I have written a classloader

Whats stopping someone simply using the classloader class directly to decrypt your classes?
To girionis:
Right. Do you have a working example? I would like to see an example where a custom classloader is specified.

To objects:
I've thought of algorithm to prevent that.
Can you share any details of the algorithm. I would think it would be a simple matter to use your custom class loading to extract the decoded bytecode, as these have to be passed to the vm.
Am interested in hearing your approach.
To objects:
Please don’t think that I’m an ingrate, but I can’t. I’m under contractual obligations… What I can tell you is that you are right, it’s fairly simple to use my custom classloader, but I have made it very hard to obtain the decryption key, even if my code is reverse-engineered. Sorry, but that’s all I can tell now…
Thats fine, I understand.
I just would have thought if WebLogic can access the key, then the WebLogic administrator (who I assume you are protecting against) also can.

Best of luck with it :)
> Right. Do you have a working example? I would like to see an example where a custom classloader is specified.

  No, sorry I do not have an example. What I would do wodl be to experiment with the configuration files until I come up with a solution (save a copy of the original files just in case).
I have gotten around this by explicitly using my custom classloader, but now I am getting a SecurityException when I call defineClass method.
 Can you post the exact error message?
I screwed up somewhere along the way... MyCustomClassLoader is working now.
Dear expert(s),

A request has been made to close this Q in CS:
https://www.experts-exchange.com/questions/20590119/I-would-like-to-withdraw-the-following-question.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
 Speaking from my point of view, since our comments did not help the asker to solve his problem I think it is a fair decision.
 It would also be good for the questionner to let us know the steps he took to solve the problem. Since it will be a PAQ other people will be spending points to get an answer, so it will be good to get an answer worth of the points they spent.
The problem wasn't solved. I had to load classes by explicitly calling MyCustomClassLoader...
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial