How to resolve java.io.FilePermission error? - java

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)

Related

Eclipse 2022-06 java.security.AccessControlException state.dat/.markers write

I have a weird problem after updateing to Eclipse 2022-06. I'm running it on Windows 10 under java.version=17.0.3 java.vendor=Azul Systems, Inc.
When I exit my (newly created) workspace after changing some system properties or project content, I get an error message:
Problems occurred while trying to save the state of the workbench.
java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\xxxxxx.metadata.plugins\org.eclipse.core.resources.projects\MyProject\org.eclipse.jdt.core\state.dat" "write")
or
java.security.AccessControlException: access denied ("java.io.FilePermission" ""D:\xxxxxx.metadata.plugins\org.eclipse.core.resources.projects\MyProject.markers" "write")
at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:485)
at java.base/java.security.AccessController.checkPermission(AccessController.java:1068)
at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:416)
at java.base/java.lang.SecurityManager.checkWrite(SecurityManager.java:847)
at ro.sync.security.manager.SandboxSecurityManager.checkWrite(SandboxSecurityManager.java:188)
at java.base/java.io.FileOutputStream.(FileOutputStream.java:223)
at java.base/java.io.FileOutputStream.(FileOutputStream.java:184)
at org.eclipse.jdt.internal.core.JavaModelManager.createOutputStream(JavaModelManager.java:4387)
at org.eclipse.jdt.internal.core.JavaModelManager.saveBuiltState(JavaModelManager.java:4341)
at org.eclipse.jdt.internal.core.JavaModelManager.saveState(JavaModelManager.java:4323)
at org.eclipse.jdt.internal.core.JavaModelManager.lambda$1(JavaModelManager.java:4699)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.Nodes$CollectorTask.doLeaf(Nodes.java:2183)
at java.base/java.util.stream.Nodes$CollectorTask$OfRef.doLeaf(Nodes.java:2193)
at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:686)
at java.base/java.util.stream.Nodes.collect(Nodes.java:328)
at java.base/java.util.stream.ReferencePipeline.evaluateToNode(ReferencePipeline.java:111)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
at org.eclipse.jdt.internal.core.JavaModelManager.lambda$0(JavaModelManager.java:4704)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1428)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
I even tried to add my project path to the java.policy file ->
permission java.io.FilePermission "D:\xxxxxx-", "write"
but that didn't help.
Is this a known issue? Any suggestions how I can resolve the problem?
Thanx
Thomas
I found the solution. I had oXygen 23.1 (to be clear - it's an older version not recomended for eclipse 2022-06) installed that seems to cause the problem. After uninstalling this version everything works fine.

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

Modify SecurityManager

Hey stackoverflow community!
I'm writing a small program. In this program code, written in a Web-Interface, is compiled and run.
Now I want the written code from the web-interface to have just a few permissions, like reading a file in a specific directory, while my own code has all permissions.
I just looked up the SecurityManager and found a way to carry this out by using the codeBase attribute of the Policy-File. My idea was to give my code all permissions so the written code has no permissions.
grant codeBase "file:/PATH/-" {
permission java.security.AllPermission;
};
grant {
};
PATH points to the root directory of my program (with bin/src as subfolder).
It works until i'm invoking javax.tools.JavaCompiler.CompilationTask.call() to compile the given code, although the file has the required permissions:
An exception has occurred in the compiler (1.8.0_05). Please file a bug at the Java Developer Connection (Report a Bug or Request a Feature) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "nonBatchMode" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
at java.lang.System.getProperty(System.java:714)
at com.sun.tools.javac.main.Main.compile(Main.java:445)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
.
.
.
I don't want to create a .java- and a .class-file for every typed code. For this reasen I used a ClassLoader with the following URI:
URI.create( "string:///" + className + Kind.CLASS.extension )
Trying to avoid the use of the "signedBy"-attriutes is important because it's difficult to sign .jar-files in Eclipse.
These are my questions:
1) Does anyone have an idea why the compiler throws an AccessControlException, although all needed rights are allowed?
2) Does anyone have an idea how to modify the SecurityManager this way?
3) Is it possible to seperate the included code from my own code at all?
4) Is the SecurityManager the right solution to my problem at all?
Thanks for reading and answering!

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

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.

access denied even though I specified policy.url in java.security

I am reading the tutorial on java security by oracle.
(http://download.oracle.com/javase/tutorial/security/toolsign/rstep4.html)
I duplicate all the files and everything from the tutorial basically.
I am able to run the file with security manager using the following approach in unix:
java -Djava.security.manager -Djava.security.policy=recvPolicy -cp sCount.jar Count ../../test
But when I try to specify a new policy.url in the java.security file like this:
policy.url.1=file:${java.home}/lib/security/java.policy
policy.url.2=file:${user.home}/.java.policy
policy.url.3=file:/home/myhome/SigningTest/recvPolicy
it gives me an exception when I run:
java -Djava.security.manager -cp sCount.jar Count ../../test
The exception is this:
Exception in thread "main" java.security.AccessControlException: access denied (java.io.FilePermission ../../test read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.FileInputStream.<init>(FileInputStream.java:100)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at Count.main(Count.java:17)
thanks for feedback
Okay, I did a quick test of this and it works for me. So the only thing that could be causing this problem (my guess) is that you have two jdks installed on your unix box. So make sure that the "java" that you are using for the command line execution is the same version whose java.security you have modified.
The default sun java 6 security file (if you are using ubuntu) is located at:
/etc/java-6-sun/security/java.security
So make sure you are editing the correct version of java.security

Categories