AccessControlException setting up logging in an applet

Q

Qu0ll

I am trying to configure the built-in Java logging within an applet using
6u11 but I encounter the following:

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.LogManager.readConfiguration(Unknown Source)
at com.test.MyApplet.init(MyApplet.java:50)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown
Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied
(java.util.logging.LoggingPermission control)

The relevant lines in MyApplet are:

final LogManager lm = LogManager.getLogManager();
final String s = "handlers=java.util.logging.ConsoleHandler";
final InputStream is = new java.io.ByteArrayInputStream(s.getBytes());
try {
lm.readConfiguration(is);
} catch (final IOException ioe) {
System.err.println(ioe);
}

The exception is generated when the readConfiguration() is called. This
same code works fine in an application.

Does Java logging work within applets? How do I get around this exception?

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
D

Dave Miller

Qu0ll said:
I am trying to configure the built-in Java logging within an applet
using 6u11 but I encounter the following:

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.LogManager.readConfiguration(Unknown Source)
at com.test.MyApplet.init(MyApplet.java:50)
at
sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown
Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied
(java.util.logging.LoggingPermission control)

The relevant lines in MyApplet are:

final LogManager lm = LogManager.getLogManager();
final String s = "handlers=java.util.logging.ConsoleHandler";
final InputStream is = new
java.io.ByteArrayInputStream(s.getBytes());
try {
lm.readConfiguration(is);
} catch (final IOException ioe) {
System.err.println(ioe);
}

The exception is generated when the readConfiguration() is called. This
same code works fine in an application.

Does Java logging work within applets? How do I get around this exception?

The applet is running within the JRE on the client computer. In the
unlikely event that you want to print to a log file on the client you
would need to sign your applet to give it file access permissions.
(java.security.AccessControlException: access denied )

If you want your applet to log to the server, you would need to "phone
home" and capture the output there.
 
Q

Qu0ll

Dave Miller said:
The applet is running within the JRE on the client computer. In the
unlikely event that you want to print to a log file on the client you
would need to sign your applet to give it file access permissions.
(java.security.AccessControlException: access denied )

If you want your applet to log to the server, you would need to "phone
home" and capture the output there.

All I want is to be able to log to the Java console and I thought
ConsoleHandler would do just that. Are you saying that Java logging can't
even do that within an applet?

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
D

Daniel Pitts

Qu0ll said:
All I want is to be able to log to the Java console and I thought
ConsoleHandler would do just that. Are you saying that Java logging
can't even do that within an applet?
It can if you sign your applet. It's not actually that hard of a
process to do. I used to be afraid of it, but I found many helpful pages
by using Google.
 
A

Andrew Thompson

All I want is to be able to log to the Java console and I thought
ConsoleHandler would do just that.  Are you saying that Java logging can't
even do that within an applet?

Try an anonymous logger. They should work in
sandboxed applets.
 
D

Dave Miller

Qu0ll said:
All I want is to be able to log to the Java console and I thought
ConsoleHandler would do just that. Are you saying that Java logging
can't even do that within an applet?
I misunderstood "logging" to mean that you wanted to write information
to a log (file). Unsigned applets can't access client system resources
outside of the sandbox (obviously including the file system) ergo my
last post.

The JRE console is the System.out of the applet. You can print to that
with an unsigned applet via System.out.print .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top