Results 1 to 10 of 10
Thread: JAVA Permissions Applet
- 09-29-2013, 06:04 PM #1
Member
- Join Date
- Sep 2013
- Posts
- 3
- Rep Power
- 0
JAVA Permissions Applet
Hello, I don’t have many experience with JAVA.
I have a problem with an Applet that I am building. The Applet is accessing a .HTML file in the computer the problem is that there is a problem with the permissions to the applet access to that file, I have tried some solutions but I cant solve the problem.
I tried to use the policy tool and add grant all permissions, did not work, and I tried some codes like this
Java Code:1. public String metodo() { 2. AccessController.doPrivileged( 3. new PrivilegedAction() { 4. public Object run() { 5. //MY CODE 6. } 7. } 8. ); 9. }
Java Code:Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "setSecurityManager") at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source) at java.lang.System.setSecurityManager0(Unknown Source) at java.lang.System.setSecurityManager(Unknown Source) at Horta.plantar.actionPerformed(plantar.java:27) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Thanks in advance
- 09-30-2013, 04:24 AM #2
Senior Member
- Join Date
- Dec 2012
- Posts
- 106
- Rep Power
- 0
Re: JAVA Permissions Applet
Can you do a Java Web Start, Java Network Launch Protocol (JNLP) instead of an Applet? It might be easier to get the security working (that is easy for me to say though, to redo the project.)
So, you mean that you have one .html file and it references an apple's .class file using an <applet> tag or an <object> tag? And when the applet runs, it tries to access another .html file, from the local file system?
Usually, applet's are downloaded from the web server, and are run in the web browser on the client computer, but they get any additional resources that they need from the web server. So you are not running your applet from a web server?
How are you accessing the second .html file? From the following line of your stack trace, I believe that I could tell which line of code is causing the exception:
at Horta.plantar.actionPerformed(plantar.java:27)
Is it in the file called "plantar.java" on line number 27? I think that if I had your whole project, then maybe I could take a look at it and understand better.
-- Kaydell
Java Coaching: Home
- 09-30-2013, 04:01 PM #3
Member
- Join Date
- Sep 2013
- Posts
- 3
- Rep Power
- 0
Re: JAVA Permissions Applet
Here is the code that I am using,
Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Horta; import java.awt.event.*; import java.io.*; import java.util.logging.*; /** * * @author HP */ class plantar implements ActionListener { @Override public void actionPerformed (ActionEvent e){ try { botao_plantar(); } catch (IOException ex) { Logger.getLogger(plantar.class.getName()).log(Level.SEVERE, null, ex); } } void botao_plantar()throws java.io.IOException{ java.awt.Desktop.getDesktop().open(new File ("plantar/plantar.html")); } }
I just show here the action listener part, if you need the code that generates the button and is trigged by this action listener, just say and I will putted here.
Thanks for the help Kaydell2
- 09-30-2013, 04:17 PM #4
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: JAVA Permissions Applet
Java Code:java.awt.Desktop.getDesktop().open(new File ("plantar/plantar.html"));
- look in the directory where Java is executed (can be anywhere) for a file plantar/plantar.html
- open that file on the local harddrive of the client in the default browser
I can say with 99.99% certainty that there is not going to be a subdirectory plantar in the directory where Java is invoked."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 09-30-2013, 04:19 PM #5
Re: JAVA Permissions Applet
Have you tried signing the applet? You probably don't need to do anything more complicated than that.
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 09-30-2013, 06:38 PM #6
Member
- Join Date
- Sep 2013
- Posts
- 3
- Rep Power
- 0
Re: JAVA Permissions Applet
In reply to gimbal2, in the java executed program by NetBeans it was opening the file just like the code was in the top. But I have moved the file to the c:/ and it gives me back the same error in the permissions when I execute the applet directly from the browser.
In reply to KevinWorkman, I tried to do that but I could not find a tutorial step by step in how to do it, if you have the knowledge of such tutorial, or if you could put here a how to do it I would be grateful.
- 09-30-2013, 06:43 PM #7
Re: JAVA Permissions Applet
How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 09-30-2013, 08:03 PM #8
Senior Member
- Join Date
- Dec 2012
- Posts
- 106
- Rep Power
- 0
Re: JAVA Permissions Applet
If you send me the entire project, or at least something that compiles and demonstrates the problem, I'll take a look at it.
Short, Self Contained, Correct Example
- 09-30-2013, 08:18 PM #9
Senior Member
- Join Date
- Dec 2012
- Posts
- 106
- Rep Power
- 0
Re: JAVA Permissions Applet
When I developed an Applet using Eclipse, I didn't get any security exceptions. I found that Eclipse was generating a security policy file for me, called: "java.policy.applet". Eclipse automatically placed this file in the right place to let my Applet do anything, but when deploying my Applet, I got security exceptions. You may want to search for a file called "java.policy.applet" in your NetBeans project, this may solve the myserioury of why it works in NetBeans, but not outside of NetBeans.
/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */
grant {
permission java.security.AllPermission;
};
To get additional HTML files by using Java Applet Code (rather than letting your web browser load them, which might be a good idea) you may need to use a Java method such a method from the AppletContext to show a document or get a resource for you Applet. When run from your own computer, you shouldn't get a security exception and when from from the Web, it should just work there too:
From within your Applet class code, call the following method, passing a url specifing the HTML file to be shown, using a relative path.
getAppletContext().showDocument(url);
AppletContext (Java Platform SE 6)
You can email me if you want to, I'd be glad to help.
-- Kaydell
kaydell@yahoo.com
- 10-01-2013, 11:09 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: JAVA Permissions Applet
Please do not ask for code as refusal often offends.
** This space for rent **
Similar Threads
-
Why is my signed applet still running into permissions problems?
By errodr in forum Java AppletsReplies: 1Last Post: 02-05-2013, 08:36 PM -
don't have permissions
By Petr in forum Suggestions & FeedbackReplies: 4Last Post: 06-12-2011, 05:38 PM -
Java and file Windows file permissions
By danborgir in forum Advanced JavaReplies: 1Last Post: 01-11-2011, 08:04 PM -
How to set permissions for a JApplet
By Gatts79 in forum Java AppletsReplies: 2Last Post: 08-12-2009, 02:54 PM
Bookmarks