webstart 应用程序日志记录权限被拒绝 [英] webstart application logging permission denied

查看:45
本文介绍了webstart 应用程序日志记录权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

并得到以下异常:

<前>java.security.AccessControlException:访问被拒绝(java.util.logging.LoggingPermission 控制)在 java.security.AccessControlContext.checkPermission(Unknown Source)在 java.security.AccessController.checkPermission(Unknown Source)在 java.lang.SecurityManager.checkPermission(Unknown Source)在 java.util.logging.LogManager.checkAccess(来源不明)在 java.util.logging.Handler.checkAccess(来源不明)在 java.util.logging.FileHandler.(来源不明)在 whoisapiclient.WhoisAPIClientApp.main(WhoisAPIClientApp.java:80)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(来源不明)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(来源不明)在 java.lang.reflect.Method.invoke(Unknown Source)在 com.sun.javaws.Launcher.executeApplication(来源不明)在 com.sun.javaws.Launcher.executeMainClass(来源不明)在 com.sun.javaws.Launcher.doLaunchApp(来源不明)在 com.sun.javaws.Launcher.run(来源不明)在 java.lang.Thread.run(未知来源)

解决方案

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

<块引用>

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

权限类的 javadoc 是这样说的:

<块引用>

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

您正在做的事情显然属于控制"权限.

如果要创建/添加自己的日志处理程序,您需要对应用程序进行签名.

<小时>

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

通过签署应用程序解决了这两个问题.然后,您遇到了用户必须接受/信任您的签名密钥的问题.但这已经足够公平了!就 Java 安全沙箱而言,您的行为可能会损坏用户的机器.

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)

解决方案

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.

这篇关于webstart 应用程序日志记录权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆