gpt4 book ai didi

java.security.AccessControlException : access denied (java. io.FilePermission

转载 作者:行者123 更新时间:2023-11-30 09:28:07 25 4
gpt4 key购买 nike

我正在 google app engine java 上创建一个应用程序,我必须在其中读取静态文件的内容。war 目录中有一个名为 myrsakey11.pk8 的文件。

我读取文件的代码段是

public static PrivateKey getPrivateKey(String privKeyFileName) throws IOException {
File privKeyFile = new File(privKeyFileName);
FileInputStream fis = new FileInputStream(privKeyFile);
DataInputStream dis = new DataInputStream(fis);

byte[] privKeyBytes = new byte[(int) privKeyFile.length()];
try {
dis.read(privKeyBytes);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dis.close();
fis.close();

String BEGIN = "-----BEGIN PRIVATE KEY-----";
String END = "-----END PRIVATE KEY-----";
String str = new String(privKeyBytes);

if (str.contains(BEGIN) && str.contains(END)) {
str = str.substring(BEGIN.length(), str.lastIndexOf(END));
}

KeyFactory fac;
try {
fac = KeyFactory.getInstance("RSA");

EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decode(str));
return fac.generatePrivate(privKeySpec);

} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Base64DecoderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidKeySpecException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

在这个函数中我传递字符串“/myrsakey11.pk8”

我得到的完整错误日志是

java.security.AccessControlException: access denied (java.io.FilePermission /myrsakey11.pk8 read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355)
at java.security.AccessController.checkPermission(AccessController.java:567)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:56)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.FileInputStream.<init>(FileInputStream.java:133)
at org.ritesh.HelloWorldServlet.getPrivateKey(HelloWorldServlet.java:129)
at org.ritesh.HelloWorldServlet.doGet(HelloWorldServlet.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:679)

谁能告诉我如何纠正这个错误?

最佳答案

这件事也发生在我身上,我花了一段时间才弄明白:

如果您声明了错误的文件路径,Google AE 不会抛出 FileNotFoundException,而是抛出“AccessControlException:访问被拒绝(读取)”。

确保您的路径有效!

关于java.security.AccessControlException : access denied (java. io.FilePermission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14209175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com