Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

help!!! java.security.access controlException

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am creating an applet using swing.I am working on linux.
In the code below , when I click on JComboBox CB1 and consequently call the dut.show() method I get the following exception
"java.security.AccessControlException access denied (java.io.FilePermission /home/ganesh/test/j2sdk_nb/bin read)
at java.security.AccessController.checkPermission(AccessControlContext java :line number)
and so on ....................."
I checked the directory for permissions and found them to be ok.
Please suggest a solution to overcome this issue.
regards,
ganesh.
public class HelloWorld2 extends JApplet implements ActionListener {

JFrame a = new JFrame("Deembed");
String data[] = { "trans" , "ind" , "kap" , "line" , "none"};

FileDialog open_file = new FileDialog(a, "-open" , FileDialog.LOAD);
FileDialog thr = new FileDialog(a, "-short - thru" , FileDialog.LOAD);
FileDialog dut = new FileDialog(a, "DUT" , FileDialog.LOAD);
JComboBox CB2 = new JComboBox();
public void init()
{
JComboBox CB1 = new JComboBox(data);

CB1.addActionListener(this);
CB2.addActionListener(this);

this.getContentPane().add(CB1);
this.getContentPane().add(CB2);
this.getContentPane().setLayout(new FlowLayout());
}
public void actionPerformed(ActionEvent e) {

JComboBox cb = (JComboBox)e.getSource();
// String data1 = (String)cb.getSource();
System.out.println(cb.getSelectedItem());
//process : Add data to CB2
if(cb.getSelectedItem() == "ind" ) {
CB2.removeAllItems();
CB2.addItem("-ind");
CB2.addItem("none");

dut.show();
}
else if (cb.getSelectedItem() == "kap"){
CB2.removeAllItems();
CB2.addItem("-kap");
CB2.addItem("none");

dut.show();
}
else if ( cb.getSelectedItem() == "trans"){
CB2.removeAllItems();
CB2.addItem("-e");
CB2.addItem("-c");
CB2.addItem("-ipol");
CB2.addItem("-l");
CB2.addItem("none");

dut.show();
}
else if ( cb.getSelectedItem() == "line"){
CB2.removeAllItems();
CB2.addItem("-line");
CB2.addItem("none");

dut.show();
}


}
}
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applets are not allowed to access the local filesystem of the client PC without the proper permissions, (usually this means you need to sign your jar file).
I am moving this to the Applets forum since you are't having a problem with the SWING GUI portion of the code.
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Gregg said, Applets run in the "sandbox" with very limited access to system resources. The fact that the file permissions are set correctly doesn't do anything for you. The easiset way to handle this is to add a permission to the plugin policy file, java.policy, which is located in the lib/security subdirectory of the plugin's main directory. If your applet's codebase is http://www.mysite.com then you would add an entry like:

That will allow unfettered access to all system resources, which may not be what you want. You can limit it to specific permissions by using different permission types for example:

That would grant read permission to just the file "/home/ganesh/test/j2sdk_nb/bin.
 
ganeshjk krishnamurthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Morris:
As Gregg said, Applets run in the "sandbox" with very limited access to system resources. The fact that the file permissions are set correctly doesn't do anything for you. The easiset way to handle this is to add a permission to the plugin policy file, java.policy, which is located in the lib/security subdirectory of the plugin's main directory. If your applet's codebase is http://www.mysite.com then you would add an entry like:

That will allow unfettered access to all system resources, which may not be what you want. You can limit it to specific permissions by using different permission types for example:

That would grant read permission to just the file "/home/ganesh/test/j2sdk_nb/bin.

 
ganeshjk krishnamurthy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Sorry for the previous message posted( was a bit careless).
Thanks a lot for guiding me.But as I am quite new to java please tell me what is this plugin you are talking about ? Also I found a java.policy file in the following path C:\Program Files\j2sdk_nb\j2sdk1.4.2\jre\lib\security.
Is it this java.policy file which I have to edit with the code you gave me ? Can I set the read permission for the whole directory ?
thanks in advance
ganesh.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic