Results 1 to 10 of 10
  1. #1
    pshenichnov is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default How to grant AllPermission to applet?

    Hi,
    I have some problems with granting AllPermission to my test applet...
    When I try to connect to the page with applet by http://localhost:8002/Test I get the next error message in the Java console:

    java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:8002 connect,resolve)

    If I change 'localhost' on 127.0.0.1 and use http://localhost:8002/Test - everything works fine. What's the difference between localhost and 127.0.0.1 in terms of Java???

    After some time browsing the internet I have found that I can grant access through .java.policy file. But I'm in stack again with format of this file...

    When I add next to the .java.policy
    Java Code:
    grant {
      permission java.security.AllPermission;
    };
    applet starts working and I can connect to the server using 'localhost' instead of 127.0.0.1. But in this case as I can understand I grant AllPermissions to all applets that I don't want.

    I have tried to specify only one necessary applet by specifying codeBase, but it stopped working and I continue get java.security.AccessControlException.

    this one didn't help:
    Java Code:
    grant codeBase "file:/D:/Projects/Test/test.jar" {
      permission java.security.AllPermission;
    };
    and this one also didn't help:
    Java Code:
    grant codeBase "http://localhost:8002/Test/-" {
      permission java.security.AllPermission;
    };
    So, the question is how I can grant AllPermisssion only to ONE applet?

    Thanks in advance,
    Alex

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Why are you using an Applet for this? If you're the only one to run it (implied by you're wanting to change the .java.policy file. No user is going to want to do that) then make it an application.

  4. #4
    pshenichnov is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    oops, sorry... forgot to mention that applet is signed.

    about why I do it in the applet: the original applet that I have problem with is a small part of a big system that developed under ASP.NET. Applet should communicate with the server (download and display text files). All development goes on ASP.NET Development Server that by default open web application with http://localhost:{{someport}}/. I have no idea how to force it to use 127.0.0.1 instead of 'localhost' - it would solve my problem in this case. Also, I'm not the only one developer for the system and not sure that another guys will be happy to change everytime 'localhost' on 127.0.0.1 manually. One time change in .java.policy is more appreciated in this case and could really ssolve the problem.

    In production everything should be OK - no ports and localhosts will be used there.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Still not clear why an applet vs an application.

  6. #6
    pshenichnov is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    hm... just mentioned that if I try to move the code that communicate with the server into the Init() applet method then everything works fine. Problem appears only when I try to do it from the methods that called by JavaScripts. What is the difference there?

    problem code:
    Java Code:
    URL u = new URL(base, filename);
    InputStreamReader is = new InputStreamReader(u.openStream());
    'u' looks like: http://localhost:8002/Test/test.txt

    why this code works perfectly in Init applet method and doesn't work it I try to use it somewhere from the JavaScript?

    Thanks for the help!
    Alex

  7. #7
    pshenichnov is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Still not clear why an applet vs an application.
    because it's already written as Applet and I just need to integrate it into our system. Application won't work in this case.
    Last edited by pshenichnov; 07-02-2011 at 10:29 PM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    works perfectly in Init applet method and doesn't work it I try to use it somewhere from the JavaScript?
    I have had the same problem with an applet that read local files. I gave all applets permission to read from the folders as it was the java doc files.
    I tried many different codebases for the policy file and finally gave up.

    I wonder if the codebase changes when you are coming thru javascript. Maybe if you set the codebase in the permission to where the browser is it would work. It worked differently for different browsers.
    Here are some of my attempts:
    grant codeBase "file:/E:/Java/Tutorial/-" {
    permission java.io.FilePermission "E:/", "read";
    permission java.io.FilePermission "E:/Java/Tutorial/", "read";
    permission java.io.FilePermission "E:/Java/Tutorial/-", "read";
    };



    Please let me know if you figure it out.

  9. #9
    pshenichnov is offline Member
    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

Similar Threads

  1. applet working in applet viewer, not browser
    By plasticfood in forum Java Applets
    Replies: 4
    Last Post: 06-24-2011, 07:47 PM
  2. Replies: 2
    Last Post: 09-29-2009, 04:33 PM
  3. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 01:54 PM
  4. Replies: 1
    Last Post: 10-16-2008, 10:56 PM
  5. Replies: 4
    Last Post: 06-08-2007, 07:15 AM

Tags for this Thread

Posting Permissions

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