java.security.AccessControlException: access denied (java.net.SocketPermiss

I am trying to connect to a Ftp server through my applet.The applet is a Signed Applet.

But I am getting the above exception.

Please kindly help me.

RAKESH.

The Source Code is as follows

/*

* Created on Jun 17, 2005

* author Rakesh

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Style - Code Templates

*/

import java.io.*;

import java.io.IOException;

import com.enterprisedt.net.ftp.FTPClient;

import com.enterprisedt.net.ftp.FTPException;

import com.enterprisedt.net.ftp.FTPMessageCollector;

import com.enterprisedt.net.ftp.FTPTransferType;

import com.enterprisedt.net.ftp.FTPConnectMode;

import com.enterprisedt.util.debug.Level;

import com.enterprisedt.util.debug.Logger;

import java.awt.BorderLayout;

import java.awt.CardLayout;

import java.awt.Color;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import javax.swing.JPasswordField;

import javax.swing.ButtonGroup;

import javax.swing.JApplet;

import javax.swing.JButton;

import javax.swing.JFileChooser;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JProgressBar;

import javax.swing.JRadioButton;

import javax.swing.JTextField;

//import java.io.*;

//import com.enterprisedt.net.ftp.FTPClient;

//import com.enterprisedt.net.ftp.FTPConnectMode;

//import com.enterprisedt.net.ftp.FTPTransferType;

/**

* @author Rakesh

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Style - Code Templates

*/

public class Rakesh extends JApplet implements ActionListener,ItemListener{

/* The class variables used for FileChooser component*/

//jar cvf TestApplet.jar TestApplet.class

//orderId is the string from the applet

String orderId;

int returnVal;

JFileChooser jfc;

String file_dir_name;

String[] files = new String[5];

FTPMessageCollector listener;

String file1;

String file2;

String file3;

String file4;

String file5;

/* Class specific constants */

String host = "passtori.com" ;

String user = "satheesh";

String password;

String localFilePath ="c:/jnlp-1_5-mr-spec.pdf";

String localDir;

String remoteFileName = "jnlp-1_5-mr-spec.pdf";

String remoteDir;

FTPClient ftp;

/* The above are used to set the parameters for the userid, password, host, dirs, and filenames */

/* Buttons required for the upload wizard*/

JButton browseDir,browseFile2,browseFile3,browseFile4,browseFile5,

browseFile6,back1,back2,uploadMore,done1,done2,

ok,cancel;

JLabel l1,l2,l6,l7,l8,l9,l3,l4,l5,l10, uploaded;

JTextField t1,t2,t3,t4,t5,t6,t7,t8;

JPasswordField t9 ;

ButtonGroup cbg;

JRadioButton c1,c2;

BorderLayout bl;

Container cont;

CardLayout cl = new CardLayout();

JPanel p1,p2,p3,p4,p5,p7,p8,p9,p10,sucessPanel;

//Progress bar for uploading or downloading

JProgressBar progressBar;

/* public void init()

{

try { orderId = getParameter("orderid"); }

catch (Exception e) {}

if (orderId == null)

orderId = "<No order id specified>";

}*/

FileOutputStream f;

DataOutputStream dis;

public void init(){

}

public void start()

{

try{

f = new FileOutputStream("C:\\Eclipse\\workspace\\rakesh\\error.txt");

dis = new DataOutputStream(f);

}catch(Exception e){

System.out.println("Exception is"+ e);

}

listener = new FTPMessageCollector();

cont = getContentPane();

cont.setLayout(cl);

cont.setBackground(Color.LIGHT_GRAY);

/*JFileChooser related code */

jfc = new JFileChooser();

//Dir chooser button on click opens the file chooser

browseDir = new JButton("Browse");

browseFile2 = new JButton("Browse");

browseFile3 = new JButton("Browse");

browseFile4 = new JButton("Browse");

browseFile5 = new JButton("Browse");

browseFile6 = new JButton("Browse");

back1 = new JButton("BACK");

back2 = new JButton("BACK");

uploadMore = new JButton("UploadMORE");

done1 = new JButton("Done");

done2 = new JButton("Done");

ok = new JButton("OK");

cancel = new JButton("Cancel");

l1 = new JLabel("DownLoading in progress");

l2 = new JLabel("Download Successful");

l6 = new JLabel("("+orderId+")"+ "UPLOAD/DOWNLOAD INTERFACE");

l7 = new JLabel("Directory Upload");

l8 = new JLabel("File Upload");

l9 = new JLabel("Kaizen Informatics Pvt Ltd Copyright 2005");

l3 = new JLabel("Host");

l4 = new JLabel("Ex: ftp:passtori.com");

l5 = new JLabel("UserName");

l10 = new JLabel("Password");

uploaded = new JLabel("Uploaded successfully");

progressBar = new JProgressBar();

progressBar.setIndeterminate(true);

cbg = new ButtonGroup();

c1 = new JRadioButton("Directory Upload", false);

c2 = new JRadioButton("File Upload", false);

cbg.add(c1);

cbg.add(c2);

p1 = new JPanel();

p2 = new JPanel();

p3 = new JPanel();

p4 = new JPanel();

p5 = new JPanel();

p7 = new JPanel();

// p6 = new JPanel(new CardLayout());

p8 = new JPanel();

p9 = new JPanel();

p10 = new JPanel();

sucessPanel = new JPanel();

sucessPanel.add(uploaded);

//sucessPanel.add(progressBar);

cl = new CardLayout();

bl = new BorderLayout();

t1 = new JTextField(20);

t2 = new JTextField(20);

t3 = new JTextField(20);

t4 = new JTextField(20);

t5 = new JTextField(20);

t6 = new JTextField(20);

t7 = new JTextField(15);

t8 = new JTextField(10);

t9 = new JPasswordField(10);

p8.setLayout(new BorderLayout());

p8.add(back1,BorderLayout.EAST);

p8.add(done1,BorderLayout.CENTER);

p9.setLayout(new BorderLayout());

p9.add(back2,BorderLayout.EAST);

p9.add(done2,BorderLayout.CENTER);

p9.add(uploadMore,BorderLayout.WEST);

p10.setLayout(new FlowLayout());

p10.add(l3);

p10.add(t7);

p10.add(l4);

p10.add(l5);

p10.add(t8);

p10.add(l10);

t9.setEchoChar('*');

p10.add(t9);

p10.add(ok);

p10.add(cancel);

p1.add(l1);

p2.add(l2);

p3.setLayout(new FlowLayout());

p3.add(l7);

p3.add(t1);

p3.add(browseDir);

p3.add(p8);

p4.setLayout(new FlowLayout());

p4.add(l8);

p4.add(t2);

p4.add(browseFile2);

p4.add(t3);

p4.add(browseFile3);

p4.add(t4);

p4.add(browseFile4);

p4.add(t5);

p4.add(browseFile5);

p4.add(t6);

p4.add(browseFile6);

p4.add(p9);

// p4.add(progressBar);

p5.setLayout(new GridLayout(2,1));

p5.add(c1);

p5.add(c2);

cont.add("one",p1);

cont.add("two",p2);

cont.add("three",p3);

cont.add("four",p4);

cont.add("five",p5);

cont.add("six",p10);

cont.add("seven",sucessPanel);

p7.add(l6);

cl = (CardLayout)cont.getLayout();

cl.show(cont,"six");

//cont.setLayout(bl);

//cont.add(p7,BorderLayout.NORTH);

//cont.add(l9,BorderLayout.SOUTH);

// cont.add(p6,BorderLayout.CENTER);

c1.addItemListener(this);

c2.addItemListener(this);

done1.addActionListener(this);

done2.addActionListener(this);

back1.addActionListener(this);

back2.addActionListener(this);

browseFile2.addActionListener(this);

browseFile3.addActionListener(this);

browseFile4.addActionListener(this);

browseFile5.addActionListener(this);

browseFile6.addActionListener(this);

browseDir.addActionListener(this);

uploadMore.addActionListener(this);

ok.addActionListener(this);

}

public void actionPerformed(ActionEvent ae)

{

try{

Object eo = ae.getSource();

String s =ae.getActionCommand();

if(eo.equals(browseDir))

{

jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

returnVal = jfc.showOpenDialog(this);

if(returnVal == JFileChooser.APPROVE_OPTION) {

file_dir_name = jfc.getSelectedFile().getAbsolutePath();

System.out.println("You chose to open this file: " +

file_dir_name);

t1.setText(file_dir_name);

}

}

else

if( (eo.equals(browseFile2)) ||

(eo.equals(browseFile3)) || (eo.equals(browseFile4))

|| (eo.equals(browseFile5)) ||(eo.equals(browseFile6)) )

{

jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);

returnVal = jfc.showOpenDialog(this);

if(returnVal == JFileChooser.APPROVE_OPTION) {

file_dir_name = jfc.getSelectedFile().getAbsolutePath();

System.out.println("You chose to open this file: " + file_dir_name);

}

if(eo.equals(browseFile2)) {t2.setText(file_dir_name);}

else if(eo.equals(browseFile3)) {t3.setText(file_dir_name);}

else if(eo.equals(browseFile4)) {t4.setText(file_dir_name);}

else if(eo.equals(browseFile5)) {t5.setText(file_dir_name);}

else if(eo.equals(browseFile6)) {t6.setText(file_dir_name);}

}

else

if(eo.equals(done2))

{

try{

// we need to check the names of the dir names in case of the dir exists.

// we need to have a module while uploading to confirm the no.of images uploaded

//and to check whether the dir exists are not , possibly no chance of having that.

// but got to be very careful

//ftp.rmdir("amar");

ftp.mkdir("amar");

ftp.chdir("amar");

}

catch(Exception e){System.out.println(e.toString());}

files[0] = t2.getText();

files[1] = t3.getText();

files[2] = t4.getText();

files[3] = t5.getText();

files[4] = t6.getText();

for(int i = 0; i < files.length; i++)

{

if(files != null){

System.out.println(new File(files).getName()+ ".todo" );

try{

//ftp.connect();

sendData(files, (new File(files)).getName()+".todo");

}

catch(Exception e){

try{ dis.writeBytes("IN Done2"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

System.out.println(e.toString());}

} else{ continue;}

}

cl.show(cont,"seven");

}

//directory panel done button (on click)

else if(eo.equals(done1))

{

try{

ftp.mkdir("amar");

ftp.chdir("amar");

} catch(Exception e){

try{ dis.writeBytes("In Done1"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

System.out.println(e.toString());}

File dir_upload = new File(file_dir_name);

sendFileToUpload(dir_upload, ftp, listener);

System.out.println("we clicked done1");

cl.show(cont,"seven");

}

else

if(s.equals("OK"))

{

host = t7.getText();

user = t8.getText();

password = new String(t9.getPassword());

//System.out.println(password.toString());

if(ftpConnect(host, user, password)){ cl.show(cont,"five"); System.out.println("connection done");}

}

else

if(s.equals("BACK"))

{

p5.repaint();

cl.show(cont,"five");

}

else

{ p5.repaint();

cl.show(cont,"five");

}

}catch(Exception e)

{

try{ dis.writeBytes("In Action Performed End"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

}

}

public void itemStateChanged(ItemEvent ie){

try{

if(c1.isSelected())

{

cl.show(cont,"three");

}

else

cl.show(cont,"four");

}catch(Exception e)

{

try{ dis.writeBytes("In itemState Changed"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

}

}

public boolean ftpConnect(String host, String user, String password)

{

try {

// set up client

ftp = new FTPClient();

ftp.setRemoteHost(host);

ftp.connect();

ftp.login(user, password);

return true;

} catch (Exception e)

{

//System.out.println("adasdasdsa");

try{ dis.writeBytes("In ftp Connect"+e.toString()); ftp.quit(); }catch(Exception ei){ System.out.println("Exception"+ei);}

return false;

}

}

public boolean sendData(String localFile, String remoteFileName)

{

try

{

ftp.setConnectMode(FTPConnectMode.PASV);

ftp.setType(FTPTransferType.BINARY);

ftp.put(localFile, remoteFileName);

return true;

}

catch (Exception e)

{

//System.out.println("adasdasdsa");

try{ dis.writeBytes("In Send Data fun"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

return false;

}

}

public void destroy()

{

try{

System.out.println("Applet destroyed");

ftp.quit();

} catch(Exception e){

try{ dis.writeBytes("In destroy"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

System.out.println("In the applet in destroy method" + e.toString());}

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/*public String sendFile(File f)

{

FTPClient ftp = null;

// set up client

ftp = new FTPClient();

try

{

ftp.setRemoteHost(host);

// connect

//log.info("Connecting");

ftp.connect();

// login

//log.info("Logging in");

// ftp.login(user, password);

// set up passive ASCII transfers

//log.debug("Setting up passive, ASCII transfers");

ftp.setConnectMode(FTPConnectMode.PASV);

ftp.setType(FTPTransferType.BINARY);

}

catch (IOException e)

{

e.printStackTrace();

return ("Some Exception : " + e.getMessage());

}

catch (FTPException e)

{

e.printStackTrace();

}

FTPMessageCollector listener = new FTPMessageCollector();

ftp.setMessageListener(listener);

String s= sendFileToUpload(f,ftp,listener);

//Shut down client

//log.info("Quitting client");

/*try

{

ftp.quit();

}

catch (IOException e1)

{

e1.printStackTrace();

}

catch (FTPException e1)

{

e1.printStackTrace();

}

return s;

}

*/

/**

* Basic usage statement

*/

public String sendFileToUpload(File f, FTPClient ftp,FTPMessageCollector listener)

{

String ftpDir="";

Logger.setLevel(Level.ALL);

try {

if(f.isDirectory())

{

System.out.println("********************************** " + f.getName() +" is a Directory **********************************");

try

{

ftp.mkdir(f.getName());

}

catch (IOException e1)

{

e1.printStackTrace();

}

catch (Exception e)

{

try{ dis.writeBytes("In sendfile toUpload1"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

e.printStackTrace();

}

try

{

ftp.chdir(f.getName());

}

catch (IOException e2)

{

e2.printStackTrace();

}

catch (FTPException e)

{

try{ dis.writeBytes("In send fileto upload2"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

e.printStackTrace();

}

String [] fileList=f.list();

for(int i=0;i<fileList.length;i++)

{

File tempFile=new File(f.getAbsolutePath()+ File.separator+ fileList);

System.out.println(

" Processing Sub File \""+fileList

+"\" ");

System.out.println("Processing Result : "+

sendFileToUpload(tempFile, ftp, listener));

}

ftp.cdup();

}

else

{

// copy file to server

//log.info("Putting file");

//ftp.put(f.getAbsolutePath(), f.getName());

sendData(f.getAbsolutePath(), f.getName());

String messages = listener.getLog();

//log.debug("Listener log:");

//log.debug(messages);

//log.info("Test complete");

return "Upload Done";

}

return "Came Back";

}

catch (Exception e)

{

//log.error("Demo failed", e);

try{ dis.writeBytes("in sendfile to upload3"+e.toString());}catch(IOException ei){ System.out.println("Exception"+ei);}

return "Upload Failed. Please try again";

}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

}

}>

[17399 byte] By [rakeshsagara] at [2007-10-1 16:53:20]
# 1

your code wasn't posted within the code tags but my guess is that you either

signed it wrong, referenced the wrong jar in your html file or call the applet

method from untrusted code (javascript)

http://forum.java.sun.com/thread.jspa?forumID=63&threadID=524815

second and last post

harmmeijera at 2007-7-11 1:23:13 > top of Java-index,Security,Signed Applets...