Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How can I grant a permission from a Java Applet

Posted on 2003-03-24
3
Medium Priority
?
1,477 Views
Last Modified: 2008-01-09
I am building a project consisting in two applets
1- a TCP/IP server
2- a TCP/IP client

I want the applet 1 to listen on a port on TCP/IP, and the applet 2 to connect to the applet 1.
The project works when the two applets are run on local machine, or when they are applications (and not applets), but when I publish the applets, I get the following permission error :

java.security.AccessControlException:access denied (java.net.SocketPermissions xxx.xxx.xxx.xxx:yyyy accept, resolve)


where xxx.xxx.xxx.xxx is the ip address
  and yyyy is the port

I want to know how to ask the user for the permission to comunicate over network ( from the applet ).
The applet must work on a Linux/Windows workstation, in Iexplore/Netscape.

Thanx ...
0
Comment
Question by:danymag
  • 2
3 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8194404
 You will need to sign them in order to do it. Take a look here:

http://java.sun.com/products/plugin/1.2/docs/signed.html
http://www.securingjava.com/appdx-c/
0
 

Author Comment

by:danymag
ID: 8194429
Why do I need to sign them ...
In the same applet I use a print method, and it DOES manage to  ask the user for permission. Here goes the print method :


public void prin() {
     PrinterJob printJob = PrinterJob.getPrinterJob();
     printJob.setPrintable(this);
       
         try {
             printJob.print();
         }
         catch (Exception ex) {
             ex.printStackTrace();
         }
   
}


public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
           if (pi >= 1) {
               return Printable.NO_SUCH_PAGE;    }

Graphics2D g2=(Graphics2D) g;
g2.translate(pf.getImageableX(), pf.getImageableY());
this.paint(g2);this.repaint();
return Printable.PAGE_EXISTS;
    }



When launchd in application mode, it prints automaticly, but when launched as an applet it asks the user for permission (without having signed anything)

I want the same thing for the network communication ...
0
 
LVL 35

Accepted Solution

by:
girionis earned 225 total points
ID: 8194478
 You are trying to open a peer-to-peer connection, from one applet to the other, this is not allowed by default, since applets can only open connections to the server where the applets' class files reside.

  The second solution you can go for is to change the java.policy file but this will require manually changing it on every client machine.

  As for the printing stuff I guess the default permissions in your java.policy file allow the applet to print on a local printer.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question