gpt4 book ai didi

java - webstart 应用程序日志记录权限被拒绝

转载 作者:搜寻专家 更新时间:2023-11-01 02:15:37 26 4
gpt4 key购买 nike

是否可以使用 java.util.Logging 并将日志记录到 java webstart 应用程序中的文件中?我有以下日志记录代码:

 Handler fh = new FileHandler("myapp.log"); Logger.getLogger(MyApp.class.getName()).addHandler(fh);

并得到以下异常:

java.security.AccessControlException: access denied (java.util.logging.LoggingPermission control)    at java.security.AccessControlContext.checkPermission(Unknown Source)    at java.security.AccessController.checkPermission(Unknown Source)    at java.lang.SecurityManager.checkPermission(Unknown Source)    at java.util.logging.LogManager.checkAccess(Unknown Source)    at java.util.logging.Handler.checkAccess(Unknown Source)    at java.util.logging.FileHandler.(Unknown Source)    at whoisapiclient.WhoisAPIClientApp.main(WhoisAPIClientApp.java:80)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at com.sun.javaws.Launcher.executeApplication(Unknown Source)    at com.sun.javaws.Launcher.executeMainClass(Unknown Source)    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)    at com.sun.javaws.Launcher.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)

最佳答案

访问控制异常是这样说的:

"access denied (java.util.logging.LoggingPermission control)"

javadoc权限类是这样说的:

"Currently there is only one named LoggingPermission. This is "control" and it grants the ability to control the logging configuration, for example by adding or removing Handlers, by adding or removing Filters, or by changing logging levels."

您所做的显然属于“控制”权限。

如果要创建/添加自己的日志处理程序,您将需要签署您的应用程序。


顺便说一句,如果您确实设法解决了 LoggingPermission("control"),您将在打开日志文件时遇到另一个访问问题。

这两个问题都通过签署应用程序来解决。然后,您遇到了用户必须接受/信任您的签名 key 的问题。但这很公平!就 Java 安全沙箱而言,您正在做的事情可能会损坏用户的机器。

关于java - webstart 应用程序日志记录权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7047324/

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