Search code examples
javahtmlappletsecurityexception

Getting a SecurityException: Permission denied in java


I am getting the java.lang.SecurityException: Permission denied: file:////Videos/public/scripts/screenshot.jar when I try to use an applet.

Here is the applet code:

<applet code="Screenshot" archive="file:////Videos/public/scripts/screenshot.jar" width="100px" height="100px">
</applet>

How do I fix it and what the problem even means?

EDIT:

From what I see I need to sign the applet. Could some one explain how and why this is done? The site provided does a bad job explaining it because it doesn't even address the fact that I am embedding this into my site and want every client to use it and not have to sign anything. Just click run.

EDIT2:

The code of the app itself:

/*
By Bavo Bruylandt (Http://www.realapplets.com")

*/

// and now The inevidable "Hello World" example :)

// tell the compiler where to find the methods you will use.
// required when you create an applet
import java.applet.*;
// required to paint on screen
import java.awt.*;


// the start of an applet - HelloWorld will be the executable class
// Extends applet means that you will build the code on the standard Applet class
public class Screenshot extends Applet
{

// The method that will be automatically called  when the applet is started
     public void init()
     {
 // It is required but does not need anything.
     }


// This method gets called when the applet is terminated
// That's when the user goes to another page or exits the browser.
     public void stop()
     {
     // no actions needed here now.
     }


// The standard method that you have to use to paint things on screen
// This overrides the empty Applet method, you can't called it "display" for example.

     public void paint(Graphics g)
     {
 //method to draw text on screen
 // String first, then x and y coordinate.
      g.drawString("Hey hey hey",20,20);
      g.drawString("Hellooow World",20,40);

     }

} 

Solution

  • It all depends on what is your applet trying to do, is it accessing the filesystem for example. Is it a signed applet or not? Applets run in a special sandbox by default with limited permissions. You would have to check out more info on Applet security, for starters have a look into Informit article here: http://www.informit.com/articles/article.aspx?p=433382&seqNum=2

    EDIT:

    Try to add a policy file eg.

    /* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
      /* DO NOT EDIT */
    
       grant {
         permission java.security.AllPermission;
       };
    

    named eg. java.policy.applet and place it on your classpath. Have a look at this question here about the policy files: Where to place java applet policy file?