security - java.io.FilePermission read access denied when launching applet with java 8 -


i have applet class that's trying read file in client's system. when accessing file, java.io.fileprmission error

java.security.accesscontrolexception: access denied ("java.io.filepermission" "c:\my_download\mytext_11may" "read")

i able access file jre 1.6. when applet uses jre1.8 above exception thrown.

my policy file in user home location:

grant codebase "file:${java.home}/lib/ext/*" {   permission java.security.allpermission; };  grant {   permission java.security.allpermission; };  grant codebase "https://*.mydomain.net-" {   permission java.security.allpermission; }; 

in 1.6, works if allpermission given in default grant block.

below code using access file:

file sourcedir = null; try {     sourcedir = (file) accesscontroller         .doprivileged(new privilegedexceptionaction<file>() {             public file run() {                     return new file(filepath);                 }             }); } catch (privilegedactionexception e) {     system.out.println(e.getmessage()+"-----");     e.printstacktrace(); } catch(exception e) {     system.out.println("eeeexception: " + e.getmessage());     e.printstacktrace(); } 

the strange part catch block not executed. executes catch block of caller method.

the jar signed necessary domains , permissions mentioned below.

permissions: all-permissions 

in same jar when try write operation works fine without policy file using versions 1.6 , 1.8. exception when try read it. in 1.6 overcome using java policy not helping in version 1.8.

thanks in advance help!

after lot of research, found solution.

the method being invoked applet had surrounded in accesscontroller.doprivileged block.

ex:

public void methforapplet(){    accesscontroller         .doprivileged(new privilegedexceptionaction<object>() {             public object run() {                     actualmethtobeexecuted();                     return null;                            }     }); } 

this worked in java 1.8 , 1.6 without policy file.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -