Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Magnos

Thread: JAVA Permissions Applet

  1. #1
    Magnos is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default 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.     }
    The code works fine when I run it from the NetBeans console, is when I execute the code in the browser directly that I have this error.

    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)
    Please can any one point me to the write direction.

    Thanks in advance

  2. #2
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default 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

  3. #3
    Magnos is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default 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
    kaydell2 likes this.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: JAVA Permissions Applet

    Java Code:
    java.awt.Desktop.getDesktop().open(new File ("plantar/plantar.html"));
    So what do you expect that to open? Because right now you're telling Java to do this:

    - 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

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default 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 - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Magnos is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default 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.

  7. #7
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,889
    Rep Power
    8

    Default Re: JAVA Permissions Applet

    Quote Originally Posted by Magnos View Post
    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.
    https://www.java.net//blog/kirillcoo...g_jars_fo.html
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default 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

  9. #9
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    107
    Rep Power
    0

    Default 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. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: JAVA Permissions Applet

    Quote Originally Posted by Magnos View Post
    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.
    Unsigned applets are not allowed to access the local drive.

    Your problem is that I suspect that file should be on your server, not on the local drive.
    In which case it should be a URL, not a File.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 02-05-2013, 07:36 PM
  2. don't have permissions
    By Petr in forum Suggestions & Feedback
    Replies: 4
    Last Post: 06-12-2011, 04:38 PM
  3. Java and file Windows file permissions
    By danborgir in forum Advanced Java
    Replies: 1
    Last Post: 01-11-2011, 07:04 PM
  4. How to set permissions for a JApplet
    By Gatts79 in forum Java Applets
    Replies: 2
    Last Post: 08-12-2009, 01:54 PM

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
  •