Custom applet class loader, how?

Fellow Java programmers;
I would like to load 'secure' class files (ie encrypted) into an applet at startup time.
I have code that does this for a normal java program.
How do you go about using a custom class loader in an applet?
Would something like this work? (using say *.Xclass local encrypted class files)
..somewhere in theapplet: init().. runClass()
.public void runClass(name)
{ aCL = new AppletClassLoader(); // extends ClassLoader
Class c = aCL.loadClass(name);
Method m= c.getMethod("main"..)
m.invoke(...);
Your comments or pehaps a code snippet would be appreciated.
Thanks, John

John,
this does not work without modifying the runtime client environment.
Security constraints will prevent you from setting up a new class loader, so you will have to at least grant this permission in a policy file deployed to your clients as you will have to deplay the encryption keys.
As bringing in a new class loader from an applet is highly security critical, this should be backed by a rather strict policy and by signing the applet.
Though the example you provided might work, the class loader implementation itself is not so easy-
If you would like to imitate the findClass() and loadClass() methods from SUN you will see that those are complex and not suitable for "hooking" in an encrypted stream.
You might try an easier way:
Load the class data as an encrypted byte array, decrypt it and use SUNs class loader methods to define a JAVA class out of this byte array:
ClassLoader.defineClass(String�name, byte[]�b, int off, int�len)
This seems to be easier than implmenting your own loader.
Oliver

Similar Messages

  • System Properties Class Loader, how to?

    Hi,
    I am trying to configure the WLS startup class to load some property class into system, i.e example.properties
    What does is it take?

    Hi,
    Step1). Create a Startup class like following:
    package startup;
    import java.util.*;
    import java.io.*;
    public class MyStartUp
        public static void main(String ar[]) throws Exception
               MyStartUp start=new MyStartUp();
                  Properties p=new Properties();
               InputStream stream=start.getClass().getClassLoader().getResourceAsStream("a.properties");
                     p.load(stream);
               System.out.println("\n\n\t Your City is : "+p.getProperty("city"));
    } Step2). Compile the above class like following
    javac  -d . MyStartUp.javaStep3). Now make a Jar which will include your properties file and the above Class
    jar -cvf  MyStartup.jar   startup  MyStartUp.java  a.propertiesStep4). Now put the MyStartUp.jar inside "$DOMAIN_HOME\lib" directory
    Step5). Configure the startup class from AdminConsole then restart your Server.
    Thanks
    Ravish Mody

  • Implementation of Class Loader

    i use resource bundle to load values in the properties object instead i have to use class loader ,how can i use the same

    The JVM source code are available but i do no where "sun.boot.class.path" is defined. I mean in which part of the source code. There are many folders in hotspot source code. As this is a part of bootstrap classloader code, i want to know where is this bootstrap source code.

  • Tomcat Class Loader

    I have setup tomcat 4.1.12 on WinXP. Tomcat is integrated with IIS.
    I am able to work with my web applications. My problem is :
    I cant use my own classes in my application. Tomcat is not able to locate my .class file, i think. I have tried this:
    1) created c:\tomcat4\webapps\myapp\WEB-INF\classes and placing my .class file in it.
    2) created c:\tomcat4\work\Standalone\localhost\myapp\WEB-INF\classes and placing my .class file in it.
    3) placed my .class file under D:\tomcat4\shared\classes
    4) placed my .class file under D:\tomcat4\common\classes
    After each step, I restarted the Tomcat service and the IIS service.
    I checked my Tomcat Application Manager, my application is there but the WEB-INF folder is not visible. But if I rename it and refresh the page, the renamed folders appears. I'm not sure why this is happening. I would be grateful if anyone could clarify this for me.
    I have referred to the documentation - Class Loader - HOW TO ... but cant solve this problem. Did I miss anything?
    Please help.

    Try this create somename\WEB-INF\classes\ fold and add all classes and then create a war file. And put the war file in webapps of tomcat. There is no problem in running tomcat and IIS totgether.

  • How do you invoke custom java classes???

    Could someone post a detailed method of invoking custom java classes that works including what files go where, settings and the way it is invoked etc.
    I have tried various ways from this forum and in the documentation without success. I am using IDM 8. I found these instructions regarding how you would do it if you were writing custom resource adaptors in the deployment tools guide:
    To install a resource adapter you’ve customized:
    1. Load the NewResourceAdapter.class file in the Identity Manager installation
    directory under
    idm/WEB-INF/classes/com/waveset/adapter/sample
    (You might have to create this directory.)
    2. Copy the .gif file to idm/applet/images.
    This .gif file is the image that displays next to the resource name on the List
    Resources page, and it should contain an image for your resource that is
    18x18 pixels and 72 DPI in size.
    3. Add the class to the resource.adapter property in
    config/waveset.properties.
    4. Stop and restart the application server. (For information about working with
    application servers, see Identity Manager Installation.)
    I tried the instructions here but placed my custom class in a folder entitled custom instead of /adapter/sample. Not sure about instruction 3 or whether it is relevent. Anyway nothings working.
    Edited by: masj78 on Nov 25, 2008 3:50 AM
    Edited by: masj78 on Nov 25, 2008 4:03 AM

    Hi,
    The way to add custom class is the same as you followed , put them in the WEB-INF/classes.
    To use the custom adapter ,
    Go To Resources - > Configure Types -> Add Custom Resource .
    Type in the fully qualified class name of the custom adapter you added.and Save.
    Now the new adapter you added should showup in the list of available adapters when you try to
    configure a new adapter.
    (Make sure that the prototype XML of your custom adapter is correct so that it displays the correct name / type for the adapter in the adapter list.
    Thanks,
    Balu

  • Netscape 's inconsistency in the loading of applets/classes

    Please I will appreciate any help.
    I am using Netscape version 4.75 on a Windows NT platform to launch my application.
    My application is a collection of java classes and applet classes and a gif file all zipped
    into an archive ( zip -o ). These classes are written in the old java version 1.0.2
    (unfortunately).The problem is that when it is launched from a netscape browser,
    sometimes all the classes get loaded but other times the loading fails. The zip file is not compressed since we realized that it was failing more often with a compressed zip file.
    SO we removed the zip file... This is how we are launching the application now but this,
    too, creates a problem because there are incidents of partial or incomplete loading of
    the classes. This application has been in use for over 3 years now, what can I do?
    Please help!
    Ike Eke

    Thanks for you quick response.
    I have not tried a jar. Can I jar these classes that were written in java 1.0.2?
    I have recommended that the application be upgraded to 1.1.x but they say there is
    no money to do that, The customer would not fund it.
    This problem does not occur on IE but we do not support IE any way. We run on HP,SUN,
    and Windows NT platforms but this problem occurs only on NT. This is a production problem
    so it occurs very where there is an NT machine ( over 200 NT users out there).
    This is the version of Netscape that was chosen by the customer and yes it occurs on other netscape versions as well. I thought that jar files came with the emergence of java 1.1.x.
    If it is possible to jar this outdated version of java classes, then I am willing to try it but
    what is required to do this?
    Thanks again
    Ike

  • How to extend the JVue applet class using ActiveX Control

    My SR recommendation was to post this here:
    ) How to Extend the JVue Applet class
    This is the preferred solution. However, when using the ActiveX control, my derived JVue class that is specified in autovue.properties is not being instantiated.
    Your ActiveX bridge looks like it's hard coding a "new JVue()" which means I have no integration hook using the ActiveX control.
    To reiterate, if I extend JVue to add functionality and specify it in the autovue.properties, it is picked up when I run it standalone but if I use the ActiveX component, it is not being picked up.
    I have already read all the documentation, have had web conferences with Mahmood and Jeff Chapman and the engineering staff who recommended this approach as the preferred option.

    We have a need to override certain VueBean/JVue method calls to meet our document handling(documents need to handle metadata information and hence change the document loading cycle, ie markup loading/XRef resolution is dynamic). Also the invokeAction/invokeSubAction do not allow parameter passing(which we have requirements for certain actions again due to metadata) so we would like to override the invokeAction method to include custom processing(we will encode the action with parameters).
    We are already using Custom VueActions for other simpler UI event handling that don't have parameter requirements.
    As I said above, these use cases were relayed to the engineering team and senior staff members in early December and we were told that we could proceed with overriding the main class in the autovue.properties file. I have SR(s) opened with a long thread detailing this so I really don't want to go through this again.
    A custom VueAction does not seem to work because it binds to late in the object call/event stream.

  • How to read file in JAR file (the one containing applet class)

    my applet needs to read a file (font file) that will be bundled in the jar file. how do i read that file?
    i tried using
    URL u = new URL("file:///myfont.ttf");
    u.openStream();i got AccessControlException. is there anyway for the applet to load file in the JAR file? i see applet can load image in the jar file so figured that it should be able to do so with some other type of file
    thanks

    The reason you're getting access violation is the way you code your URL -- it's pointing to a file on the user's local disk. If my.ttf is in the jar, try:
          URL url=myApplet.class.getClassLoader().getResource("myfont.ttf");Where myApplet is the name of your applet and the font file is assumedly kept in the same directory level in the jar file as the class file for your applet.
    ;o)
    V.V.

  • How to get applet to load text file and use it

    The applet is loaded from my site and the short text file is updated by a perl script in my cgi-bin, which is called whenever someone loads the html that loads my applet.
    The text file is just a counter string and I'd like to use it to display #.gif's at a certain place on the applet window (no problem there if I can get the text file into the applet).
    How would I get the applet to load the text file into a string or array?
    It has a running thread and I'd like it to update it periodically.

    I believe you can do that with Class.getResourceAsStream.
    Or you can do it explicitly with java.net.* stuff.

  • "ClassNotFoundException" loading custom LookAndFeel class

    Hi!
    I created a custom LaF for my application. It works fine after registering e.g. my new ButtonUI in the myLookAndFeel class:
    Object[] uiDefaults = {
    "ButtonUI", myPackageName + "myButtonUI",
    "CheckBoxUI", metalPackageName + "MetalCheckBoxUI",
    The main program looks something like:
    UIManager.setLookAndFeel(new GUI.mygui.plaf.myLookAndFeel());
    SwingUtilities.updateComponentTreeUI(frame);
    I can change the background-color in myTheme or directly myLookAndFeel (~line 384):
    "Button.background", new ColorUIResource(204, 204, 255),
    Works fine, but when changing the font to:
    "Button.font", new UIDefaults.ProxyLazyValue(          "GUI.mygui.plaf.myLookAndFeel",
         "getControlTextFont"),
    instead of
    "Button.font", new UIDefaults.ProxyLazyValue(          "javax.swing.plaf.metal.MetalLookAndFeel",
         "getControlTextFont"),
    (i.e. not using a standard plaf), i get an error at runtime (from UIDefaults):
    Problem creating GUI.mygui.plaf.myLookAndFeel with method getControlTextFont and args { : java.lang.ClassNotFoundException: GUI/mygui/plaf/myLookAndFeel
    It seems to be a problem with the class loader, but everyone said it isn't a problem any more since jdk1.2.2! I am using jdk1.3.1 on win. Any clue?
    Thanks a lot, Holger

    Even specifying the classpath explicitly with
    java -cp C:\java\ui\classes Main
    (or with ';.' ) doesn't solve it, where the LaF is in
    C:\java\ui\classes\GUI\mygui\plaf\myLookAndFeel.class
    At the point i'm registering the new LaF in the main program he doesn't show any exception. It's in the moment he has to show one of the modified buttons.
    As i explained before, the was a bug report on this topic, i found it again:
    Bug Id 4155617
    It certainly has to do with the class loader, but why do they say the bug is fixed (status: closed), when no one really knows how to make it right?
    The workarounds for the mentioned Bug Ids 4378245, 4120021 and 4138667 don't seem to work.

  • Custom class loader and local class accessing local variable

    I have written my own class loader to solve a specific problem. It
    seemed to work very well, but then I started noticing strange errors in
    the log output. Here is an example. Some of the names are in Norwegian,
    but they are not important to this discussion. JavaNotis.Oppstart is the
    name of my class loader class.
    java.lang.ClassFormatError: JavaNotis/SendMeldingDialog$1 (Illegal
    variable name " val$indeks")
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:431)
    at JavaNotis.Oppstart.findClass(Oppstart.java:193)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at JavaNotis.SendMeldingDialog.init(SendMeldingDialog.java:78)
    at JavaNotis.SendMeldingDialog.<init>(SendMeldingDialog.java:54)
    at JavaNotis.Notistavle.sendMelding(Notistavle.java:542)
    at JavaNotis.Notistavle.access$900(Notistavle.java:59)
    at JavaNotis.Notistavle$27.actionPerformed(Notistavle.java:427)
    JavaNotis/SendMeldingDialog$1 is a local class in the method
    JavaNotis.SendMeldingDialog.init, and it's accessing a final local
    variable named indeks. The compiler automatically turns this into a
    variable in the inner class called val$indeks. But look at the error
    message, there is an extra space in front of the variable name.
    This error doesn't occur when I don't use my custom class loader and
    instead load the classes through the default class loader in the JVM.
    Here is my class loading code. Is there something wrong with it?
    Again some Norwegian words, but it should still be understandable I hope.
         protected Class findClass(String name) throws ClassNotFoundException
             byte[] b = loadClassData(name);
             return defineClass(name, b, 0, b.length);
         private byte[] loadClassData(String name) throws ClassNotFoundException
             ByteArrayOutputStream ut = null;
             InputStream inn = null;
             try
                 JarEntry klasse = arkiv.getJarEntry(name.replace('.', '/')
    + ".class");
                 if (klasse == null)
                    throw new ClassNotFoundException("Finner ikke klassen "
    + NOTISKLASSE);
                 inn = arkiv.getInputStream(klasse);
                 ut = new ByteArrayOutputStream(inn.available());
                 byte[] kode = new byte[4096];
                 int antall = inn.read(kode);
                 while (antall > 0)
                     ut.write(kode, 0, antall);
                     antall = inn.read(kode);
                 return ut.toByteArray();
             catch (IOException ioe)
                 throw new RuntimeException(ioe.getMessage());
             finally
                 try
                    if (inn != null)
                       inn.close();
                    if (ut != null)
                       ut.close();
                 catch (IOException ioe)
         }I hope somebody can help. :-)
    Regards,
    Knut St�re

    I'm not quite sure how Java handles local classes defined within a method, but from this example it seems as if the local class isn't loaded until it is actually needed, that is when the method is called, which seems like a good thing to me.
    The parent class is already loaded as you can see. It is the loading of the inner class that fails.
    But maybe there is something I've forgotten in my loading code? I know in the "early days" you had to do a lot more to load a class, but I think all that is taken care of by the superclass of my classloader now. All I have to do is provide the raw data of the class. Isn't it so?

  • Detecting when exception was thrown using custom class loader

    Hello all,
    I would like to implement the solution described here - http://stackoverflow.com/questions/75218/how-can-i-detect-when-an-exceptions-been-thrown-globally-in-java - that uses custom class loader in order to detect when an Exeption thrown somewhere in the JVM hosting my app, please note that exceptions might be thrown from 3rd party jars the app is using. So, thanks to help I got from another post, I've managed to code the custom class loader. My question is how can the class loader wrap the original exception, as the methods in ClassLoader deals with classes, not instances. So where should I set the original exception?
    Thanks!
    Edited by: user9355666 on Sep 28, 2010 10:48 PM

    user9355666 wrote:
    I think I'm missing something fundumental, forgive me for being slow...
    This is what I did so far. For the exception wrapper I made a simple class extens Exception that recieve Exception in its ctor and store it. I also subclassed ClassLoader and override its loadClass(). I've registered it as the system classloader. My thinking was to check in that point that if the requested class is instance of Exception and if yes, returning my wrapper class wrapping this exception. But, since loadClass() return class, how can I set in the wrapper the original exception?
    In addition, let's say 2 different places in the code throws NPE, to my understanding the classloader will load NPE only once, so how throwing the NPE in the second time can be detected?you are missing a key point. you should creating a custom implementation of the NPE class which hooks into your detection code in its constructor. from that point forward, anytime any NPE (which is your custom class) is constructed, you can detect it.

  • How can I rewrite the java.io.file class to a custom file class?

    Hi All!
    Im new to Java. Well, I did some experiments with small Applets. Because it is not allowed to use Files in an unsigned Applet, I need to know, how I can manage to overwrite the java.io.File class. The background: I have to port some Applications which need file access into Applets.
    I think it is necessary to create a class with the same signature then the Java.io.File that stores the information in an database on the Webserver or read information from there. Then overload the java.io.File with my custom file class.
    Is this possible and, if so, how?
    Thanks!

    Hi yawmark !
    Thanks for the quick answer! My idea to store the filecontent into a database is caused by the plan to make the application-port independent from the workstation executing it. So it would be a nice feature storing the "files" into a database.
    JavaBeginner2009

  • How to configure Class Loading-Import Shared Library using admin_client

    i am deploying ear using below command through command prompt.its deployed successfully.
    java -jar ../admin_client.jar deployer:oc4j:localhost:23792 oc4jadmin oc4jadmin -deploy -file C:/ex.ear -deploymentName ex -bindAllWebApps
    i have one requirement if i deploy thorugh command prompt. while deploying ear through admin console in Deploy: Deployment Settings-Configure Class Loading-Import Shared Libraries-i checked JAXB then the ear will be deployed successafully.
    i need to incorporate same thing in above command also.i have created shared library and jars are placed in this path.
    C:\Oc4J\j2ee\node1\shared-lib\JAXB\2.0
    but while deploying ear using admin_client.jar command script i need to configure classs loading and import above shared library.how to modify the script?

    Ours is not a Desktop Application, but we want to handle Authentication(Which authenticates the userid and password by making a Tuxedo call) and add the Principal to Subject in session, so that ADF Authorization and securityContext can be used as is,
    but doing this with Custom Authentication Provider in weblogic needs me to have a lot of Tuxedo Service related jars in weblogic/system classpath which i feel is not right thing to do, as the same jars are required in application also, which means i will have the jars in class path twice and i need to deploy the jars to both places everytime there is any change.
    Is there any way by which i can set Authenticated principal to Subject in the created session from within Application?

  • Can I dinamicly load a class with custom class loader ?

    Can I dinamicly load a class with custom class loader ?

    Hi,
    I was wondering if you found answer to your question, and also were you using your custom class loader inside a signed applet as I am in a similar situation, and was wondering if you could help me. An example would be great...
    Thanks a lot.
    Regards.

Maybe you are looking for

  • Ipod 2G speaker doesn't work after iOS 4 update

    I've just posted a message with the music that "lags" with the new software update and on top of that I now found out the the build in speaker of the Ipod stopped working to! Please help! Message was edited by: Paulf88

  • Hard Drive Crashed - No Backup Available - Anyway to retrieve purchases?

    My 3 year old dumped a bottle of pop on my 6 month old laptop last week and I lost everything - with no backup of course. Is there anyway to get my itunes purchases re-downloaded on my new install without having to purchase them again?

  • Migration- downpayment requests and downpayments - how to clear

    Hi, we want to migrate open down-payments from source system and create downpayment request with the balance of the open amounts. After that we intend to clear through F-32 those documents in the custoemr account. Aim should be however that the downp

  • Spool get lost while job runs in background

    Hi We wrote a custom program where in we use two custom bapi's which were copied from original bapi's. When we run this interface program in backgroud, we have lost the spool. But when we run the test with limited data in foreground, it works fine. W

  • Time Machine backup fails about once a week

    I'm backing up to an external firewire drive. About once a week, a Time Machine backup will fail. I have no other information on the failure. There are no errors in any of the log in Console.app. Time Machine simply reports "Last Backup Failed", and