Results 1 to 10 of 10
- 07-02-2011, 05:43 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
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
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.Java Code:grant { permission java.security.AllPermission; };
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:
and this one also didn't help:Java Code:grant codeBase "file:/D:/Projects/Test/test.jar" { permission java.security.AllPermission; };
So, the question is how I can grant AllPermisssion only to ONE applet?Java Code:grant codeBase "http://localhost:8002/Test/-" { permission java.security.AllPermission; };
Thanks in advance,
Alex
- 07-02-2011, 04:13 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
See
What Applets Can and Cannot Do (The Java™ Tutorials > Deployment > Java Applets)
In other words, sign the applet
- 07-02-2011, 07:37 PM #3
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.
- 07-02-2011, 09:11 PM #4
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
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.
- 07-02-2011, 09:14 PM #5
Still not clear why an applet vs an application.
- 07-02-2011, 09:25 PM #6
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
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:
'u' looks like: http://localhost:8002/Test/test.txtJava Code:URL u = new URL(base, filename); InputStreamReader is = new InputStreamReader(u.openStream());
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
- 07-02-2011, 09:27 PM #7
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
- 07-02-2011, 10:03 PM #8
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.works perfectly in Init applet method and doesn't work it I try to use it somewhere from the JavaScript?
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.
- 07-05-2011, 08:56 PM #9
Member
- Join Date
- Jul 2011
- Posts
- 5
- Rep Power
- 0
here is how I solved my problem: security - What's the difference between http://localhost:8000/ and http://127.0.0.1:8000/ for Java Applets - Stack Overflow
- 07-05-2011, 10:35 PM #10
Similar Threads
-
applet working in applet viewer, not browser
By plasticfood in forum Java AppletsReplies: 4Last Post: 06-24-2011, 06:47 PM -
Pass parameter from one applet to another applet in different webpages...
By anubhavranjan in forum Java AppletsReplies: 2Last Post: 09-29-2009, 03:33 PM -
Calling another applet on click of button in one applet
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 02-19-2009, 12:54 PM -
Can we grant permission to applets with out changing java policy file?
By kuppi in forum Java AppletsReplies: 1Last Post: 10-16-2008, 09:56 PM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks