简体   繁体   中英

Java applet: AccessControlException again

Yet again issue with privileges of signed applets.

I want my self-signed applet to delete a file from the local drive, but I get the exception:

java.security.AccessControlException: access denied
  (java.io.FilePermission /Users/me/tmp.txt delete)

Here I invoke the deletion:

    public void deleteFile( String path )
    {
        AccessController.doPrivileged( new Deleter( path ));
    }

and this class deletes the file:

class Deleter implements PrivilegedAction {
    public Deleter( String path ) {
        m_path = path;
    }

    public Object run()
    {
        File file = new File( m_path );
        file.delete();
        return null;
    }

    private String m_path;
};

HTML code is:

<APPLET CODE="HelloWorld.class" ARCHIVE="SignedHelloWorld.jar" WIDTH=600 HEIGHT=25>
<PARAM NAME="MAYSCRIPT" VALUE="true">
</APPLET>

SOLVED:

I needed to add the policy (under OS X):

cat >> ~/.java.policy

grant {
  permission java.io.FilePermission "<<ALL FILES>>", "delete";   
};

To grant permissions, applets need a policy file. This defines what they can do to the users system. You can find more information here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM