/    Sign up×
Community /Pin to ProfileBookmark

Applet error – Access Control Exception: access denied

I’ve put together an applet that is supposed to display a user’s file system via a JTree. Unfortunately, I’ve been getting an access control exception error. Does anyone know how to overcome the following error?

[QUOTE]

Java Plug-in 1.6.0_11
Using JRE version 1.6.0_11 Java HotSpot(TM) Client VM

java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertiesAccess(Unknown Source)
at java.lang.System.getProperties(Unknown Source)
at TreeApplet.<init>(TreeApplet.java:17)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.security.AccessControlException: access denied (java.util.PropertyPermission *
read,write)

[/QUOTE]

Here is my code:

[CODE]import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.JTree.*;
import java.util.*;

/*
<applet code=”TreeApplet.class” width=300 height=100>
</applet>
*/

public class TreeApplet extends Applet {
// Create default tree
Properties systemProperties = new Properties(System.getProperties());
JTree systemTree = new JTree(systemProperties);
JScrollPane scrollPane = new JScrollPane(systemTree);
JPanel panel = new JPanel(new FlowLayout());

public void init(){
systemTree.setRootVisible(true);
panel.add(scrollPane);
setLayout(new FlowLayout());
add(panel);
setVisible(true);
}

public void start(){

showStatus(“Java Tree”);
}

}
[/CODE]

to post a comment
Java

2 Comments(s)

Copy linkTweet thisAlerts:
@chazzyFeb 18.2009 — you're getting caught up because of this comment in System.getProperties():


First, if there is a security manager, its checkPropertiesAccess method is called with no arguments. This may result in a security exception.
[/quote]


Unfortunately, I don't think you're going to be able to get around this. I can't think of a way to ignore security in an applet.
Copy linkTweet thisAlerts:
@Dan0authorFeb 18.2009 — You're right, the system.getProperties() code should be:

[CODE]Properties systemProperties = System.getProperties();[/CODE]

As for the security problem, I figured out that it was caused by a lapsed certificate - once I signed the applet again, it worked fine.
×

Success!

Help @Dan0 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...