Webstart 应用程序日志记录权限被拒绝

发布于 2024-11-29 21:58:17 字数 1322 浏览 3 评论 0原文

是否可以使用 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)

is it possible to use java.util.Logging and log to a file in a java webstart application?
I have the following logging code:


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

and got the following exception:


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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

メ斷腸人バ 2024-12-06 21:58:18

访问控制异常说明如下:

“访问被拒绝(java.util.logging.LoggingPermission 控制)”

javadoc 对于权限类来说是这样的:

“目前只有一个名为 LoggingPermission 的权限。这是“控制”,它授予控制日志记录配置的能力,例如通过添加或删除处理程序、添加或删除过滤器或更改日志记录级别.

你正在做的事情显然属于“控制”权限。

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


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

这两个问题都可以通过签署申请来解决。然后您就会遇到用户必须接受/信任您的签名密钥的问题。但这很公平!据 Java 安全沙箱所知,您所做的事情可能会损坏用户的计算机。

The access control exception says this:

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

The javadoc for the permission class says this:

"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."

What you are doing clearly falls under the "control" permission.

You will need to sign your application if it is to create/add its own log handlers.


Incidentally, if you did manage to work around the LoggingPermission("control"), you would then run into another access issue in opening the log file.

Both problems are solved by signing the application. You've then got the problem that the user has to accept / trust your signing key. But that is fair enough! As far as the Java security sandbox can tell, what you are doing could potentially damage the user's machine.

浅浅 2024-12-06 21:58:18

您是否尝试过指定绝对路径?也许问题是您无权访问应用程序本身的当前工作目录。

Have you tried specifying an absolute path? Perhaps the issue is that you don't have access to the current working directory of the application itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文