Results 1 to 5 of 5
  1. #1
    DylanDubya is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Please help, java.security.AccessControlException, TA doesn't know why

    When I run the two programs below, I run the Server as an application from the command prompt, then I run the Client as an applet. I always get this exception.

    java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:8000" "connect,resolve")
    at java.security.AccessControlContext.checkPermission (AccessControlContext.java:366)
    at java.security.AccessController.checkPermission(Acc essController.java:555)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:549)
    at java.lang.SecurityManager.checkConnect(SecurityMan ager.java:1051)
    at java.net.Socket.connect(Socket.java:574)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at AppletClient.init(AppletClient.java:25)
    at sun.applet.AppletPanel.run(AppletPanel.java:434)
    at java.lang.Thread.run(Thread.java:722)

    The programs are:
    Client:
    Java Code:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    
    public class AppletClient extends JApplet {
      // Label for displaying the visit count
      private JLabel jlblCount = new JLabel();
    
      // Indicate if it runs as application
      private boolean isStandAlone = false;
    
      // Host name or ip
      private String host = "localhost";
    
      /** Initialize the applet */
      public void init() {
        add(jlblCount);
    
        try {
          // Create a socket to connect to the server
          Socket socket;
          if (isStandAlone)
            socket = new Socket(host, 8000);
          else
            socket = new Socket(getCodeBase().getHost(), 8000);
    
          // Create an input stream to receive data from the server
          DataInputStream inputFromServer =
            new DataInputStream(socket.getInputStream());
    
          // Receive the count from the server and display it on label
          int count = inputFromServer.readInt();
          jlblCount.setText("You are visitor number " + count);
    
          // Close the stream
          inputFromServer.close();
        }
        catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    
      /** Run the applet as an application */
      public static void main(String[] args) {
        // Create a frame
        JFrame frame = new JFrame("Applet Client");
    
        // Create an instance of the applet
        AppletClient applet = new AppletClient();
        applet.isStandAlone = true;
    
        // Get host
        if (args.length == 1) applet.host = args[0];
    
        // Add the applet instance to the frame
        frame.add(applet, java.awt.BorderLayout.CENTER);
    
        // Invoke init() and start()
        applet.init();
        applet.start();
    
        // Display the frame
        frame.pack();
        frame.setVisible(true);
      }
    }
    Server:
    Java Code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    
    public class Server extends JFrame {
      // Text area for displaying contents
      private JTextArea jta = new JTextArea();
    
      public static void main(String[] args) {
        new Server();
      }
    
      public Server() {
        // Place text area on the frame
        setLayout(new BorderLayout());
        add(new JScrollPane(jta), BorderLayout.CENTER);
    
        setTitle("Server");
        setSize(500, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true); // It is necessary to show the frame here!
    
        try {
          // Create a server socket
          ServerSocket serverSocket = new ServerSocket(8000);
          jta.append("Server started at " + new Date() + '\n');
    
          // Listen for a connection request
          Socket socket = serverSocket.accept();
    
          // Create data input and output streams
          DataInputStream inputFromClient = new DataInputStream(
            socket.getInputStream());
          DataOutputStream outputToClient = new DataOutputStream(
            socket.getOutputStream());
    
          while (true) {
            // Receive radius from the client
            double radius = inputFromClient.readDouble();
    
            // Compute area
            double area = radius * radius * Math.PI;
    
            // Send area back to the client
            outputToClient.writeDouble(area);
    
            jta.append("Radius received from client: " + radius + '\n');
            jta.append("Area found: " + area + '\n');
          }
        }
        catch(IOException ex) {
          System.err.println(ex);
        }
      }
    }
    We are getting the same issue in a project, this is just a much simpler version of the code.
    Last edited by DylanDubya; 12-06-2012 at 01:44 AM.

  2. #2
    DylanDubya is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: Please help, java.security.AccessControlException, TA doesn't know why

    No one? Can someone at least try running it on their computer and see if they get the same error?

  3. #3
    DylanDubya is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default java.security.AccessControlException? Urgent!

    I'm posting this here since I had posted in applets and no one has responded for a week, and my project is due tomorrow.

    When I run the two programs below, I run the Server as an application from the command prompt, then I run the Client as an applet. I always get this exception.

    java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:8000" "connect,resolve")
    at java.security.AccessControlContext.checkPermission (AccessControlContext.java:366)
    at java.security.AccessController.checkPermission(Acc essController.java:555)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:549)
    at java.lang.SecurityManager.checkConnect(SecurityMan ager.java:1051)
    at java.net.Socket.connect(Socket.java:574)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at AppletClient.init(AppletClient.java:25)
    at sun.applet.AppletPanel.run(AppletPanel.java:434)
    at java.lang.Thread.run(Thread.java:722)

    The programs are:
    Client:
    Java Code:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
     
    public class AppletClient extends JApplet {
      // Label for displaying the visit count
      private JLabel jlblCount = new JLabel();
     
      // Indicate if it runs as application
      private boolean isStandAlone = false;
     
      // Host name or ip
      private String host = "localhost";
     
      /** Initialize the applet */
      public void init() {
        add(jlblCount);
     
        try {
          // Create a socket to connect to the server
          Socket socket;
          if (isStandAlone)
            socket = new Socket(host, 8000);
          else
            socket = new Socket(getCodeBase().getHost(), 8000);
     
          // Create an input stream to receive data from the server
          DataInputStream inputFromServer =
            new DataInputStream(socket.getInputStream());
     
          // Receive the count from the server and display it on label
          int count = inputFromServer.readInt();
          jlblCount.setText("You are visitor number " + count);
     
          // Close the stream
          inputFromServer.close();
        }
        catch (IOException ex) {
          ex.printStackTrace();
        }
      }
     
      /** Run the applet as an application */
      public static void main(String[] args) {
        // Create a frame
        JFrame frame = new JFrame("Applet Client");
     
        // Create an instance of the applet
        AppletClient applet = new AppletClient();
        applet.isStandAlone = true;
     
        // Get host
        if (args.length == 1) applet.host = args[0];
     
        // Add the applet instance to the frame
        frame.add(applet, java.awt.BorderLayout.CENTER);
     
        // Invoke init() and start()
        applet.init();
        applet.start();
     
        // Display the frame
        frame.pack();
        frame.setVisible(true);
      }
    }
    Server:
    Java Code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
     
    public class Server extends JFrame {
      // Text area for displaying contents
      private JTextArea jta = new JTextArea();
     
      public static void main(String[] args) {
        new Server();
      }
     
      public Server() {
        // Place text area on the frame
        setLayout(new BorderLayout());
        add(new JScrollPane(jta), BorderLayout.CENTER);
     
        setTitle("Server");
        setSize(500, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true); // It is necessary to show the frame here!
     
        try {
          // Create a server socket
          ServerSocket serverSocket = new ServerSocket(8000);
          jta.append("Server started at " + new Date() + '\n');
     
          // Listen for a connection request
          Socket socket = serverSocket.accept();
     
          // Create data input and output streams
          DataInputStream inputFromClient = new DataInputStream(
            socket.getInputStream());
          DataOutputStream outputToClient = new DataOutputStream(
            socket.getOutputStream());
     
          while (true) {
            // Receive radius from the client
            double radius = inputFromClient.readDouble();
     
            // Compute area
            double area = radius * radius * Math.PI;
     
            // Send area back to the client
            outputToClient.writeDouble(area);
     
            jta.append("Radius received from client: " + radius + '\n');
            jta.append("Area found: " + area + '\n');
          }
        }
        catch(IOException ex) {
          System.err.println(ex);
        }
      }
    }
    We are getting the same issue in a project, this is just a much simpler version of the code.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: java.security.AccessControlException? Urgent!

    Quote Originally Posted by DylanDubya View Post
    I'm posting this here since I had posted in applets and no one has responded for a week, and my project is due tomorrow.
    Please see the Forum Rules -- particularly the second paragraph.

    I've merged the new thread you started in New to Java. Please don't do this again.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: Please help, java.security.AccessControlException, TA doesn't know why

    Did you take a look at a google result?
    Applet funktioniert nicht im Browser !! AccessControlException ORACLE @ Swing, Java2D/3D, SWT, JFace - tutorials.de: Tutorial, Forum, Anleitung & Hilfe
    (Sorry for posting this external link :/ )
    Is that what your problem is?
    I like likes!

Similar Threads

  1. Replies: 0
    Last Post: 12-22-2011, 12:48 PM
  2. Java.security.AccessControlException
    By ramanareddy438 in forum Java Applets
    Replies: 4
    Last Post: 12-13-2011, 04:00 PM
  3. java.security.AccessControlException in Applet
    By gopimano in forum New To Java
    Replies: 0
    Last Post: 12-07-2010, 10:57 AM
  4. How to solve java.security.AccessControlException
    By chyrl in forum Advanced Java
    Replies: 0
    Last Post: 09-24-2010, 08:49 PM
  5. java.security.AccessControlException
    By cecily in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 02:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •