?
Solved

How can I grant a permission from a Java Applet

Posted on 2003-03-24
3
Medium Priority
?
1,461 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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