Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Error while running Applet

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Error while running Applet

    When ever I run my Applet , I am getting error as ,

    java.lang.SecurityException: trusted loader attempted to load sandboxed resource from file:/C:/CryptoApplet/Ramesh/right/
    at com.sun.deploy.security.CPCallbackHandler$ParentCa llback.check(Unknown Source)
    at com.sun.deploy.security.CPCallbackHandler$ParentCa llback.access$1500(Unknown Source)
    at com.sun.deploy.security.CPCallbackHandler$ChildEle ment.checkResource(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.checkResourc e(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(U nknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Un known Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unk nown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception: java.lang.SecurityException: trusted loader attempted to load sandboxed resource from file:/C:/CryptoApplet/Ramesh/right
    SampleApplet.Jar contains,

    SampleApplet.java
    import java.applet.Applet;
    import java.awt.Graphics;

    public class SampleApplet extends Applet
    {

    public SampleApplet()
    {
    }

    public void paint(Graphics g)
    {
    Sample sample = new Sample();
    String s = sample.test();
    g.drawString(s, 20, 30);
    }
    }
    Manifest.MF
    Manifest-Version: 1.0
    Class-Path: /C:/Sample.jar
    Created-By: 1.6.0_20 (Sun Microsystems Inc.)
    Sample.jar contains,

    Sample.Java
    public class Sample
    {

    public Sample()
    {
    }

    public String test()
    {
    return "Ramesh - C Drive";
    }
    }
    Please help me to solve it !


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,342
    My Mood
    Hungover
    Thanks
    143
    Thanked 625 Times in 536 Posts

    Default Re: Error while running Applet

    I have a stupid question- what happens when you get rid of the first '/' in your class path string?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,360
    Thanks
    49
    Thanked 2,207 Times in 2,180 Posts

    Default Re: Error while running Applet

    What is the Sample class trying to do?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Error while running Applet

    SecurityException equates to a non-signed applet trying to do something that is not allowed, or a signed applet trying to load an unsigned resource. Without knowing more information as to whether your applet is signed and/or what it is trying to do its hard to advice.

  5. #5
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Error while running Applet

    Quote Originally Posted by copeg View Post
    SecurityException equates to a non-signed applet trying to do something that is not allowed, or a signed applet trying to load an unsigned resource. Without knowing more information as to whether your applet is signed and/or what it is trying to do its hard to advice.
    This is my exact problem.I have tried the same with the sample code as Posted above.

    We are trying to access JNative.jar from our TestApplet.jar. We have downloaded JNative.jar form some site. Purpose of Jnative.jar is to access the dll. If I try from eclipse as a standalone code, it will call the dll and give me the response but when I am trying it from applet its not working.
    We have signed both the jars i.e. our Testapplet.jar and downloaded JNative.jar. Here our aim to access the dll which will create the pinblock and give it to me.

    TestApplet.java file code is as follows:
    import java.applet.Applet;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.net.InetAddress;
    import java.net.NetworkInterface;
    import java.util.Formatter;
    import org.xvolks.jnative.JNative;
    import org.xvolks.jnative.Type;
    import org.xvolks.jnative.exceptions.NativeException;

    public class TestApplet extends Applet {
    private static final int version = 11;

    private static Boolean synchro = new Boolean(true);

    private Exception lastException;

    private String passwordCipher;

    private int symCipherKeySize;

    private boolean debug;

    private boolean raiseExceptions;

    private String signature;

    private boolean persistPrivateKey;

    private boolean statePrepared;

    private String stMacAddress;

    private String stNewWorkKey;

    private String stCardDetails;

    @Override
    public void init() {
    System.out.println("initializing");
    statePrepared = false;
    }

    @Override
    public void start() {
    System.out.println("Start method()");
    try {
    System.out.println("Pin Block:"+callGenPinBlock("","6220180080000133217|49 01|6220180080000133217D49011018620000000|Dhivya C |10081567"));
    }catch(Exception e) {
    System.out.println("Exception in callGenPinBlock() :"+e);
    }
    }

    public boolean isPrepared() {
    System.out.println("isPrepared()");
    return statePrepared;
    }

    @Override
    public void stop() {
    System.out.println("stopping");
    }

    @Override
    public void destroy() {
    System.out.println("destroying");
    }

    public Exception getLastException() {
    return lastException;
    }

    public String getLastExceptionStackTrace() {
    if (lastException == null) {
    return null;
    } else {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, true);
    lastException.printStackTrace(pw);
    pw.close();
    return sw.toString();
    }
    }

    private void handleException(Exception e) throws Exception {
    lastException = e;
    if (raiseExceptions) {
    throw e;
    } else {
    e.printStackTrace();
    }
    }

    public int getVersion() {
    return version;
    }

    public String getJavaVersion() {
    return System.getProperty("java.version");
    }

    public String callGenPinBlock(String stBlank,String cardDetails) {
    String retValue = null;
    try
    {
    JNative BlockInput = new JNative("C:\\NEWDLL_TEST"+"\\kioskPinPad", "GenPinBlock");
    BlockInput.setRetVal(Type.STRING);
    BlockInput.setParameter(0,stBlank);
    BlockInput.setParameter(1,cardDetails);
    BlockInput.invoke();
    retValue = BlockInput.getRetVal();
    BlockInput.dispose();
    }
    catch(NativeException exp)
    {
    exp.printStackTrace();
    return "error in calling";
    }
    catch(IllegalAccessException exp)
    {
    exp.printStackTrace();
    return "error in calling";
    }
    catch(Exception exp)
    {
    exp.printStackTrace();
    return "error in calling";
    }
    return retValue;
    }
    }
    HTML page with Applet calling code
    <html>
    <head>
    <script type="text/javascript" charset="US-ASCII">
    function callApplet()
    {
    //alert("Pin Block:"+testApplet.callGenPinBlock("","62201800800 00133217|4901|6220180080000133217D4901101862000000 0|Dhivya C |10081567"));
    }
    </script>
    </head>
    <body onload="callApplet();">
    Applet Test
    </body>
    <applet name="testApplet" code="TestApplet" archive="TestApplet.jar" width="0" height="0" mayscript="true">
    <param name="debug" value="true" />
    <param name="raiseExceptions" value="false" />
    No Java support for APPLET!!
    </applet>
    </html>
    jar creation code

    keytool -genkey -keyalg RSA -alias jarsignks -keystore jarsignks.ks

    javac -classpath C:\NEWDLL_TEST\JNative.jar TestApplet.java

    jar cvfm Test.jar MANIFEST.txt TestApplet.class

    jarsigner -keystore jarsignks.ks -storepass santanu -keypass santanu TestApplet.jar jarsignks

    jarsigner -keystore jarsignks.ks -storepass santanu -keypass santanu JNative.jar jarsignks

    pause
    Manifest file
    As we will keep this jar at this place,

    Class-Path: /C:/NEWDLL_TEST/JNative.jar
    In java console exception is coming as:

    Java Plug-in 1.6.0_22
    Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\353323

    ----------------------------------------------------
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------

    initializing
    Start method()
    Entry san getMacAddress
    mac address from applet:6C:F0:49:28:52:66
    Exception in thread "thread applet-TestApplet-1" java.lang.ExceptionInInitializerError
    at TestApplet.callGenPinBlock(TestApplet.java:169)
    at TestApplet.start(TestApplet.java:65)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission shutdownHooks)
    at java.security.AccessControlContext.checkPermission (Unknown Source)
    at java.security.AccessController.checkPermission(Unk nown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.Runtime.addShutdownHook(Unknown Source)
    at org.xvolks.jnative.JNative.<clinit>(JNative.java:3 51)
    ... 4 more
    Last edited by rameshiit19; July 26th, 2011 at 05:41 AM.

  6. #6
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Error while running Applet

    Quote Originally Posted by KevinWorkman View Post
    I have a stupid question- what happens when you get rid of the first '/' in your class path string?
    / means that the dependant jar is in a different directory.I have read it in a forum and have implemented it here !

  7. #7
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Error while running Applet

    Quote Originally Posted by Norm View Post
    What is the Sample class trying to do?
    Sample class is simply a dependant class of SampleApplet class and returns some string from a function !

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Error while running Applet

    We are trying to access JNative.jar from our TestApplet.jar. We have downloaded JNative.jar form some site. Purpose of Jnative.jar is to access the dll. If I try from eclipse as a standalone code, it will call the dll and give me the response but when I am trying it from applet its not working.
    We have signed both the jars i.e. our Testapplet.jar and downloaded JNative.jar. Here our aim to access the dll which will create the pinblock and give it to me.
    2 suggestions. First, try removing any previous sign certificate of the JNative.jar, then resign with yours. Next, update to the latest version of the JRE. Reason why - while its hard to say this is your problem, there is a bug in earlier versions of java 6 having to do with multiple signatures in deployment jars (and the JRE only reading the first - which could lead to a clash).

  9. The Following User Says Thank You to copeg For This Useful Post:

    rameshiit19 (July 28th, 2011)

  10. #9
    Member
    Join Date
    Sep 2010
    Posts
    32
    My Mood
    Confused
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Cool Re: Error while running Applet

    Finally I have solved it ...

    I have added the following line in Java/jre6/lib/security/Java.policy , by specifying the folder where the JAR and DLL exists ...

    grant codeBase "file:/C:/PATH/*" {
    permission java.security.AllPermission;
    };


    Thanks to everyone for your valuable suggestions !

Similar Threads

  1. Running an Applet With JAR file
    By rameshiit19 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 20th, 2011, 07:10 AM
  2. Running out of ideas...
    By Cat in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 12th, 2011, 10:21 AM
  3. 'Run' isn't 'Running'
    By leonsas in forum AWT / Java Swing
    Replies: 5
    Last Post: December 27th, 2010, 12:37 PM
  4. Running a external exe in Mac OS
    By supertreta in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: November 15th, 2010, 12:32 PM
  5. Runtime Error running in UVA
    By mathfxr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 17th, 2010, 02:06 PM

Tags for this Thread