Console don't let my applet run because of a file - java

I am working in an applet. It works perfect with Eclipse but when I try to run from Console it gives me this stack trace:
C:\Course Technology\src>appletviewer TestJAlienHunt.html
Path for file entered D:\Course Technology\AssignmentFinal\scoreFile.txt java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\Course Technology\AssignmentFinal\scoreFile.txt" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
at java.security.AccessController.checkPermission(AccessController.java:555)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at sun.nio.fs.WindowsPath.checkRead(WindowsPath.java:792)
at sun.nio.fs.WindowsFileSystemProvider.checkAccess(WindowsFileSystemProvider.java:360)
at java.nio.file.Files.exists(Files.java:2311)
at ReadFile.fileExists(ReadFile.java:47)
at JAlienHunt.readScore(JAlienHunt.java:187)
at JAlienHunt.init(JAlienHunt.java:73)
at sun.applet.AppletPanel.run(AppletPanel.java:434)
at java.lang.Thread.run(Thread.java:722)
The file has permission to read and write, why I am getting this?

An applet needs to be digitally signed by you and trusted by the end user before it can access the local file system on the user's computer.
I highlight user's computer because that is where any File will equate to. There is no option for getting a File pointing to the server. If this is read only and the server hosts the resource, access it by URL.

Related

Access Denied when using openJDK

I get an error
IOException:access denied ("java.io.FilePermission"
"D:\certainfilelocation" "read")
When accessing a file while using OpenJDK10 instead of JRE.
I also added in the java.policy this line
jdk-10.0.2\conf\security
permission java.io.FilePermission "<< ALL FILES >>","read";
But I still get the same error.
Is there any way? Thanks

How to resolve java.io.FilePermission error?

I am developing a java game for my school project from a tutorial which uses eclipse as its IDE. I am supposed to make this game in Netbeans but the problem is that after porting it gives an error like this.
java.security.AccessControlException: access denied ("java.io.FilePermission" "E:\java game\TheBigGame\Unit 3 Day 7\build\data\character.png" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
at java.security.AccessController.checkPermission(AccessController.java:555)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at sun.awt.image.URLImageSource.<init>(URLImageSource.java:55)
at sun.applet.AppletImageRef.reconstitute(AppletImageRef.java:51)
at sun.misc.Ref.get(Ref.java:64)
at sun.applet.AppletViewer.getCachedImage(AppletViewer.java:395)
at sun.applet.AppletViewer.getImage(AppletViewer.java:390)
at java.applet.Applet.getImage(Applet.java:274)
at java.applet.Applet.getImage(Applet.java:296)
at kiloboltgame.StartingClass$1.run(StartingClass.java:66)
at java.security.AccessController.doPrivileged(Native Method)
at kiloboltgame.StartingClass.init(StartingClass.java:64)
at sun.applet.AppletPanel.run(AppletPanel.java:434)
at java.lang.Thread.run(Thread.java:722)
The game works well in Eclipse but is having troubles in Netbeans.
I saw a similar question and tried using policy tool, editing java.properties and java.policy in lib\security but still no progress. By the way I use Windows 8.1 (if that helps).
The game is made on an applet.
I think your file is open. When under Windows, if a file is being used, sometimes you cannot open it from somewhere else..
Or it could be that you really don't have permissions :) right click on the file and check permissions (need to have all of them, read, write)

Java applet: connect to "maps.googleapis.com" - access denied ("java.net.SocketPermission")

I'm running a java applet embedded into a Grails application on my local. The applet should connect to the Google Maps API, but it gives me access denied.
Exception in thread "AWT-EventQueue-11" java.security.AccessControlException: access denied ("java.net.SocketPermission" "maps.googleapis.com:80" "connect,resolve")
When running the .java file in the applet viewer, the connection is fine, however when the applet is running on the tomcat server, I get access denied.
I've tried every solution I could find - granting permissions, signing the .jar file, creating and crossdomain.xml file and so on. Nothing works.
I'm running java version "1.8.0_40" on ubuntu.
You have to put the your applet inside of a jar and sign it using jarsigner

Granting access to anything on a path in the Java policy file

I'm dealing with a badly-behaved library (JRuby) which tries to read the entire universe and then fails to deal with the SecurityException as well, thus fails to start up at all.
Caused by: org.jruby.exceptions.RaiseException: (LoadError) library `java' could not be loaded: java.security.AccessControlException: access denied ("java.io.FilePermission" "/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/ant-javafx.jar" "read")
I don't mind JRuby (or any other library, for that matter) reading the entire universe, though, so I am trying to figure out how to add this to the grants. This jar file turns out to be on the java.class.path, but I can't figure out the rule to grant the permission.
Taking examples from other policy files I have seen in the past, I have been trying things like this:
grant {
permission java.io.FilePermission "${{java.class.path}}", "read, execute";
permission java.io.FilePermission "${{java.class.path}}/-", "read, execute";
};
But it makes no difference whatsoever, so I suspect this ${{...}} syntax only works for the codeBase.
Is there a way to do it for file permissions as well?

How to solve java.security.AccessControlException?

I am trying to access client's temp directory through my applet on my web project.
When I run the applet by itself, it gets the tempdir with no problem.
When I try to get it on my project using javascript and calling the applet method, I am having accessControlException on my javascript console. Also I am getting the same exception when I try to read a file under the temp directory.
This is what I see exactly:
java.security.accesscontrolexception access denied (java.util.propertypermission java.io.tmpdir read)
java.security.accesscontrolexception access denied (java.io.filepermission read)
How to solve java.security.AccessControlException?
Simplest solution is just to sign the applet.

Categories