Reading files from app engine project running in eclipse - java

I am trying to read a file stored in my computer from the app engine project which I am debugging in eclipse. But I am getting security exception with the following error:
java.security.AccessControlException: access denied ("java.io.FilePermission" ""D:\PROJECTS\LocBiz-AppEngine\war\Key\locbiz_key.json"" "read")
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
How do I read the file?

Put the files you want to read on the classpath and use the class loader to read them in
Foo.class.getResource("myfile");
A Java App Engine application's access to the classes in the Java standard library is limited to the whitelisted classes.

Related

Netbeans 7.3.1 Cannot establish a connection to jdbc:derby

Recently I'm working on this little project with Java EE and I need to use derby database , but every time I go to service->Database and try to connect to my jdbc:derby I get this error :
Unable to connect. Cannot establish a connection to jdbc:derby://localhost:1527//sample using org.apache.derby.jdbc.ClientDriver (java.netConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.).
and this exception :
Wed Oct 29 15:05:26 EET 2014 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
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.checkListen(SecurityManager.java:1131)
at java.net.ServerSocket.bind(ServerSocket.java:374)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231)
at org.apache.derby.impl.drda.NetworkServerControlImpl.createServerSocket(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.access$000(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl$1.run(Unknown Source)
at java.security.AccessControWed Oct 29 15:05:26 EET 2014 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
at java.security.AccessContrller.doPrivileged(Native Method)
at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.executeWork(Unknown Source)
at org.apache.derby.drda.NetworkServerControl.maiolContext.checkPermission(AccessControlContext.java:457)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkListen(SecurityManager.java:1131)
at java.net.ServerSocket.bind(ServerSocket.java:374)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231)
at org.apache.derby.impl.drda.NetworkServerControlImpl.createServerSocket(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.access$000(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.executeWork(Unknown Source)
at org.apache.derby.drda.NetworkServerControl.main(Unknown Source)
n(Unknown Source)
Any ideas how to fix it?
Did you already try the hint from here http://wiki.netbeans.org/JavaDB_grant_permissions
JDK 7u51 comes with some security improvements which are causing problems with starting Java DB on this Java version.
When you try to start DB from NetBeans you will probably get the Exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
The same exception you will get while starting using script /db/bin/startNetworkServer
Because there is no suitable way to fix it on the NetBeans side and this should be fixed on the side of the Java DB.
There are several ways how to deal with this problem. I will mention only the easiest way. You have to start DB manually from command line.
Start Java DB with -noSecurityManager argument.
<JDK 7u51 location>/db/bin/startNetworkServer -noSecurityManager
you need to add start page in project property.
Open Project property. Then choose tab run. Then add your project start page to relative URL text box. Mine is "/index.jsp".
Sorry if i have some mistake in english grammar.

Applet and jackson external jars: Can not access public class

i have an applet, in eclipse everything works right, but, when i export the jar, and embed to my website(which i have to embed every jackson jar too), im getting this error:
com.fasterxml.jackson.databind.JsonMappingException: Can not access public ticket.Ticket() (from class ticket.Ticket; failed to set access: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks")
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:272)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:247)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:146)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:322)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:2990)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2884)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
at ticket.Main.init(Main.java:56)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Can not access public ticket.Ticket() (from class ticket.Ticket; failed to set access: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks")
at com.fasterxml.jackson.databind.util.ClassUtil.checkAndFixAccess(ClassUtil.java:510)
at com.fasterxml.jackson.databind.deser.impl.CreatorCollector._fixAccess(CreatorCollector.java:203)
at com.fasterxml.jackson.databind.deser.impl.CreatorCollector.setDefaultConstructor(CreatorCollector.java:106)
at com.fasterxml.jackson.databind.deser.impl.CreatorCollector.setDefaultCreator(CreatorCollector.java:123)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._addDeserializerConstructors(BasicDeserializerFactory.java:369)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:315)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:259)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:263)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:401)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:354)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:267)
... 10 more
What can i do in this case?
An applet that attempts reflection would need to be digitally signed by the developer, and trusted by the user when prompted.
In addition to signing, you should be able to avoid this problem by disabling MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, (see javadoc). This prevents specific call that is failing for you; for non-applet use case this is important for access and performance reasons; but it requires that security manager allows it.

Java - How to get permission in Java Web Start

Hi managed to create the jar and .jnlp files for my Java application but running into trouble when it runs. Launches okay with Java Web Start but I think I need to do something
extra as normally when I run it it doesn't ask for permission to access the HD for file I/O.
Would appreciate some help and advise to know what to do to get the permission rights i.e. what do I have to do is it something I have to do to all my classes not sure. The error
message I get in Java Web Start is as below.
Exception in thread "AWT-EventQueue-0" java.security.AccessControlException:
access denied (java.io.FilePermission StockDatabase;Stocks.dat read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.exists(Unknown Source)
at StockCodeDatabase.<init>(OptraderSA.java:782)
at OptraderSA.actionPerformed(OptraderSA.java:136)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unkno
You need to sign your JNLP file and configure the <security> element, as discussed here.
Add the following to your JNLP:
<security>
<all-permissions/>
</security>
This will pop a dialogue asking the user the give the necessary permission to your app.
If you want access to the file system you need to change your JNLP file to include:
<security><all-permissions/></security>
This requires you to also sign your jar files.
Another option is to package the file inside the jar as a resource and you don't have to do all that.

java.security.AccessControlException: access denied when running applet on browser

I am getting the following error when trying to run an applet in a browser. The applet in question contains file access code in it:
java.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.RGENGINEJAVA)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.getenv(Unknown Source)
at com.socp.components.SOCPMapViewer.bootstrapArcobjectsJar(SOCPMapViewer.java:668)
at com.socp.components.SOCPMapViewer.init(SOCPMapViewer.java:130)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.RGSENGINEJAVA)
The applet works fine when invoked from the Elipse IDE but when I use an HTML file to run it in a browser it gives the above shown error. Please help me to resolve this issue. Tell me how I can grant the following permission file in the HTML context:
grant {
permission java.security.AllPermission;
};
Check: http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html

A quick way to solve java.security.AccessControlException

I have an applet which have to read a file from server. But I receive the following exception
java.security.AccessControlException: access denied (java.io.FilePermission \kb1.xml read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at java.io.File.isDirectory(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
...
I tried to put a java.policy.applet file with permission granted for reading but it doesn't work.
I need a quick way to solve this problem. I have to specify that for making this applet I used java 6.
You said you want to read a file on the server, but the exception is caused by trying to read a file on the client (the machine that is running the applet).
You cannot read files from the server directly. You need to access them via HTTP or put them into the applet's jar file and load it from there.

Categories