Is it possible to access files beyond WEB-INF folder in dev mode of GAE (java.security.AccessControlException: access denied)?

人盡茶涼 提交于 2019-12-12 02:52:58

问题


Is it possible to access files beyond WEB-INF folder in Google App Engine's development server ? Maybe I can somehow force GAE dev server to do not block external connections/file access ?

I'm trying to create Java version of gae-sqlite. But I can't access external sql server (mysql or h2db) due to access denied exceptions.

Call stack:

Caused by: java.security.AccessControlException: access denied (java.io.FilePermission C:\work\test_projects\gae_test\out\artifacts\gae_test_war_exploded\database.lock.db write)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:252)
    at java.lang.SecurityManager.checkWrite(SecurityManager.java:962)
    at java.io.File.createNewFile(File.java:882)
    at org.h2.store.fs.FilePathDisk.createFile(FilePathDisk.java:121)
    at org.h2.store.fs.FileUtils.createFile(FileUtils.java:59)
    at org.h2.store.FileLock.lockFile(FileLock.java:327)
    at org.h2.store.FileLock.lock(FileLock.java:128)
    at org.h2.engine.Database.open(Database.java:542)
    at org.h2.engine.Database.openDatabase(Database.java:222)

回答1:


According to GAE for Java Questions:

Why can't I read from this file?

It is possible to read from a file which is uploaded as part of your application provided that it is in the following locations:

  • war/WEB-INF
  • in a location matching the <resource-files> pattern in appengine-web.xml (which by default includes everything)

If the file location is not the issue, the problem may be that the method you are using to read from the file is not whitelisted. Your application can use any IO classes that are useful for reading from the file system, such as File, FileInputStream, FileReader, or RandomAccessFile. For a full list of whitelisted classes, please see the JRE Class White List. If you need to get file access to your own resources (such as properties files), you could put these files inside of jars and use Class or ClassLoader to load them.

So to answer your question, the only available place besides the WEB-INF directory to read files from is whatever you specified in the <resource-files> entry in appengine-web.xml.

Now one thing I noticed is that you're trying to read a DB file which should be okay if you're only considering it read-only. You cannot write to any "local" files because (from the same link):

Why can't I write to this file?

Writing to local files is not supported in App Engine due to the distributed nature of your application. Instead, data which must be persisted should be stored in the distributed datastore. For more information see the documentation on the runtime sandbox.




回答2:


As of GAE SDK 1.6.1 it's not possible. If you guys later find the way to do it please let me know.



来源:https://stackoverflow.com/questions/8950163/is-it-possible-to-access-files-beyond-web-inf-folder-in-dev-mode-of-gae-java-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!